Merged nuttx/nuttx/master into master

This commit is contained in:
Masayuki Ishikawa 2017-03-25 21:11:54 +09:00
commit 37fd76fa77
36 changed files with 880 additions and 80 deletions

View File

@ -8,7 +8,7 @@
<tr align="center" bgcolor="#e4e4e4"> <tr align="center" bgcolor="#e4e4e4">
<td> <td>
<h1><big><font color="#3c34ec"><i>NuttX README Files</i></font></big></h1> <h1><big><font color="#3c34ec"><i>NuttX README Files</i></font></big></h1>
<p>Last Updated: March 21, 2017</p> <p>Last Updated: March 23, 2017</p>
</td> </td>
</tr> </tr>
</table> </table>
@ -68,6 +68,8 @@ nuttx/
| | `- <a href="https://bitbucket.org/nuttx/nuttx/src/master/configs/c5471evm/README.txt" target="_blank"><b><i>README.txt</i></b></a> | | `- <a href="https://bitbucket.org/nuttx/nuttx/src/master/configs/c5471evm/README.txt" target="_blank"><b><i>README.txt</i></b></a>
| |- cc3200-launchpad/ | |- cc3200-launchpad/
| | `- <a href="https://bitbucket.org/nuttx/nuttx/src/master/configs/cc3200-launchpad/README.txt" target="_blank"><b><i>README.txt</i></b></a> | | `- <a href="https://bitbucket.org/nuttx/nuttx/src/master/configs/cc3200-launchpad/README.txt" target="_blank"><b><i>README.txt</i></b></a>
| |- clicker2-stm32/
| | `- <a href="https://bitbucket.org/nuttx/nuttx/src/master/configs/clicker2-stm32/README.txt" target="_blank"><b><i>README.txt</i></b></a>
| |- cloudctrl/ | |- cloudctrl/
| | `- <a href="https://bitbucket.org/nuttx/nuttx/src/master/configs/cloudctrl/README.txt" target="_blank"><b><i>README.txt</i></b></a> | | `- <a href="https://bitbucket.org/nuttx/nuttx/src/master/configs/cloudctrl/README.txt" target="_blank"><b><i>README.txt</i></b></a>
| |- demo9s12ne64/ | |- demo9s12ne64/

View File

@ -1453,6 +1453,8 @@ nuttx/
| | `- README.txt | | `- README.txt
| |- cc3200-launchpad/ | |- cc3200-launchpad/
| | `- README.txt | | `- README.txt
| |- clicker2-stm32
| | `- README.txt
| |- cloudctrl | |- cloudctrl
| | `- README.txt | | `- README.txt
| |- demo0s12ne64/ | |- demo0s12ne64/

View File

@ -2629,9 +2629,9 @@ config STM32_FLASH_PREFETCH
default y if STM32_STM32F427 || STM32_STM32F429 || STM32_STM32F446 default y if STM32_STM32F427 || STM32_STM32F429 || STM32_STM32F446
default n default n
---help--- ---help---
Enable FLASH prefetch and F2 and F4 parts (FLASH pre-fetch is always enabled 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 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. properly and enabling this option may interfere with ADC accuracy.
config STM32_FLASH_WORKAROUND_DATA_CACHE_CORRUPTION_ON_RWW config STM32_FLASH_WORKAROUND_DATA_CACHE_CORRUPTION_ON_RWW
bool "Workaround for FLASH data cache corruption" bool "Workaround for FLASH data cache corruption"
@ -6201,12 +6201,11 @@ config STM32_I2C_DUTY16_9
config STM32_I2C_DMA config STM32_I2C_DMA
bool "I2C DMA Support" bool "I2C DMA Support"
default n default n
depends on STM32_I2C && STM32_STM32F40XX && STM32_DMA1 depends on STM32_I2C && STM32_STM32F40XX && STM32_DMA1 && !I2C_POLLED
---help--- ---help---
This option enables the DMA for I2C transfers. This option enables the DMA for I2C transfers.
Note: The user can define CONFIG_I2C_DMAPRIO: a custom priority value for the 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. I2C dma streams, else the default priority level is set to medium.
Note: This option is compatible with CONFIG_I2C_POLLED.
endmenu endmenu

View File

@ -324,10 +324,10 @@
# define FLASH_CR_OBL_LAUNCH (1 << 13) /* Bit 13: Force option byte loading */ # define FLASH_CR_OBL_LAUNCH (1 << 13) /* Bit 13: Force option byte loading */
# endif # endif
#elif defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX) #elif defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX)
# define FLASH_CR_PG (1 << 0) /* Bit 0: Programming */ # define FLASH_CR_PG (1 << 0) /* Bit 0: Programming */
# define FLASH_CR_SER (1 << 1) /* Bit 1: Sector Erase */ # 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_MER (1 << 2) /* Bit 2: Mass Erase sectors 0..11 */
# define FLASH_CR_SNB_SHIFT (3) /* Bits 3-6: Sector number */ # define FLASH_CR_SNB_SHIFT (3) /* Bits 3-6: Sector number */
#if defined(CONFIG_STM32_STM32F427) || defined(CONFIG_STM32_STM32F429) #if defined(CONFIG_STM32_STM32F427) || defined(CONFIG_STM32_STM32F429)
# define FLASH_CR_SNB_MASK (31 << FLASH_CR_SNB_SHIFT) # 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 */ # 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_MASK (15 << FLASH_CR_SNB_SHIFT)
# define FLASH_CR_SNB(n) ((n) << FLASH_CR_SNB_SHIFT) /* Sector n, n=0..11 */ # define FLASH_CR_SNB(n) ((n) << FLASH_CR_SNB_SHIFT) /* Sector n, n=0..11 */
#endif #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_MASK (3 << FLASH_CR_PSIZE_SHIFT)
# define FLASH_CR_PSIZE_X8 (0 << FLASH_CR_PSIZE_SHIFT) /* 00 program x8 */ # 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_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_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_PSIZE_X64 (3 << FLASH_CR_PSIZE_SHIFT) /* 11 program x64 */
# define FLASH_CR_STRT (1 << 16) /* Bit 16: Start Erase */ # 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_EOPIE (1 << 24) /* Bit 24: End of operation interrupt enable */
# define FLASH_CR_ERRIE (1 << 25) /* Bit 25: Error 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_LOCK (1 << 31) /* Bit 31: Lock */
#endif #endif
#if defined(CONFIG_STM32_STM32F427) || defined(CONFIG_STM32_STM32F429) #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 #endif
/* Flash Option Control Register (OPTCR) */ /* Flash Option Control Register (OPTCR) */
@ -375,7 +375,7 @@
/* Flash Option Control Register (OPTCR1) */ /* Flash Option Control Register (OPTCR1) */
#if defined(CONFIG_STM32_STM32F427) || defined(CONFIG_STM32_STM32F429) #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_NWRP_MASK (0xfff << FLASH_OPTCR_NWRP_SHIFT)
# define FLASH_OPTCR1_BFB2_SHIFT (4) /* Bits 4: Dual-bank Boot option byte */ # define FLASH_OPTCR1_BFB2_SHIFT (4) /* Bits 4: Dual-bank Boot option byte */
@ -384,7 +384,7 @@
#endif #endif
#if defined(CONFIG_STM32_STM32F446) #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) # define FLASH_OPTCR1_NWRP_MASK (0xff << FLASH_OPTCR_NWRP_SHIFT)
#endif #endif

View File

@ -128,6 +128,7 @@ static void flash_lock(void)
modifyreg32(STM32_FLASH_CR, 0, FLASH_CR_LOCK); 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) static void data_cache_disable(void)
{ {
modifyreg32(STM32_FLASH_ACR, FLASH_ACR_DCEN, 0); 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); modifyreg32(STM32_FLASH_ACR, 0, FLASH_ACR_DCEN);
} }
#endif /* defined(CONFIG_STM32_FLASH_WORKAROUND_DATA_CACHE_CORRUPTION_ON_RWW) */
/************************************************************************************ /************************************************************************************
* Public Functions * Public Functions
@ -288,6 +290,7 @@ ssize_t up_progmem_erasepage(size_t page)
#if !defined(CONFIG_STM32_STM32F40XX) #if !defined(CONFIG_STM32_STM32F40XX)
if (!(getreg32(STM32_RCC_CR) & RCC_CR_HSION)) if (!(getreg32(STM32_RCC_CR) & RCC_CR_HSION))
{ {
sem_unlock();
return -EPERM; return -EPERM;
} }
#endif #endif

View File

@ -1204,6 +1204,9 @@ static inline void stm32_i2c_enablefsmc(uint32_t ahbenr)
static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv) static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv)
{ {
#ifndef CONFIG_I2C_POLLED
uint32_t regval;
#endif
uint32_t status; uint32_t status;
i2cinfo("I2C ISR called\n"); i2cinfo("I2C ISR called\n");
@ -1867,7 +1870,6 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv)
#else #else
/* Clear all interrupts */ /* Clear all interrupts */
uint32_t regval;
regval = stm32_i2c_getreg(priv, STM32_I2C_CR2_OFFSET); regval = stm32_i2c_getreg(priv, STM32_I2C_CR2_OFFSET);
regval &= ~I2C_CR2_ALLINTS; regval &= ~I2C_CR2_ALLINTS;
stm32_i2c_putreg(priv, STM32_I2C_CR2_OFFSET, regval); stm32_i2c_putreg(priv, STM32_I2C_CR2_OFFSET, regval);

View File

@ -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); stm32_putreg16(priv, STM32_GTIM_SR_OFFSET, regval & ~GTIM_SR_UIF);
/* Check the direction bit in the CR1 register and add or subtract the /* 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); regval = stm32_getreg16(priv, STM32_GTIM_CR1_OFFSET);
if ((regval & ATIM_CR1_DIR) != 0) if ((regval & ATIM_CR1_DIR) != 0)
{ {
priv->position -= (int32_t)0x0000ffff; priv->position -= (int32_t)0x00010000;
} }
else else
{ {
priv->position += (int32_t)0x0000ffff; priv->position += (int32_t)0x00010000;
} }
return OK; return OK;

View File

@ -1261,6 +1261,15 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv)
priv->status = status; 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 /* Check if this is a new transmission so to set up the
* trace table accordingly. * 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); 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("Address ACKed beginning data reception\n");
i2cinfo("short read N=1: programming stop bit\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"); 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->ptr++ = stm32_i2c_getreg(priv, STM32_I2C_DR_OFFSET);
priv->dcnt--; priv->dcnt--;
*priv->ptr++ = stm32_i2c_getreg(priv, STM32_I2C_DR_OFFSET); *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); 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 */ /* read dcnt = 2 */
@ -2015,7 +2048,6 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv)
#else #else
/* Clear all interrupts */ /* Clear all interrupts */
uint32_t regval;
regval = stm32_i2c_getreg(priv, STM32_I2C_CR2_OFFSET); regval = stm32_i2c_getreg(priv, STM32_I2C_CR2_OFFSET);
regval &= ~I2C_CR2_ALLINTS; regval &= ~I2C_CR2_ALLINTS;
stm32_i2c_putreg(priv, STM32_I2C_CR2_OFFSET, regval); 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. * 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 /* Let the I2C periph know to stop DMA transfers, also is used by ISR to check
* if DMA is done. * 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); regval |= (I2C_CR2_ITERREN | I2C_CR2_ITEVFEN);
stm32_i2c_putreg(priv, STM32_I2C_CR2_OFFSET, regval); stm32_i2c_putreg(priv, STM32_I2C_CR2_OFFSET, regval);
#endif #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 */ #endif /* ifdef CONFIG_STM32_I2C_DMA */

View File

@ -126,7 +126,7 @@
# endif # endif
#endif #endif
/* There are 4 possible heap configurations: /* There are 5 possible heap configurations:
* *
* Configuration 1. System SRAM1 (only) * Configuration 1. System SRAM1 (only)
* CONFIG_MM_REGIONS == 1 * CONFIG_MM_REGIONS == 1

View File

@ -89,7 +89,7 @@ OBJS = $(AOBJS) $(COBJS)
BIN = libconfigs$(LIBEXT) BIN = libconfigs$(LIBEXT)
all: $(BIN) all: $(BIN)
.PHONY: depend ccontext clean_context clean distclean .PHONY: depend context clean_context clean distclean
$(AOBJS): %$(OBJEXT): %.S $(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@) $(call ASSEMBLE, $<, $@)

View File

@ -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/<subdir>
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 <subdir> 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

View File

@ -269,8 +269,8 @@
* Assuming RS-232 connverted connected on mikroMB1/12 * Assuming RS-232 connverted connected on mikroMB1/12
*/ */
#define GPIO_USART2_RX GPIO_USART2_RX_2 /* PD6 */ #define GPIO_USART2_RX GPIO_USART2_RX_2 /* PD6 */
#define GPIO_USART2_TX GPIO_USART2_TX_2 /* PD5 */ #define GPIO_USART2_TX GPIO_USART2_TX_2 /* PD5 */
#define GPIO_USART3_RX GPIO_USART3_RX_3 /* PD9 */ #define GPIO_USART3_RX GPIO_USART3_RX_3 /* PD9 */
#define GPIO_USART3_TX GPIO_USART3_TX_3 /* PD8 / #define GPIO_USART3_TX GPIO_USART3_TX_3 /* PD8 /

View File

@ -144,10 +144,10 @@ CONFIG_ARM_HAVE_MPU_UNIFIED=y
# CONFIG_ARMV7M_HAVE_ITCM is not set # CONFIG_ARMV7M_HAVE_ITCM is not set
# CONFIG_ARMV7M_HAVE_DTCM is not set # CONFIG_ARMV7M_HAVE_DTCM is not set
# CONFIG_ARMV7M_TOOLCHAIN_IARL 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_CODEREDL is not set
# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL 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_OABI_TOOLCHAIN is not set
CONFIG_ARMV7M_HAVE_STACKCHECK=y CONFIG_ARMV7M_HAVE_STACKCHECK=y
# CONFIG_ARMV7M_STACKCHECK is not set # CONFIG_ARMV7M_STACKCHECK is not set

View File

@ -42,8 +42,7 @@
* *
* When booting from FLASH, FLASH memory is aliased to address 0x0000:0000 * 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 * where the code expects to begin execution by jumping to the entry point in
* the 0x0800:0000 address * the 0x0800:0000 address range.
* range.
*/ */
MEMORY MEMORY

View File

@ -33,8 +33,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __CONFIGS_OLIMEX_STM32_P407_SRC_H #ifndef __CONFIGS_CLICKER2_STM32_SRC_CLICKER2_H
#define __CONFIGS_OLIMEX_STM32_P407_SRC_H #define __CONFIGS_CLICKER2_STM32_SRC_CLICKER2_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -212,7 +212,7 @@
#define GPIO_MB1_RST (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\ #define GPIO_MB1_RST (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_CLEAR|GPIO_PORTE|GPIO_PIN7) 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) GPIO_OUTPUT_CLEAR|GPIO_PORTE|GPIO_PIN13)
/* Interrupts /* Interrupts
@ -287,4 +287,4 @@ int stm32_can_setup(void);
#endif #endif
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#endif /* __CONFIGS_OLIMEX_STM32_P407_SRC_H */ #endif /* __CONFIGS_CLICKER2_STM32_SRC_CLICKER2_H */

View File

@ -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 * Copyright (C) 2013 Alan Carvalho de Assis
* Author: Alan Carvalho de Assis <acassis@gmail.com> * Author: Alan Carvalho de Assis <acassis@gmail.com>
@ -38,34 +38,36 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __CONFIGS_FREEDOM_KL25Z_INCLUDE_KL_CC3000_H
#define __CONFIGS_FREEDOM_KL25Z_INCLUDE_KL_CC3000_H 1
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
long ReadWlanInterruptPin(void); long ReadWlanInterruptPin(void);
/* /* Enable WiFi Interrupt */
* Enable WiFi Interrupt
*/
void WlanInterruptEnable(void); void WlanInterruptEnable(void);
/* /* Disable WiFi Interrupt */
* Disable WiFi Interrupt
*/
void WlanInterruptDisable(void); void WlanInterruptDisable(void);
/* /* Enable/Disable WiFi */
* Enable/Disable WiFi
*/
void WriteWlanEnablePin(uint8_t val); void WriteWlanEnablePin(uint8_t val);
/* /* Assert CC3000 CS */
* Assert CC3000 CS
*/
void AssertWlanCS(void); void AssertWlanCS(void);
/* /*
@ -73,8 +75,9 @@ void AssertWlanCS(void);
*/ */
void DeassertWlanCS(void); void DeassertWlanCS(void);
/* /* Setup needed pins */
* Setup needed pins
*/
void Wlan_Setup(void); void Wlan_Setup(void);
#endif /* __CONFIGS_FREEDOM_KL25Z_INCLUDE_KL_CC3000_H */

View File

@ -43,7 +43,7 @@ CSRCS += kl_appinit.c
endif endif
ifeq ($(CONFIG_WL_CC3000),y) ifeq ($(CONFIG_WL_CC3000),y)
CSRCS += kl_wifi.c CSRCS += kl_cc3000.c
endif endif
ifeq ($(CONFIG_KL_TSI),y) ifeq ($(CONFIG_KL_TSI),y)

View File

@ -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 * Copyright (C) 2014 Alan Carvalho de Assis
* Author: Alan Carvalho de Assis <acassis@gmail.com> * Author: Alan Carvalho de Assis <acassis@gmail.com>
@ -38,7 +38,7 @@
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <arch/board/kl_wifi.h> #include <arch/board/kl_cc3000.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
@ -212,12 +212,12 @@ static void wl_enable_irq(FAR struct cc3000_config_s *state, bool enable)
if (enable) if (enable)
{ {
(void)kl_gpioirqattach(GPIO_WIFI_INT, priv->handler, priv->arg); (void)kl_gpioirqattach(GPIO_WIFI_INT, priv->handler, priv->arg);
kl_gpioirqenable(GPIO_WIFI_INT); kl_gpioirqenable(GPIO_WIFI_INT);
} }
else else
{ {
(void)kl_gpioirqattach(GPIO_WIFI_INT, NULL, NULL); (void)kl_gpioirqattach(GPIO_WIFI_INT, NULL, NULL);
kl_gpioirqdisable(GPIO_WIFI_INT); kl_gpioirqdisable(GPIO_WIFI_INT);
} }
} }

View File

@ -49,7 +49,7 @@ CSRCS += stm32_buttons.c
endif endif
ifeq ($(CONFIG_WL_CC3000),y) ifeq ($(CONFIG_WL_CC3000),y)
CSRCS += stm32_wireless.c CSRCS += stm32_cc3000.c
ifeq ($(CONFIG_CC3000_PROBES),) ifeq ($(CONFIG_CC3000_PROBES),)
CSRCS += stm32_io.c CSRCS += stm32_io.c
endif endif

View File

@ -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. * Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Laurent Latil <laurent@latil.nom.fr> * Author: Laurent Latil <laurent@latil.nom.fr>

View File

@ -66,7 +66,7 @@ CSRCS += stm32_composite.c
endif endif
ifeq ($(CONFIG_WL_CC3000),y) ifeq ($(CONFIG_WL_CC3000),y)
CSRCS += stm32_wireless.c CSRCS += stm32_cc3000.c
endif endif
ifeq ($(CONFIG_CC3000_PROBES),) ifeq ($(CONFIG_CC3000_PROBES),)

View File

@ -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. * Copyright (C) 2009, 2013 Gregory Nutt. All rights reserved.
* Author: Laurent Latil <laurent@latil.nom.fr> * Author: Laurent Latil <laurent@latil.nom.fr>

View File

@ -44,7 +44,7 @@ CSRCS += stm32_pwm.c
endif endif
ifeq ($(CONFIG_WL_NRF24L01),y) ifeq ($(CONFIG_WL_NRF24L01),y)
CSRCS += stm32_wireless.c CSRCS += stm32_cc3000.c
endif endif
ifeq ($(CONFIG_LIB_BOARDCTL),y) ifeq ($(CONFIG_LIB_BOARDCTL),y)

View File

@ -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. * Copyright (C) 2009, 2013, 2017 Gregory Nutt. All rights reserved.
* Author: Laurent Latil <laurent@latil.nom.fr> * Author: Laurent Latil <laurent@latil.nom.fr>

View File

@ -86,7 +86,7 @@ CSRCS += stm32_veml6070.c
endif endif
ifeq ($(CONFIG_WL_NRF24L01),y) ifeq ($(CONFIG_WL_NRF24L01),y)
CSRCS += stm32_wireless.c CSRCS += stm32_cc3000.c
endif endif
ifeq ($(CONFIG_USBDEV),y) ifeq ($(CONFIG_USBDEV),y)

View File

@ -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. * Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Laurent Latil <laurent@latil.nom.fr> * Author: Laurent Latil <laurent@latil.nom.fr>

View File

@ -64,6 +64,18 @@
# define UNUSED(a) ((void)(a)) # 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 /* Attributes
* *
* GCC supports weak symbols which can be used to reduce code size because * GCC supports weak symbols which can be used to reduce code size because

View File

@ -105,14 +105,14 @@ typedef struct sem_s sem_t;
#ifdef CONFIG_PRIORITY_INHERITANCE #ifdef CONFIG_PRIORITY_INHERITANCE
# if CONFIG_SEM_PREALLOCHOLDERS > 0 # if CONFIG_SEM_PREALLOCHOLDERS > 0
# define SEM_INITIALIZER(c) \ # define SEM_INITIALIZER(c) \
{(c), 0, NULL} /* semcount, flags, hhead */ {(c), 0, NULL} /* semcount, flags, hhead */
# else # else
# define SEM_INITIALIZER(c) \ # define SEM_INITIALIZER(c) \
{(c), 0, {SEMHOLDER_INITIALIZER, SEMHOLDER_INITIALIZER}} /* semcount, flags, holder[2] */ {(c), 0, {SEMHOLDER_INITIALIZER, SEMHOLDER_INITIALIZER}} /* semcount, flags, holder[2] */
# endif # endif
#else #else
# define SEM_INITIALIZER(c) \ # define SEM_INITIALIZER(c) \
{(c)} /* semcount */ {(c)} /* semcount */
#endif #endif
/**************************************************************************** /****************************************************************************

View File

@ -114,6 +114,17 @@ static inline FAR char *rindex(FAR const char *s, int c)
****************************************************************************/ ****************************************************************************/
int ffs(int j); 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 strcasecmp(FAR const char *, FAR const char *);
int strncasecmp(FAR const char *, FAR const char *, size_t); int strncasecmp(FAR const char *, FAR const char *, size_t);

View File

@ -35,7 +35,8 @@
# Add the string C files to the build # 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_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_stpcpy.c lib_strcasecmp.c lib_strcat.c lib_strchr.c
CSRCS += lib_strcpy.c lib_strcmp.c lib_strcspn.c lib_strdup.c CSRCS += lib_strcpy.c lib_strcmp.c lib_strcspn.c lib_strdup.c

View File

@ -33,11 +33,11 @@
* *
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include <nuttx/compiler.h>
#include <strings.h> #include <strings.h>
/**************************************************************************** /****************************************************************************
@ -55,11 +55,11 @@
* *
* Description: * Description:
* The ffs() function will find the first bit set (beginning with the least * 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). * numbered starting at one (the least significant bit).
* *
* Returned Value: * 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. * 0, then ffs() will return 0.
* *
****************************************************************************/ ****************************************************************************/
@ -70,6 +70,11 @@ int ffs(int j)
if (j != 0) 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; unsigned int value = (unsigned int)j;
int bitno; int bitno;
@ -81,6 +86,7 @@ int ffs(int j)
break; break;
} }
} }
#endif
} }
return ret; return ret;

93
libc/string/lib_ffsl.c Normal file
View File

@ -0,0 +1,93 @@
/****************************************************************************
* libc/string/lib_ffsl.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <nuttx/compiler.h>
#include <strings.h>
/****************************************************************************
* 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;
}

97
libc/string/lib_ffsll.c Normal file
View File

@ -0,0 +1,97 @@
/****************************************************************************
* libc/string/lib_ffsll.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <nuttx/compiler.h>
#include <strings.h>
/****************************************************************************
* 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

93
libc/string/lib_fls.c Normal file
View File

@ -0,0 +1,93 @@
/****************************************************************************
* libc/string/lib_fls.c
*
* Copyright (C) 2017 Haltian Ltd. All rights reserved.
* Author: Jussi Kivilinna <jussi.kivilinna@haltian.com>
*
* 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 <nuttx/compiler.h>
#include <strings.h>
/****************************************************************************
* 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;
}

93
libc/string/lib_flsl.c Normal file
View File

@ -0,0 +1,93 @@
/****************************************************************************
* libc/string/lib_fls.c
*
* Copyright (C) 2017 Haltian Ltd. All rights reserved.
* Author: Jussi Kivilinna <jussi.kivilinna@haltian.com>
*
* 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 <nuttx/compiler.h>
#include <strings.h>
/****************************************************************************
* 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;
}

98
libc/string/lib_flsll.c Normal file
View File

@ -0,0 +1,98 @@
/****************************************************************************
* libc/string/lib_fls.c
*
* Copyright (C) 2017 Haltian Ltd. All rights reserved.
* Author: Jussi Kivilinna <jussi.kivilinna@haltian.com>
*
* 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 <nuttx/compiler.h>
#include <strings.h>
/****************************************************************************
* 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