diff --git a/Documentation/README.html b/Documentation/README.html
index 4430ef211f7..01a27ce6446 100644
--- a/Documentation/README.html
+++ b/Documentation/README.html
@@ -8,7 +8,7 @@
NuttX README Files
- Last Updated: March 21, 2017
+ Last Updated: March 23, 2017
|
@@ -68,6 +68,8 @@ nuttx/
| | `- README.txt
| |- cc3200-launchpad/
| | `- README.txt
+ | |- clicker2-stm32/
+ | | `- README.txt
| |- cloudctrl/
| | `- README.txt
| |- demo9s12ne64/
diff --git a/README.txt b/README.txt
index 4bab1306ff7..3db07e882ac 100644
--- a/README.txt
+++ b/README.txt
@@ -1453,6 +1453,8 @@ nuttx/
| | `- README.txt
| |- cc3200-launchpad/
| | `- README.txt
+ | |- clicker2-stm32
+ | | `- README.txt
| |- cloudctrl
| | `- README.txt
| |- demo0s12ne64/
diff --git a/arch/arm/src/stm32/Kconfig b/arch/arm/src/stm32/Kconfig
index 9e3ce56127f..eba911dfc56 100644
--- a/arch/arm/src/stm32/Kconfig
+++ b/arch/arm/src/stm32/Kconfig
@@ -2629,9 +2629,9 @@ config STM32_FLASH_PREFETCH
default y if STM32_STM32F427 || STM32_STM32F429 || STM32_STM32F446
default n
---help---
- Enable FLASH prefetch and F2 and F4 parts (FLASH pre-fetch is always enabled
- on F1 parts). Some early revisions of F4 parts do not support FLASH pre-fetch
- properly and enabling this option may interfere with ADC accuracy.
+ Enable FLASH prefetch and F2 and F4 parts (FLASH pre-fetch is always enabled
+ on F1 parts). Some early revisions of F4 parts do not support FLASH pre-fetch
+ properly and enabling this option may interfere with ADC accuracy.
config STM32_FLASH_WORKAROUND_DATA_CACHE_CORRUPTION_ON_RWW
bool "Workaround for FLASH data cache corruption"
@@ -6201,12 +6201,11 @@ config STM32_I2C_DUTY16_9
config STM32_I2C_DMA
bool "I2C DMA Support"
default n
- depends on STM32_I2C && STM32_STM32F40XX && STM32_DMA1
+ depends on STM32_I2C && STM32_STM32F40XX && STM32_DMA1 && !I2C_POLLED
---help---
This option enables the DMA for I2C transfers.
Note: The user can define CONFIG_I2C_DMAPRIO: a custom priority value for the
I2C dma streams, else the default priority level is set to medium.
- Note: This option is compatible with CONFIG_I2C_POLLED.
endmenu
diff --git a/arch/arm/src/stm32/chip/stm32_flash.h b/arch/arm/src/stm32/chip/stm32_flash.h
index 32eeaf90dd8..6bc1085bd18 100644
--- a/arch/arm/src/stm32/chip/stm32_flash.h
+++ b/arch/arm/src/stm32/chip/stm32_flash.h
@@ -324,10 +324,10 @@
# define FLASH_CR_OBL_LAUNCH (1 << 13) /* Bit 13: Force option byte loading */
# endif
#elif defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX)
-# define FLASH_CR_PG (1 << 0) /* Bit 0: Programming */
-# define FLASH_CR_SER (1 << 1) /* Bit 1: Sector Erase */
-# define FLASH_CR_MER (1 << 2) /* Bit 2: Mass Erase sectors 0..11 */
-# define FLASH_CR_SNB_SHIFT (3) /* Bits 3-6: Sector number */
+# define FLASH_CR_PG (1 << 0) /* Bit 0: Programming */
+# define FLASH_CR_SER (1 << 1) /* Bit 1: Sector Erase */
+# define FLASH_CR_MER (1 << 2) /* Bit 2: Mass Erase sectors 0..11 */
+# define FLASH_CR_SNB_SHIFT (3) /* Bits 3-6: Sector number */
#if defined(CONFIG_STM32_STM32F427) || defined(CONFIG_STM32_STM32F429)
# define FLASH_CR_SNB_MASK (31 << FLASH_CR_SNB_SHIFT)
# define FLASH_CR_SNB(n) (((n % 12) << FLASH_CR_SNB_SHIFT) | ((n / 12) << 7)) /* Sector n, n=0..23 */
@@ -335,19 +335,19 @@
# define FLASH_CR_SNB_MASK (15 << FLASH_CR_SNB_SHIFT)
# define FLASH_CR_SNB(n) ((n) << FLASH_CR_SNB_SHIFT) /* Sector n, n=0..11 */
#endif
-# define FLASH_CR_PSIZE_SHIFT (8) /* Bits 8-9: Program size */
+# define FLASH_CR_PSIZE_SHIFT (8) /* Bits 8-9: Program size */
# define FLASH_CR_PSIZE_MASK (3 << FLASH_CR_PSIZE_SHIFT)
# define FLASH_CR_PSIZE_X8 (0 << FLASH_CR_PSIZE_SHIFT) /* 00 program x8 */
# define FLASH_CR_PSIZE_X16 (1 << FLASH_CR_PSIZE_SHIFT) /* 01 program x16 */
# define FLASH_CR_PSIZE_X32 (2 << FLASH_CR_PSIZE_SHIFT) /* 10 program x32 */
# define FLASH_CR_PSIZE_X64 (3 << FLASH_CR_PSIZE_SHIFT) /* 11 program x64 */
-# define FLASH_CR_STRT (1 << 16) /* Bit 16: Start Erase */
-# define FLASH_CR_EOPIE (1 << 24) /* Bit 24: End of operation interrupt enable */
-# define FLASH_CR_ERRIE (1 << 25) /* Bit 25: Error interrupt enable */
-# define FLASH_CR_LOCK (1 << 31) /* Bit 31: Lock */
+# define FLASH_CR_STRT (1 << 16) /* Bit 16: Start Erase */
+# define FLASH_CR_EOPIE (1 << 24) /* Bit 24: End of operation interrupt enable */
+# define FLASH_CR_ERRIE (1 << 25) /* Bit 25: Error interrupt enable */
+# define FLASH_CR_LOCK (1 << 31) /* Bit 31: Lock */
#endif
#if defined(CONFIG_STM32_STM32F427) || defined(CONFIG_STM32_STM32F429)
-# define FLASH_CR_MER1 (1 << 15) /* Bit 15: Mass Erase sectors 12..23 */
+# define FLASH_CR_MER1 (1 << 15) /* Bit 15: Mass Erase sectors 12..23 */
#endif
/* Flash Option Control Register (OPTCR) */
@@ -375,7 +375,7 @@
/* Flash Option Control Register (OPTCR1) */
#if defined(CONFIG_STM32_STM32F427) || defined(CONFIG_STM32_STM32F429)
-# define FLASH_OPTCR1_NWRP_SHIFT (16) /* Bits 16-27: Not write protect (high bank) */
+# define FLASH_OPTCR1_NWRP_SHIFT (16) /* Bits 16-27: Not write protect (high bank) */
# define FLASH_OPTCR1_NWRP_MASK (0xfff << FLASH_OPTCR_NWRP_SHIFT)
# define FLASH_OPTCR1_BFB2_SHIFT (4) /* Bits 4: Dual-bank Boot option byte */
@@ -384,7 +384,7 @@
#endif
#if defined(CONFIG_STM32_STM32F446)
-# define FLASH_OPTCR1_NWRP_SHIFT (16) /* Bits 16-23: Not write protect (high bank) */
+# define FLASH_OPTCR1_NWRP_SHIFT (16) /* Bits 16-23: Not write protect (high bank) */
# define FLASH_OPTCR1_NWRP_MASK (0xff << FLASH_OPTCR_NWRP_SHIFT)
#endif
diff --git a/arch/arm/src/stm32/stm32_flash.c b/arch/arm/src/stm32/stm32_flash.c
index 8ba48a82623..fb1e1cac220 100644
--- a/arch/arm/src/stm32/stm32_flash.c
+++ b/arch/arm/src/stm32/stm32_flash.c
@@ -128,6 +128,7 @@ static void flash_lock(void)
modifyreg32(STM32_FLASH_CR, 0, FLASH_CR_LOCK);
}
+#if defined(CONFIG_STM32_FLASH_WORKAROUND_DATA_CACHE_CORRUPTION_ON_RWW)
static void data_cache_disable(void)
{
modifyreg32(STM32_FLASH_ACR, FLASH_ACR_DCEN, 0);
@@ -143,6 +144,7 @@ static void data_cache_enable(void)
modifyreg32(STM32_FLASH_ACR, 0, FLASH_ACR_DCEN);
}
+#endif /* defined(CONFIG_STM32_FLASH_WORKAROUND_DATA_CACHE_CORRUPTION_ON_RWW) */
/************************************************************************************
* Public Functions
@@ -288,6 +290,7 @@ ssize_t up_progmem_erasepage(size_t page)
#if !defined(CONFIG_STM32_STM32F40XX)
if (!(getreg32(STM32_RCC_CR) & RCC_CR_HSION))
{
+ sem_unlock();
return -EPERM;
}
#endif
diff --git a/arch/arm/src/stm32/stm32_i2c_alt.c b/arch/arm/src/stm32/stm32_i2c_alt.c
index 9112b084076..b115ce2795c 100644
--- a/arch/arm/src/stm32/stm32_i2c_alt.c
+++ b/arch/arm/src/stm32/stm32_i2c_alt.c
@@ -1204,6 +1204,9 @@ static inline void stm32_i2c_enablefsmc(uint32_t ahbenr)
static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv)
{
+#ifndef CONFIG_I2C_POLLED
+ uint32_t regval;
+#endif
uint32_t status;
i2cinfo("I2C ISR called\n");
@@ -1867,7 +1870,6 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv)
#else
/* Clear all interrupts */
- uint32_t regval;
regval = stm32_i2c_getreg(priv, STM32_I2C_CR2_OFFSET);
regval &= ~I2C_CR2_ALLINTS;
stm32_i2c_putreg(priv, STM32_I2C_CR2_OFFSET, regval);
diff --git a/arch/arm/src/stm32/stm32_qencoder.c b/arch/arm/src/stm32/stm32_qencoder.c
index e2245075b91..126ef24987c 100644
--- a/arch/arm/src/stm32/stm32_qencoder.c
+++ b/arch/arm/src/stm32/stm32_qencoder.c
@@ -693,17 +693,17 @@ static int stm32_interrupt(int irq, FAR void *context, FAR void *arg)
stm32_putreg16(priv, STM32_GTIM_SR_OFFSET, regval & ~GTIM_SR_UIF);
/* Check the direction bit in the CR1 register and add or subtract the
- * maximum value, as appropriate.
+ * maximum value + 1, as appropriate.
*/
regval = stm32_getreg16(priv, STM32_GTIM_CR1_OFFSET);
if ((regval & ATIM_CR1_DIR) != 0)
{
- priv->position -= (int32_t)0x0000ffff;
+ priv->position -= (int32_t)0x00010000;
}
else
{
- priv->position += (int32_t)0x0000ffff;
+ priv->position += (int32_t)0x00010000;
}
return OK;
diff --git a/arch/arm/src/stm32/stm32f40xxx_i2c.c b/arch/arm/src/stm32/stm32f40xxx_i2c.c
index 3d7d5567f89..12080928c20 100644
--- a/arch/arm/src/stm32/stm32f40xxx_i2c.c
+++ b/arch/arm/src/stm32/stm32f40xxx_i2c.c
@@ -1261,6 +1261,15 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv)
priv->status = status;
+ /* Any new message should begin with "Start" condition
+ * Situation priv->msgc == 0 came from DMA RX handler and should be managed
+ */
+
+ if (priv->dcnt == -1 && priv->msgc != 0 && (status & I2C_SR1_SB) == 0)
+ {
+ return OK;
+ }
+
/* Check if this is a new transmission so to set up the
* trace table accordingly.
*/
@@ -1516,9 +1525,16 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv)
status |= (stm32_i2c_getreg(priv, STM32_I2C_SR2_OFFSET) << 16);
- /* Send Stop */
+ /* Send Stop/Restart */
- stm32_i2c_sendstop(priv);
+ if (priv->msgc > 0)
+ {
+ stm32_i2c_sendstart(priv);
+ }
+ else
+ {
+ stm32_i2c_sendstop(priv);
+ }
i2cinfo("Address ACKed beginning data reception\n");
i2cinfo("short read N=1: programming stop bit\n");
@@ -1828,7 +1844,17 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv)
{
i2cinfo("short read N=2: DR and SR full setting stop bit and reading twice\n");
- stm32_i2c_sendstop(priv);
+ /* Send Stop/Restart */
+
+ if (priv->msgc > 0)
+ {
+ stm32_i2c_sendstart(priv);
+ }
+ else
+ {
+ stm32_i2c_sendstop(priv);
+ }
+
*priv->ptr++ = stm32_i2c_getreg(priv, STM32_I2C_DR_OFFSET);
priv->dcnt--;
*priv->ptr++ = stm32_i2c_getreg(priv, STM32_I2C_DR_OFFSET);
@@ -1905,9 +1931,16 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv)
stm32_i2c_traceevent(priv, I2CEVENT_READ_3, priv->dcnt);
- /* Program stop */
+ /* Program Stop/Restart */
- stm32_i2c_sendstop(priv);
+ if (priv->msgc > 0)
+ {
+ stm32_i2c_sendstart(priv);
+ }
+ else
+ {
+ stm32_i2c_sendstop(priv);
+ }
/* read dcnt = 2 */
@@ -2015,7 +2048,6 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv)
#else
/* Clear all interrupts */
- uint32_t regval;
regval = stm32_i2c_getreg(priv, STM32_I2C_CR2_OFFSET);
regval &= ~I2C_CR2_ALLINTS;
stm32_i2c_putreg(priv, STM32_I2C_CR2_OFFSET, regval);
@@ -2062,7 +2094,14 @@ static void stm32_i2c_dmarxcallback(DMA_HANDLE handle, uint8_t status, void *arg
* interrupt routine if enabled.
*/
- stm32_i2c_sendstop(priv);
+ if (priv->msgc > 0)
+ {
+ stm32_i2c_sendstart(priv);
+ }
+ else
+ {
+ stm32_i2c_sendstop(priv);
+ }
/* Let the I2C periph know to stop DMA transfers, also is used by ISR to check
* if DMA is done.
@@ -2116,10 +2155,6 @@ static void stm32_i2c_dmatxcallback(DMA_HANDLE handle, uint8_t status, void *arg
regval |= (I2C_CR2_ITERREN | I2C_CR2_ITEVFEN);
stm32_i2c_putreg(priv, STM32_I2C_CR2_OFFSET, regval);
#endif
-
- /* let the ISR routine take care of shutting down or switching to next msg */
-
- stm32_i2c_isr(priv);
}
#endif /* ifdef CONFIG_STM32_I2C_DMA */
diff --git a/arch/arm/src/stm32f7/stm32_allocateheap.c b/arch/arm/src/stm32f7/stm32_allocateheap.c
index ffa6d27455b..4714b53f3d5 100644
--- a/arch/arm/src/stm32f7/stm32_allocateheap.c
+++ b/arch/arm/src/stm32f7/stm32_allocateheap.c
@@ -126,7 +126,7 @@
# endif
#endif
-/* There are 4 possible heap configurations:
+/* There are 5 possible heap configurations:
*
* Configuration 1. System SRAM1 (only)
* CONFIG_MM_REGIONS == 1
diff --git a/configs/Makefile b/configs/Makefile
index f430e137e88..31de5604e08 100644
--- a/configs/Makefile
+++ b/configs/Makefile
@@ -89,7 +89,7 @@ OBJS = $(AOBJS) $(COBJS)
BIN = libconfigs$(LIBEXT)
all: $(BIN)
-.PHONY: depend ccontext clean_context clean distclean
+.PHONY: depend context clean_context clean distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
diff --git a/configs/clicker2-stm32/README.txt b/configs/clicker2-stm32/README.txt
new file mode 100644
index 00000000000..c412c114350
--- /dev/null
+++ b/configs/clicker2-stm32/README.txt
@@ -0,0 +1,251 @@
+README
+======
+
+ This is the README file for the port of NuttX to the Mikroe Clicker2 STM32
+ board based on the STMicro STM32F407VGT6 MCU.
+
+ Reference: https://shop.mikroe.com/development-boards/starter/clicker-2/stm32f4
+
+Contents
+========
+
+ o Serial Console
+ o LEDs
+ o Buttons
+ o Using JTAG
+ o Configurations
+
+Serial Console
+==============
+
+ The are no RS-232 drivers on-board. An RS-232 Click board is available:
+ https://shop.mikroe.com/click/interface/rs232 or you can cannot an off-
+ board TTL-to-RS-232 converter as follows:
+
+ USART2: mikroBUS1 PD6/RX and PD5/TX
+ USART3: mikroBUS2 PD9/RX and PD8TX
+
+ GND, 3.3V, and 5V. Are also available
+
+ By default, USART3 on mikroBUS2 is used as the serial console in each
+ configuration unless stated otherwise in the description of the
+ configuration.
+
+LEDs
+====
+
+ The Mikroe Clicker2 STM32 has two user controllable LEDs:
+
+ LD1/PE12, Active high output illuminates
+ LD2/PE15, Active high output illuminates
+
+ If CONFIG_ARCH_LEDS is not defined, then the user can control the LEDs in any
+ way. If CONFIG_ARCH_LEDs is defined, then NuttX will control the 2 LEDs on
+ board the Clicker2 for STM32. The following definitions describe how NuttX
+ controls the LEDs:
+
+ SYMBOL Meaning LED state
+ LD1 LD2
+ ------------------- ----------------------- -------- --------
+ LED_STARTED NuttX has been started OFF OFF
+ LED_HEAPALLOCATE Heap has been allocated OFF OFF
+ LED_IRQSENABLED Interrupts enabled OFF OFF
+ LED_STACKCREATED Idle stack created ON OFF
+ LED_INIRQ In an interrupt N/C ON
+ LED_SIGNAL In a signal handler No change
+ LED_ASSERTION An assertion failed No change
+ LED_PANIC The system has crashed OFF Blinking
+ LED_IDLE STM32 is is sleep mode Not used
+
+ Thus is LD1 is illuminated, the Clicker2 has completed boot-up. IF LD2
+ is glowly softly, then interrupts are being taken; the level of illumination
+ depends amount of time processing interupts. If LD1 is off and LD2 is
+ blinking at about 2Hz, then the system has crashed.
+
+Buttons
+=======
+
+ The Mikroe Clicker2 STM32 has two buttons available to software:
+
+ T2/E0, Low sensed when pressed
+ T3/PA10, Low sensed when pressed
+
+Using JTAG
+==========
+
+ The Clicker2 comes with the mikroBootloader installed. That bootloader
+ has not been used and is possibly incompatible with the Clicker2-STM32
+ linker script at configs/clicker2-stm32/scripts/flash.ld. Often code must
+ be built to execute at an offset in to FLASH when a bootloader is used.
+ Certainly that is the case for the ST-Micro DFU bootloader but I am not
+ aware of the requirements for use with the mikroBootloader.
+
+ JTAG has been used in the development of this board support. The
+ Clicker2-STM32 board offers a 2x5 JTAG connector. You may use Dupont
+ jumpers to connect this port to JTAG as described here:
+
+ https://www.mikroe.com/how-to-use-st-link-v2-with-clicker-2-for-stm32-a-detailed-walkthrough/
+ http://www.playembedded.org/blog/en/2016/02/06/mikroe-clicker-2-for-stm32-and-stlink-v2/
+
+ NOTE that the FLASH probably has read protection enabled locked. You may
+ need to follow the instructions at the second link to unlock it. You can
+ also use the STM32 ST-Link CLI tool on Windows to remove the read protection
+ using the -OB command:
+
+ $ ./ST-LINK_CLI.exe -c SN=53FF6F064966545035320387 SWD LPM
+ STM32 ST-LINK CLI v2.3.0
+ STM32 ST-LINK Command Line Interface
+
+ ST-LINK SN : 53FF6F064966545035320387
+ ST-LINK Firmware version : V2J24S4
+ Connected via SWD.
+ SWD Frequency = 4000K.
+ Target voltage = 3.2 V.
+ Connection mode : Normal.
+ Debug in Low Power mode enabled.
+ Device ID:0x413
+ Device family :STM32F40xx/F41xx
+
+ $ ./ST-LINK_CLI.exe -OB RDP=0
+ STM32 ST-LINK CLI v2.3.0
+ STM32 ST-LINK Command Line Interface
+
+ ST-LINK SN : 53FF6F064966545035320387
+ ST-LINK Firmware version : V2J24S4
+ Connected via SWD.
+ SWD Frequency = 4000K.
+ Target voltage = 3.2 V.
+ Connection mode : Normal.
+ Device ID:0x413
+ Device family :STM32F40xx/F41xx
+ Updating option bytes...
+ Option bytes updated successfully.
+
+ NOTE:
+ 1. You can get the ST-Link Utilies here:
+ http://www.st.com/en/embedded-software/stsw-link004.html
+ 2. The ST-LINK Utility command line interface is located at:
+ [Install_Directory]\STM32 ST-LINK Utility\ST-LINK Utility\ST-LINK_CLI.exe
+ 3. You can get a summary of all of the command options by running
+ ST-LINK_CLI.exe with no arguments.
+ 4. You can get the serial number of the ST-Link when from the information
+ window if you connect via the ST-Link Utility:
+
+ 11:04:28 : ST-LINK SN : 53FF6F064966545035320387
+ 11:04:28 : ST-LINK Firmware version : V2J24S4
+ 11:04:28 : Connected via SWD.
+ 11:04:28 : SWD Frequency = 100 KHz.
+ 11:04:28 : Connection mode : Normal.
+ 11:04:28 : Debug in Low Power mode enabled.
+ 11:04:30 : Device ID:0x413
+ 11:04:30 : Device family :STM32F40xx/F41xx
+ 11:04:30 : Can not read memory!
+ Disable Read Out Protection and retry.
+
+ You can avoid the mess of jumpers using the mikroProg to ST-Link v2 adapter
+ along with a 2x5, 10-wire ribbon cable connector:
+
+ https://shop.mikroe.com/add-on-boards/adapter/mikroprog-st-link-v2-adapter
+
+ Then you can use the ST-Link Utility or other debugger software to write
+ the NuttX binary to FLASH. OpenOCD can be used with the ST-Link to provide
+ a debug environment. The debug adaptor is NOT compatible with other JTAG
+ debuggers such as the Segger J-Link.
+
+Configurations
+==============
+
+ Information Common to All Configurations
+ ----------------------------------------
+ Each Clicker2 configuration is maintained in a sub-directory and can be
+ selected as follow:
+
+ cd tools
+ ./configure.sh clicker2-stm32/
+ cd -
+ . ./setenv.sh
+
+ Before sourcing the setenv.sh file above, you should examine it and
+ perform edits as necessary so that TOOLCHAIN_BIN is the correct path
+ to the directory than holds your toolchain binaries.
+
+ And then build NuttX by simply typing the following. At the conclusion of
+ the make, the nuttx binary will reside in an ELF file called, simply, nuttx.
+
+ make oldconfig
+ make
+
+ The that is provided above as an argument to the tools/configure.sh
+ must be is one of the following.
+
+ NOTES:
+
+ 1. These configurations use the mconf-based configuration tool. To
+ change any of these configurations using that tool, you should:
+
+ a. Build and install the kconfig-mconf tool. See nuttx/README.txt
+ see additional README.txt files in the NuttX tools repository.
+
+ b. Execute 'make menuconfig' in nuttx/ in order to start the
+ reconfiguration process.
+
+ 2. Unless stated otherwise, all configurations generate console
+ output on USART3, channel 0) as described above under "Serial
+ Console". The relevant configuration settings are listed below:
+
+ CONFIG_STM32_USART3=y
+ CONFIG_STM32_USART3_SERIALDRIVER=y
+ CONFIG_STM32_USART=y
+
+ CONFIG_USART3_SERIALDRIVER=y
+ CONFIG_USART3_SERIAL_CONSOLE=y
+
+ CONFIG_USART3_RXBUFSIZE=256
+ CONFIG_USART3_TXBUFSIZE=256
+ CONFIG_USART3_BAUD=115200
+ CONFIG_USART3_BITS=8
+ CONFIG_USART3_PARITY=0
+ CONFIG_USART3_2STOP=0
+
+
+ 3. All of these configurations are set up to build under Linux using the
+ "GNU Tools for ARM Embedded Processors" that is maintained by ARM
+ (unless stated otherwise in the description of the configuration).
+
+ https://launchpad.net/gcc-arm-embedded
+
+ That toolchain selection can easily be reconfigured using
+ 'make menuconfig'. Here are the relevant current settings:
+
+ Build Setup:
+ CONFIG_HOST_LINUX =y : Linux environment
+
+ System Type -> Toolchain:
+ CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL=y : GNU ARM EABI toolchain
+
+ Configuration sub-directories
+ -----------------------------
+
+ nsh:
+
+ Configures the NuttShell (nsh) located at examples/nsh. This
+ configuration is focused on low level, command-line driver testing. It
+ has no network.
+
+ NOTES:
+
+ 1. Support for NSH built-in applications is provided:
+
+ Binary Formats:
+ CONFIG_BUILTIN=y : Enable support for built-in programs
+
+ Application Configuration:
+ CONFIG_NSH_BUILTIN_APPS=y : Enable starting apps from NSH command line
+
+ No built applications are enabled in the base configuration, however.
+
+ 2. C++ support for applications is enabled:
+
+ CONFIG_HAVE_CXX=y
+ CONFIG_HAVE_CXXINITIALIZE=y
+ CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y
diff --git a/configs/clicker2-stm32/include/board.h b/configs/clicker2-stm32/include/board.h
index fa271666cb2..7f757d49516 100644
--- a/configs/clicker2-stm32/include/board.h
+++ b/configs/clicker2-stm32/include/board.h
@@ -269,8 +269,8 @@
* Assuming RS-232 connverted connected on mikroMB1/12
*/
-#define GPIO_USART2_RX GPIO_USART2_RX_2 /* PD6 */
-#define GPIO_USART2_TX GPIO_USART2_TX_2 /* PD5 */
+#define GPIO_USART2_RX GPIO_USART2_RX_2 /* PD6 */
+#define GPIO_USART2_TX GPIO_USART2_TX_2 /* PD5 */
#define GPIO_USART3_RX GPIO_USART3_RX_3 /* PD9 */
#define GPIO_USART3_TX GPIO_USART3_TX_3 /* PD8 /
diff --git a/configs/clicker2-stm32/nsh/defconfig b/configs/clicker2-stm32/nsh/defconfig
index 7ae63061f9c..764b16372c6 100644
--- a/configs/clicker2-stm32/nsh/defconfig
+++ b/configs/clicker2-stm32/nsh/defconfig
@@ -144,10 +144,10 @@ CONFIG_ARM_HAVE_MPU_UNIFIED=y
# CONFIG_ARMV7M_HAVE_ITCM is not set
# CONFIG_ARMV7M_HAVE_DTCM is not set
# CONFIG_ARMV7M_TOOLCHAIN_IARL is not set
-CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y
+# CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT is not set
# CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set
# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL is not set
-# CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL is not set
+CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL=y
# CONFIG_ARMV7M_OABI_TOOLCHAIN is not set
CONFIG_ARMV7M_HAVE_STACKCHECK=y
# CONFIG_ARMV7M_STACKCHECK is not set
diff --git a/configs/clicker2-stm32/scripts/flash.ld b/configs/clicker2-stm32/scripts/flash.ld
index ca2e7eefcfc..6bb3aabaddf 100644
--- a/configs/clicker2-stm32/scripts/flash.ld
+++ b/configs/clicker2-stm32/scripts/flash.ld
@@ -42,8 +42,7 @@
*
* When booting from FLASH, FLASH memory is aliased to address 0x0000:0000
* where the code expects to begin execution by jumping to the entry point in
- * the 0x0800:0000 address
- * range.
+ * the 0x0800:0000 address range.
*/
MEMORY
diff --git a/configs/clicker2-stm32/src/clicker2-stm32.h b/configs/clicker2-stm32/src/clicker2-stm32.h
index 544366c8dd2..24dd9e54dc6 100644
--- a/configs/clicker2-stm32/src/clicker2-stm32.h
+++ b/configs/clicker2-stm32/src/clicker2-stm32.h
@@ -33,8 +33,8 @@
*
****************************************************************************/
-#ifndef __CONFIGS_OLIMEX_STM32_P407_SRC_H
-#define __CONFIGS_OLIMEX_STM32_P407_SRC_H
+#ifndef __CONFIGS_CLICKER2_STM32_SRC_CLICKER2_H
+#define __CONFIGS_CLICKER2_STM32_SRC_CLICKER2_H
/****************************************************************************
* Included Files
@@ -212,7 +212,7 @@
#define GPIO_MB1_RST (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_CLEAR|GPIO_PORTE|GPIO_PIN7)
-#define GPIO_MB1_RST (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
+#define GPIO_MB2_RST (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_CLEAR|GPIO_PORTE|GPIO_PIN13)
/* Interrupts
@@ -287,4 +287,4 @@ int stm32_can_setup(void);
#endif
#endif /* __ASSEMBLY__ */
-#endif /* __CONFIGS_OLIMEX_STM32_P407_SRC_H */
+#endif /* __CONFIGS_CLICKER2_STM32_SRC_CLICKER2_H */
diff --git a/configs/freedom-kl25z/include/kl_wifi.h b/configs/freedom-kl25z/include/kl_cc3000.h
similarity index 82%
rename from configs/freedom-kl25z/include/kl_wifi.h
rename to configs/freedom-kl25z/include/kl_cc3000.h
index ab9ac43564a..117fc57eefc 100644
--- a/configs/freedom-kl25z/include/kl_wifi.h
+++ b/configs/freedom-kl25z/include/kl_cc3000.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * configs/freedom-kl25z/include/kl_wifi.h
+ * configs/freedom-kl25z/include/kl_cc300.h
*
* Copyright (C) 2013 Alan Carvalho de Assis
* Author: Alan Carvalho de Assis
@@ -38,34 +38,36 @@
*
****************************************************************************/
+#ifndef __CONFIGS_FREEDOM_KL25Z_INCLUDE_KL_CC3000_H
+#define __CONFIGS_FREEDOM_KL25Z_INCLUDE_KL_CC3000_H 1
+
/****************************************************************************
* Included Files
****************************************************************************/
+
#include
#include
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
long ReadWlanInterruptPin(void);
-/*
- * Enable WiFi Interrupt
- */
+/* Enable WiFi Interrupt */
void WlanInterruptEnable(void);
-/*
- * Disable WiFi Interrupt
- */
+/* Disable WiFi Interrupt */
+
void WlanInterruptDisable(void);
-/*
- * Enable/Disable WiFi
- */
+/* Enable/Disable WiFi */
+
void WriteWlanEnablePin(uint8_t val);
-/*
- * Assert CC3000 CS
- */
+/* Assert CC3000 CS */
+
void AssertWlanCS(void);
/*
@@ -73,8 +75,9 @@ void AssertWlanCS(void);
*/
void DeassertWlanCS(void);
-/*
- * Setup needed pins
- */
+/* Setup needed pins */
+
void Wlan_Setup(void);
+#endif /* __CONFIGS_FREEDOM_KL25Z_INCLUDE_KL_CC3000_H */
+
diff --git a/configs/freedom-kl25z/src/Makefile b/configs/freedom-kl25z/src/Makefile
index 2105da11019..37f83bc1ffb 100644
--- a/configs/freedom-kl25z/src/Makefile
+++ b/configs/freedom-kl25z/src/Makefile
@@ -43,7 +43,7 @@ CSRCS += kl_appinit.c
endif
ifeq ($(CONFIG_WL_CC3000),y)
-CSRCS += kl_wifi.c
+CSRCS += kl_cc3000.c
endif
ifeq ($(CONFIG_KL_TSI),y)
diff --git a/configs/freedom-kl25z/src/kl_wifi.c b/configs/freedom-kl25z/src/kl_cc3000.c
similarity index 98%
rename from configs/freedom-kl25z/src/kl_wifi.c
rename to configs/freedom-kl25z/src/kl_cc3000.c
index 0f1810da37b..e233a64d062 100644
--- a/configs/freedom-kl25z/src/kl_wifi.c
+++ b/configs/freedom-kl25z/src/kl_cc3000.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * configs/freedom-kl25z/src/kl_tsi.c
+ * configs/freedom-kl25z/src/kl_cc3000.c
*
* Copyright (C) 2014 Alan Carvalho de Assis
* Author: Alan Carvalho de Assis
@@ -38,7 +38,7 @@
****************************************************************************/
#include
-#include
+#include
#include
#include
@@ -212,12 +212,12 @@ static void wl_enable_irq(FAR struct cc3000_config_s *state, bool enable)
if (enable)
{
(void)kl_gpioirqattach(GPIO_WIFI_INT, priv->handler, priv->arg);
- kl_gpioirqenable(GPIO_WIFI_INT);
+ kl_gpioirqenable(GPIO_WIFI_INT);
}
else
{
(void)kl_gpioirqattach(GPIO_WIFI_INT, NULL, NULL);
- kl_gpioirqdisable(GPIO_WIFI_INT);
+ kl_gpioirqdisable(GPIO_WIFI_INT);
}
}
diff --git a/configs/nucleo-l476rg/src/Makefile b/configs/nucleo-l476rg/src/Makefile
index a27b0f3b84f..7c908435278 100644
--- a/configs/nucleo-l476rg/src/Makefile
+++ b/configs/nucleo-l476rg/src/Makefile
@@ -49,7 +49,7 @@ CSRCS += stm32_buttons.c
endif
ifeq ($(CONFIG_WL_CC3000),y)
-CSRCS += stm32_wireless.c
+CSRCS += stm32_cc3000.c
ifeq ($(CONFIG_CC3000_PROBES),)
CSRCS += stm32_io.c
endif
diff --git a/configs/nucleo-l476rg/src/stm32_wireless.c b/configs/nucleo-l476rg/src/stm32_cc3000.c
similarity index 99%
rename from configs/nucleo-l476rg/src/stm32_wireless.c
rename to configs/nucleo-l476rg/src/stm32_cc3000.c
index b65a5eaae5f..d1c94b338e9 100644
--- a/configs/nucleo-l476rg/src/stm32_wireless.c
+++ b/configs/nucleo-l476rg/src/stm32_cc3000.c
@@ -1,5 +1,5 @@
/************************************************************************************
- * configs/nucleo-l476rg/src/stm32_wireless.c
+ * configs/nucleo-l476rg/src/stm32_cc3000.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Laurent Latil
diff --git a/configs/spark/src/Makefile b/configs/spark/src/Makefile
index 51ee3a02805..70a7879f15b 100644
--- a/configs/spark/src/Makefile
+++ b/configs/spark/src/Makefile
@@ -66,7 +66,7 @@ CSRCS += stm32_composite.c
endif
ifeq ($(CONFIG_WL_CC3000),y)
-CSRCS += stm32_wireless.c
+CSRCS += stm32_cc3000.c
endif
ifeq ($(CONFIG_CC3000_PROBES),)
diff --git a/configs/spark/src/stm32_wireless.c b/configs/spark/src/stm32_cc3000.c
similarity index 99%
rename from configs/spark/src/stm32_wireless.c
rename to configs/spark/src/stm32_cc3000.c
index afd0f9a819d..7f384213e41 100644
--- a/configs/spark/src/stm32_wireless.c
+++ b/configs/spark/src/stm32_cc3000.c
@@ -1,5 +1,5 @@
/************************************************************************************
- * configs/spark/src/stm32_wireless.c
+ * configs/spark/src/stm32_cc3000.c
*
* Copyright (C) 2009, 2013 Gregory Nutt. All rights reserved.
* Author: Laurent Latil
diff --git a/configs/stm32_tiny/src/Makefile b/configs/stm32_tiny/src/Makefile
index 14ee306846f..02062684c6c 100644
--- a/configs/stm32_tiny/src/Makefile
+++ b/configs/stm32_tiny/src/Makefile
@@ -44,7 +44,7 @@ CSRCS += stm32_pwm.c
endif
ifeq ($(CONFIG_WL_NRF24L01),y)
-CSRCS += stm32_wireless.c
+CSRCS += stm32_cc3000.c
endif
ifeq ($(CONFIG_LIB_BOARDCTL),y)
diff --git a/configs/stm32_tiny/src/stm32_wireless.c b/configs/stm32_tiny/src/stm32_cc3000.c
similarity index 99%
rename from configs/stm32_tiny/src/stm32_wireless.c
rename to configs/stm32_tiny/src/stm32_cc3000.c
index a08e48a65ab..9a8a0d3619b 100644
--- a/configs/stm32_tiny/src/stm32_wireless.c
+++ b/configs/stm32_tiny/src/stm32_cc3000.c
@@ -1,5 +1,5 @@
/************************************************************************************
- * configs/stm32_tiny/src/stm32_wireless.c
+ * configs/stm32_tiny/src/stm32_cc3000.c
*
* Copyright (C) 2009, 2013, 2017 Gregory Nutt. All rights reserved.
* Author: Laurent Latil
diff --git a/configs/stm32f103-minimum/src/Makefile b/configs/stm32f103-minimum/src/Makefile
index 7eaf2d9c277..75b6cb29532 100644
--- a/configs/stm32f103-minimum/src/Makefile
+++ b/configs/stm32f103-minimum/src/Makefile
@@ -86,7 +86,7 @@ CSRCS += stm32_veml6070.c
endif
ifeq ($(CONFIG_WL_NRF24L01),y)
-CSRCS += stm32_wireless.c
+CSRCS += stm32_cc3000.c
endif
ifeq ($(CONFIG_USBDEV),y)
diff --git a/configs/stm32f103-minimum/src/stm32_wireless.c b/configs/stm32f103-minimum/src/stm32_cc3000.c
similarity index 98%
rename from configs/stm32f103-minimum/src/stm32_wireless.c
rename to configs/stm32f103-minimum/src/stm32_cc3000.c
index c3ddcff7848..23b1144ef51 100644
--- a/configs/stm32f103-minimum/src/stm32_wireless.c
+++ b/configs/stm32f103-minimum/src/stm32_cc3000.c
@@ -1,5 +1,5 @@
/************************************************************************************
- * configs/stm32f103-minimum//src/stm32_wireless.c
+ * configs/stm32f103-minimum//src/stm32_cc3000.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Laurent Latil
diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h
index 5c5c25be295..15a0f059a9a 100644
--- a/include/nuttx/compiler.h
+++ b/include/nuttx/compiler.h
@@ -64,6 +64,18 @@
# define UNUSED(a) ((void)(a))
+/* Built-in functions */
+
+/* GCC 4.x have __builtin_ctz(|l|ll) and __builtin_clz(|l|ll). These count
+ * trailing/leading zeros of input number and typically will generate few
+ * fast bit-counting instructions. Inputting zero to these functions is
+ * undefined and needs to be taken care of by the caller. */
+
+#if __GNUC__ >= 4
+# define CONFIG_HAVE_BUILTIN_CTZ 1
+# define CONFIG_HAVE_BUILTIN_CLZ 1
+#endif
+
/* Attributes
*
* GCC supports weak symbols which can be used to reduce code size because
diff --git a/include/semaphore.h b/include/semaphore.h
index 0056909db6a..e14b1aa409e 100644
--- a/include/semaphore.h
+++ b/include/semaphore.h
@@ -105,14 +105,14 @@ typedef struct sem_s sem_t;
#ifdef CONFIG_PRIORITY_INHERITANCE
# if CONFIG_SEM_PREALLOCHOLDERS > 0
# define SEM_INITIALIZER(c) \
- {(c), 0, NULL} /* semcount, flags, hhead */
+ {(c), 0, NULL} /* semcount, flags, hhead */
# else
# define SEM_INITIALIZER(c) \
{(c), 0, {SEMHOLDER_INITIALIZER, SEMHOLDER_INITIALIZER}} /* semcount, flags, holder[2] */
# endif
#else
# define SEM_INITIALIZER(c) \
- {(c)} /* semcount */
+ {(c)} /* semcount */
#endif
/****************************************************************************
diff --git a/include/strings.h b/include/strings.h
index 4b7fc439da4..54be5dd380e 100644
--- a/include/strings.h
+++ b/include/strings.h
@@ -114,6 +114,17 @@ static inline FAR char *rindex(FAR const char *s, int c)
****************************************************************************/
int ffs(int j);
+int ffsl(long j);
+#ifdef CONFIG_HAVE_LONG_LONG
+int ffsll(long long j);
+#endif
+
+int fls(int j);
+int flsl(long j);
+#ifdef CONFIG_HAVE_LONG_LONG
+int flsll(long long j);
+#endif
+
int strcasecmp(FAR const char *, FAR const char *);
int strncasecmp(FAR const char *, FAR const char *, size_t);
diff --git a/libc/string/Make.defs b/libc/string/Make.defs
index defedcfb60a..72cb8354d53 100644
--- a/libc/string/Make.defs
+++ b/libc/string/Make.defs
@@ -35,7 +35,8 @@
# Add the string C files to the build
-CSRCS += lib_ffs.c lib_isbasedigit.c lib_memset.c lib_memchr.c
+CSRCS += lib_ffs.c lib_ffsl.c lib_ffsll.c lib_fls.c lib_flsl.c
+CSRCS += lib_flsll.c lib_isbasedigit.c lib_memset.c lib_memchr.c
CSRCS += lib_memccpy.c lib_memcmp.c lib_memmove.c lib_skipspace.c
CSRCS += lib_stpcpy.c lib_strcasecmp.c lib_strcat.c lib_strchr.c
CSRCS += lib_strcpy.c lib_strcmp.c lib_strcspn.c lib_strdup.c
diff --git a/libc/string/lib_ffs.c b/libc/string/lib_ffs.c
index c52a9c43b23..885718ba49e 100644
--- a/libc/string/lib_ffs.c
+++ b/libc/string/lib_ffs.c
@@ -33,11 +33,11 @@
*
****************************************************************************/
-
/****************************************************************************
* Included Files
****************************************************************************/
+#include
#include
/****************************************************************************
@@ -55,11 +55,11 @@
*
* Description:
* The ffs() function will find the first bit set (beginning with the least
- * significant bit) in i, and return the index of that bit. Bits are
+ * significant bit) in j, and return the index of that bit. Bits are
* numbered starting at one (the least significant bit).
*
* Returned Value:
- * The ffs() function will return the index of the first bit set. If i is
+ * The ffs() function will return the index of the first bit set. If j is
* 0, then ffs() will return 0.
*
****************************************************************************/
@@ -70,6 +70,11 @@ int ffs(int j)
if (j != 0)
{
+#ifdef CONFIG_HAVE_BUILTIN_CTZ
+ /* Count trailing zeros function can be used to implement ffs. */
+
+ ret = __builtin_ctz(j) + 1;
+#else
unsigned int value = (unsigned int)j;
int bitno;
@@ -81,6 +86,7 @@ int ffs(int j)
break;
}
}
+#endif
}
return ret;
diff --git a/libc/string/lib_ffsl.c b/libc/string/lib_ffsl.c
new file mode 100644
index 00000000000..4d5739cc03b
--- /dev/null
+++ b/libc/string/lib_ffsl.c
@@ -0,0 +1,93 @@
+/****************************************************************************
+ * libc/string/lib_ffsl.c
+ *
+ * Copyright (C) 2017 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
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define NBITS (8 * sizeof(unsigned long))
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: ffsl
+ *
+ * Description:
+ * The ffsl() function will find the first bit set (beginning with the least
+ * significant bit) in j, and return the index of that bit. Bits are
+ * numbered starting at one (the least significant bit).
+ *
+ * Returned Value:
+ * The ffsl() function will return the index of the first bit set. If j is
+ * 0, then ffsl() will return 0.
+ *
+ ****************************************************************************/
+
+int ffsl(long j)
+{
+ int ret = 0;
+
+ if (j != 0)
+ {
+#ifdef CONFIG_HAVE_BUILTIN_CTZ
+ /* Count trailing zeros function can be used to implement ffs. */
+
+ ret = __builtin_ctzl(j) + 1;
+#else
+ unsigned long value = (unsigned long)j;
+ int bitno;
+
+ for (bitno = 1; bitno <= NBITS; bitno++, value >>= 1)
+ {
+ if ((value & 1) != 0)
+ {
+ ret = bitno;
+ break;
+ }
+ }
+#endif
+ }
+
+ return ret;
+}
diff --git a/libc/string/lib_ffsll.c b/libc/string/lib_ffsll.c
new file mode 100644
index 00000000000..111e664d422
--- /dev/null
+++ b/libc/string/lib_ffsll.c
@@ -0,0 +1,97 @@
+/****************************************************************************
+ * libc/string/lib_ffsll.c
+ *
+ * Copyright (C) 2017 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
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define NBITS (8 * sizeof(unsigned long long))
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_LONG
+
+/****************************************************************************
+ * Name: ffsll
+ *
+ * Description:
+ * The ffsll() function will find the first bit set (beginning with the least
+ * significant bit) in i, and return the index of that bit. Bits are
+ * numbered starting at one (the least significant bit).
+ *
+ * Returned Value:
+ * The ffsll() function will return the index of the first bit set. If j is
+ * 0, then ffsll() will return 0.
+ *
+ ****************************************************************************/
+
+int ffsll(long long j)
+{
+ int ret = 0;
+
+ if (j != 0)
+ {
+#ifdef CONFIG_HAVE_BUILTIN_CTZ
+ /* Count trailing zeros function can be used to implement ffs. */
+
+ ret = __builtin_ctzll(j) + 1;
+#else
+ unsigned long long value = (unsigned long long)j;
+ int bitno;
+
+ for (bitno = 1; bitno <= NBITS; bitno++, value >>= 1)
+ {
+ if ((value & 1) != 0)
+ {
+ ret = bitno;
+ break;
+ }
+ }
+#endif
+ }
+
+ return ret;
+}
+
+#endif
diff --git a/libc/string/lib_fls.c b/libc/string/lib_fls.c
new file mode 100644
index 00000000000..5894fb1953a
--- /dev/null
+++ b/libc/string/lib_fls.c
@@ -0,0 +1,93 @@
+/****************************************************************************
+ * libc/string/lib_fls.c
+ *
+ * Copyright (C) 2017 Haltian Ltd. All rights reserved.
+ * Author: Jussi Kivilinna
+ *
+ * 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 NBITS (8 * sizeof(unsigned int))
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: fls
+ *
+ * Description:
+ * The fls() function will find the last bit set in value and return
+ * the index of that bit. Bits are numbered starting at one (the least
+ * significant bit).
+ *
+ * Returned Value:
+ * The fls() function will return the index of the last bit set. If j is
+ * 0, then fls() will return 0.
+ *
+ ****************************************************************************/
+
+int fls(int j)
+{
+ int ret = 0;
+
+ if (j != 0)
+ {
+#ifdef CONFIG_HAVE_BUILTIN_CLZ
+ /* Count leading zeros function can be used to implement fls. */
+
+ ret = NBITS - __builtin_clz(j);
+#else
+ unsigned int value = (unsigned int)j;
+ int bitno;
+
+ for (bitno = 1; bitno <= NBITS; bitno++, value >>= 1)
+ {
+ if (value == 1)
+ {
+ ret = bitno;
+ break;
+ }
+ }
+#endif
+ }
+
+ return ret;
+}
diff --git a/libc/string/lib_flsl.c b/libc/string/lib_flsl.c
new file mode 100644
index 00000000000..2a3837ddc7e
--- /dev/null
+++ b/libc/string/lib_flsl.c
@@ -0,0 +1,93 @@
+/****************************************************************************
+ * libc/string/lib_fls.c
+ *
+ * Copyright (C) 2017 Haltian Ltd. All rights reserved.
+ * Author: Jussi Kivilinna
+ *
+ * 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 NBITS (8 * sizeof(unsigned long))
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: flsl
+ *
+ * Description:
+ * The flsl() function will find the last bit set in value and return
+ * the index of that bit. Bits are numbered starting at one (the least
+ * significant bit).
+ *
+ * Returned Value:
+ * The flsl() function will return the index of the last bit set. If j is
+ * 0, then flsl() will return 0.
+ *
+ ****************************************************************************/
+
+int flsl(long j)
+{
+ int ret = 0;
+
+ if (j != 0)
+ {
+#ifdef CONFIG_HAVE_BUILTIN_CLZ
+ /* Count leading zeros function can be used to implement fls. */
+
+ ret = NBITS - __builtin_clzl(j);
+#else
+ unsigned long value = (unsigned long)j;
+ int bitno;
+
+ for (bitno = 1; bitno <= NBITS; bitno++, value >>= 1)
+ {
+ if (value == 1)
+ {
+ ret = bitno;
+ break;
+ }
+ }
+#endif
+ }
+
+ return ret;
+}
diff --git a/libc/string/lib_flsll.c b/libc/string/lib_flsll.c
new file mode 100644
index 00000000000..2f30f8142e1
--- /dev/null
+++ b/libc/string/lib_flsll.c
@@ -0,0 +1,98 @@
+/****************************************************************************
+ * libc/string/lib_fls.c
+ *
+ * Copyright (C) 2017 Haltian Ltd. All rights reserved.
+ * Author: Jussi Kivilinna
+ *
+ * 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 NBITS (8 * sizeof(unsigned long long))
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_LONG
+
+/****************************************************************************
+ * Name: flsll
+ *
+ * Description:
+ * The flsll() function will find the last bit set in value and return
+ * the index of that bit. Bits are numbered starting at one (the least
+ * significant bit).
+ *
+ * Returned Value:
+ * The flsll() function will return the index of the last bit set. If j is
+ * 0, then flsll() will return 0.
+ *
+ ****************************************************************************/
+
+int flsll(long long j)
+{
+ int ret = 0;
+
+ if (j != 0)
+ {
+#ifdef CONFIG_HAVE_BUILTIN_CLZ
+ /* Count leading zeros function can be used to implement fls. */
+
+ ret = NBITS - __builtin_clzll(j);
+#else
+ unsigned long long value = (unsigned long long)j;
+ int bitno;
+
+ for (bitno = 1; bitno <= NBITS; bitno++, value >>= 1)
+ {
+ if (value == 1)
+ {
+ ret = bitno;
+ break;
+ }
+ }
+#endif
+ }
+
+ return ret;
+}
+
+#endif
+