diff --git a/Documentation/README.html b/Documentation/README.html index 01a27ce6446..8cc093715d4 100644 --- a/Documentation/README.html +++ b/Documentation/README.html @@ -8,7 +8,7 @@

NuttX README Files

-

Last Updated: March 23, 2017

+

Last Updated: April 8, 2017

@@ -362,6 +362,8 @@ nuttx/ | | `- README.txt | `- README.txt |- net/ + | |- sixlowpan/ + | | `- README.txt | `- README.txt |- syscall/ | `- README.txt diff --git a/README.txt b/README.txt index 5d3721f4c50..af17a2334dd 100644 --- a/README.txt +++ b/README.txt @@ -1750,6 +1750,8 @@ nuttx/ | | `- README.txt | `- README.txt |- net/ + | |- sixlowpan + | | `- README.txt | `- README.txt |- syscall/ | `- README.txt diff --git a/TODO b/TODO index d19ac0f067a..93db26ced47 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated March 26, 2017) +NuttX TODO List (Last updated April 12, 2017) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -9,7 +9,7 @@ issues related to each board port. nuttx/: - (10) Task/Scheduler (sched/) + (11) Task/Scheduler (sched/) (1) SMP (1) Memory Management (mm/) (0) Power Management (drivers/pm) @@ -108,9 +108,10 @@ o Task/Scheduler (sched/) 2. They run in supervisor mode (if applicable), and 3. They do not obey any setup of PIC or address environments. Do they need to? - 4. In the case of task_delete() and pthread_cancel(), these - callbacks will run on the thread of execution and address - context of the caller of task. That is very bad! + 4. In the case of task_delete() and pthread_cancel() without + defferred cancellation, these callbacks will run on the + thread of execution and address context of the caller of + task_delete() or pthread_cancel(). That is very bad! The fix for all of these issues it to have the callbacks run on the caller's thread as is currently done with @@ -185,6 +186,47 @@ o Task/Scheduler (sched/) Priority: Low. Things are just the way that we want them for the way that NuttX is used today. + Title: INTERNAL VERSIONS OF USER FUNCTIONS + Description: The internal NuttX logic uses the same interfaces as does + the application. That sometime produces a problem because + there is "overloaded" functionality in those user interfaces + that are not desireable. + + For example, having cancellation points hidden inside of the + OS can cause non-cancellation point interfaces to behave + strangely. There was a change recently in pthread_cond_wait() + and pthread_cond_timedwait() recently to effectively disable + the cancellation point behavior of sem_init(). This was + accomplished with two functions: pthread_disable_cancel() + and pthread_enable_cancel() + + Here is another issue:  Internal OS functions should not set + errno and should never have to look at the errno value to + determine the cause of the failure.  The errno is provided + for compatibility with POSIX application interface + requirements and really doesn't need to be used within the + OS. + + Both of these could be fixed if there were special internal + versions these functions.  For example, there could be a an + nx_sem_wait() that does all of the same things as sem_wait() + was does not create a cancellation point and does not set + the errno value on failures. + + Everything inside the OS would use nx_sem_wait(). + Applications would call sem_wait() which would just be a + wrapper around nx_sem_wait() that adds the cancellation point + and that sets the errno value on failures. + + Changes like that could clean up some of this internal + craziness.  The condition variable change described above is + really a "bandaid" to handle the case that sem_wait() is a + cancellation point. + Status: Open + Priority: Low. Things are working OK the way they are. But the design + could be improved and made a little more efficient with this + change. + o SMP ^^^ diff --git a/arch/arm/src/stm32/chip/stm32_exti.h b/arch/arm/src/stm32/chip/stm32_exti.h index 791bed1f174..e18b60cf71b 100644 --- a/arch/arm/src/stm32/chip/stm32_exti.h +++ b/arch/arm/src/stm32/chip/stm32_exti.h @@ -188,9 +188,9 @@ /* Pending register */ -#define EXTI_IMR_BIT(n) STM32_EXTI_BIT(n) /* 1=Selected trigger request occurred */ -#define EXTI_IMR_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ -#define EXTI_IMR_MASK STM32_EXTI_MASK +#define EXTI_PR_BIT(n) STM32_EXTI_BIT(n) /* 1=Selected trigger request occurred */ +#define EXTI_PR_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ +#define EXTI_PR_MASK STM32_EXTI_MASK /* Compatibility Definitions ********************************************************/ diff --git a/arch/arm/src/stm32/stm32_comp.h b/arch/arm/src/stm32/stm32_comp.h index 16a0ad69713..ab28cac186a 100644 --- a/arch/arm/src/stm32/stm32_comp.h +++ b/arch/arm/src/stm32/stm32_comp.h @@ -44,6 +44,8 @@ #include "chip.h" +#ifdef CONFIG_STM32_COMP + #if defined(CONFIG_STM32_STM32F30XX) # error "COMP support for STM32F30XX not implemented yet" #elif defined(CONFIG_STM32_STM32F33XX) @@ -211,4 +213,5 @@ FAR struct comp_dev_s* stm32_compinitialize(int intf); #endif #endif /* __ASSEMBLY__ */ +#endif /* CONFIG_STM23_COMP */ #endif /* __ARCH_ARM_SRC_STM32_STM32_COMP_H */ diff --git a/arch/arm/src/stm32f7/Kconfig b/arch/arm/src/stm32f7/Kconfig index d8eabdcd4bd..2c21fadf610 100644 --- a/arch/arm/src/stm32f7/Kconfig +++ b/arch/arm/src/stm32f7/Kconfig @@ -1634,7 +1634,7 @@ config SERIAL_DISABLE_REORDERING config STM32F7_FLOWCONTROL_BROKEN bool "Use Software UART RTS flow control" - depends on STM32F7_USART + depends on STM32F7_USART && SERIAL_IFLOWCONTROL_WATERMARKS default n ---help--- Enable UART RTS flow control using Software. Because STM diff --git a/arch/arm/src/stm32f7/chip/stm32_exti.h b/arch/arm/src/stm32f7/chip/stm32_exti.h index 288f51b228c..8663d2f08e7 100644 --- a/arch/arm/src/stm32f7/chip/stm32_exti.h +++ b/arch/arm/src/stm32f7/chip/stm32_exti.h @@ -125,9 +125,9 @@ /* Pending register */ -#define EXTI_IMR_BIT(n) STM32_EXTI_BIT(n) /* 1=Selected trigger request occurred */ -#define EXTI_IMR_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ -#define EXTI_IMR_MASK STM32_EXTI_MASK +#define EXTI_PR_BIT(n) STM32_EXTI_BIT(n) /* 1=Selected trigger request occurred */ +#define EXTI_PR_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ +#define EXTI_PR_MASK STM32_EXTI_MASK #endif /* CONFIG_STM32F7_STM32F74XX || CONFIG_STM32F7_STM32F75XX || CONFIG_STM32F7_STM32F76XX || CONFIG_STM32F7_STM32F77XX */ #endif /* __ARCH_ARM_SRC_STM32F7_CHIP_STM32_EXTI_H */ diff --git a/arch/arm/src/stm32f7/stm32_serial.c b/arch/arm/src/stm32f7/stm32_serial.c index ec97ec7096c..5c2b8b74bcc 100644 --- a/arch/arm/src/stm32f7/stm32_serial.c +++ b/arch/arm/src/stm32f7/stm32_serial.c @@ -220,43 +220,56 @@ /* Warnings for potentially unsafe configuration combinations. */ +#if defined(CONFIG_STM32F7_FLOWCONTROL_BROKEN) && \ + !defined(CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS) +# error "CONFIG_STM32F7_FLOWCONTROL_BROKEN requires \ + CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS to be enabled." +#endif + +#ifndef CONFIG_STM32F7_FLOWCONTROL_BROKEN /* Combination of RXDMA + IFLOWCONTROL does not work as one might expect. * Since RXDMA uses circular DMA-buffer, DMA will always keep reading new * data from USART peripheral even if DMA buffer underruns. Thus this * combination only does following: RTS is asserted on USART setup and * deasserted on shutdown and does not perform actual RTS flow-control. + * + * With SW flow-control, RTS is asserted before UART receive buffer fully + * fills, thus preventing data loss if application is slow to process data + * from serial device node. However, if RxDMA interrupt is blocked for too + * long, data loss is still possible as SW flow-control would also be + * blocked. */ -#if defined(CONFIG_USART1_RXDMA) && defined(CONFIG_USART1_IFLOWCONTROL) -# warning "RXDMA and IFLOWCONTROL both enabled for USART1. \ - This combination can lead to data loss." -#endif +# if defined(CONFIG_USART1_RXDMA) && defined(CONFIG_USART1_IFLOWCONTROL) +# warning "RXDMA and IFLOWCONTROL both enabled for USART1. \ + This combination can lead to data loss." +# endif -#if defined(CONFIG_USART2_RXDMA) && defined(CONFIG_USART2_IFLOWCONTROL) -# warning "RXDMA and IFLOWCONTROL both enabled for USART2. \ - This combination can lead to data loss." -#endif +# if defined(CONFIG_USART2_RXDMA) && defined(CONFIG_USART2_IFLOWCONTROL) +# warning "RXDMA and IFLOWCONTROL both enabled for USART2. \ + This combination can lead to data loss." +# endif -#if defined(CONFIG_USART3_RXDMA) && defined(CONFIG_USART3_IFLOWCONTROL) -# warning "RXDMA and IFLOWCONTROL both enabled for USART3. \ - This combination can lead to data loss." -#endif +# if defined(CONFIG_USART3_RXDMA) && defined(CONFIG_USART3_IFLOWCONTROL) +# warning "RXDMA and IFLOWCONTROL both enabled for USART3. \ + This combination can lead to data loss." +# endif -#if defined(CONFIG_USART6_RXDMA) && defined(CONFIG_USART6_IFLOWCONTROL) -# warning "RXDMA and IFLOWCONTROL both enabled for USART6. \ - This combination can lead to data loss." -#endif +# if defined(CONFIG_USART6_RXDMA) && defined(CONFIG_USART6_IFLOWCONTROL) +# warning "RXDMA and IFLOWCONTROL both enabled for USART6. \ + This combination can lead to data loss." +# endif -#if defined(CONFIG_UART7_RXDMA) && defined(CONFIG_UART7_IFLOWCONTROL) -# warning "RXDMA and IFLOWCONTROL both enabled for UART7. \ - This combination can lead to data loss." -#endif - -#if defined(CONFIG_UART8_RXDMA) && defined(CONFIG_UART8_IFLOWCONTROL) -# warning "RXDMA and IFLOWCONTROL both enabled for UART8. \ - This combination can lead to data loss." -#endif +# if defined(CONFIG_UART7_RXDMA) && defined(CONFIG_UART7_IFLOWCONTROL) +# warning "RXDMA and IFLOWCONTROL both enabled for UART7. \ + This combination can lead to data loss." +# endif +# if defined(CONFIG_UART8_RXDMA) && defined(CONFIG_UART8_IFLOWCONTROL) +# warning "RXDMA and IFLOWCONTROL both enabled for UART8. \ + This combination can lead to data loss." +# endif +#endif /* CONFIG_STM32F7_FLOWCONTROL_BROKEN */ /**************************************************************************** * Private Types @@ -2211,6 +2224,22 @@ static bool up_rxflowcontrol(struct uart_dev_s *dev, /* Assert/de-assert nRTS set it high resume/stop sending */ stm32_gpiowrite(priv->rts_gpio, upper); + + if (upper) + { + /* With heavy Rx traffic, RXNE might be set and data pending. + * Returning 'true' in such case would cause RXNE left unhandled + * and causing interrupt storm. Sending end might be also be slow + * to react on nRTS, and returning 'true' here would prevent + * processing that data. + * + * Therefore, return 'false' so input data is still being processed + * until sending end reacts on nRTS signal and stops sending more. + */ + + return false; + } + return upper; } diff --git a/arch/arm/src/stm32l4/chip/stm32l4_exti.h b/arch/arm/src/stm32l4/chip/stm32l4_exti.h index 1fb1628a7a9..f9f087a051e 100644 --- a/arch/arm/src/stm32l4/chip/stm32l4_exti.h +++ b/arch/arm/src/stm32l4/chip/stm32l4_exti.h @@ -167,13 +167,13 @@ /* Pending register */ -#define EXTI_IMR1_BIT(n) STM32L4_EXTI1_BIT(n) /* 1=Selected trigger request occurred */ -#define EXTI_IMR1_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ -#define EXTI_IMR1_MASK STM32L4_EXTI1_MASK +#define EXTI_PR1_BIT(n) STM32L4_EXTI1_BIT(n) /* 1=Selected trigger request occurred */ +#define EXTI_PR1_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ +#define EXTI_PR1_MASK STM32L4_EXTI1_MASK -#define EXTI_IMR2_BIT(n) STM32L4_EXTI2_BIT(n) /* 1=Selected trigger request occurred */ -#define EXTI_IMR2_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ -#define EXTI_IMR2_MASK STM32L4_EXTI2_MASK +#define EXTI_PR2_BIT(n) STM32L4_EXTI2_BIT(n) /* 1=Selected trigger request occurred */ +#define EXTI_PR2_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ +#define EXTI_PR2_MASK STM32L4_EXTI2_MASK #endif /* __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4_EXTI_H */ diff --git a/arch/arm/src/stm32l4/chip/stm32l4x6xx_dma.h b/arch/arm/src/stm32l4/chip/stm32l4x6xx_dma.h index ab63195d2f2..6e7afac9af1 100644 --- a/arch/arm/src/stm32l4/chip/stm32l4x6xx_dma.h +++ b/arch/arm/src/stm32l4/chip/stm32l4x6xx_dma.h @@ -306,7 +306,12 @@ #define STM32L4_DMA2_CHAN6 (12) #define STM32L4_DMA2_CHAN7 (13) -#define DMACHAN_SETTING(chan, sel) ( ( ( (sel) & 0xff) << 8) | ( (chan) & 0xff) ) +/* DMA Channel settings include a channel and an alternative function. + * Channel is in bits 0..7 + * Request number is in bits 8..15 + */ + +#define DMACHAN_SETTING(chan, req) ((((req) & 0xff) << 8) | ((chan) & 0xff)) #define DMACHAN_SETTING_CHANNEL_MASK 0x00FF #define DMACHAN_SETTING_CHANNEL_SHIFT (0) #define DMACHAN_SETTING_FUNCTION_MASK 0xFF00 @@ -384,7 +389,7 @@ #define DMACHAN_SPI1_RX_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN2, 1) #define DMACHAN_SPI1_RX_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN3, 4) -#define DMACHAN_SPI1_TX_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN3, 0) +#define DMACHAN_SPI1_TX_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN3, 1) #define DMACHAN_SPI1_TX_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN4, 4) #define DMACHAN_SPI2_RX DMACHAN_SETTING(STM32L4_DMA1_CHAN4, 1) diff --git a/arch/sim/src/up_initialize.c b/arch/sim/src/up_initialize.c index fa8468196e0..5b3f1c0e9f9 100644 --- a/arch/sim/src/up_initialize.c +++ b/arch/sim/src/up_initialize.c @@ -187,7 +187,7 @@ void up_initialize(void) * separately. */ - syslog(LOG_INFO, "SIM: Initializing"); + syslog(LOG_INFO, "SIM: Initializing\n"); #endif #ifdef CONFIG_PM diff --git a/configs/avr32dev1/src/avr32_buttons.c b/configs/avr32dev1/src/avr32_buttons.c index 72191bb5855..4514a800a5e 100644 --- a/configs/avr32dev1/src/avr32_buttons.c +++ b/configs/avr32dev1/src/avr32_buttons.c @@ -120,15 +120,15 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions in the board.h header file for the meaning of each bit in * the returned value. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t retval; + uint32_t retval; retval = at32uc3_gpioread(PINMUX_GPIO_BUTTON1) ? 0 : BUTTON1; retval |= at32uc3_gpioread(PINMUX_GPIO_BUTTON2) ? 0 : BUTTON2; diff --git a/configs/bambino-200e/src/lpc43_buttons.c b/configs/bambino-200e/src/lpc43_buttons.c index 8aaeac3c95c..8f96dafd274 100644 --- a/configs/bambino-200e/src/lpc43_buttons.c +++ b/configs/bambino-200e/src/lpc43_buttons.c @@ -120,9 +120,9 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/clicker2-stm32/src/stm32_buttons.c b/configs/clicker2-stm32/src/stm32_buttons.c index 14da26b9646..00a571c817b 100644 --- a/configs/clicker2-stm32/src/stm32_buttons.c +++ b/configs/clicker2-stm32/src/stm32_buttons.c @@ -79,9 +79,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key. A low value will be sensed when the * button is pressed. @@ -110,7 +110,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/cloudctrl/src/stm32_buttons.c b/configs/cloudctrl/src/stm32_buttons.c index b62dbeb719c..574e6a15817 100644 --- a/configs/cloudctrl/src/stm32_buttons.c +++ b/configs/cloudctrl/src/stm32_buttons.c @@ -104,9 +104,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ @@ -145,7 +145,7 @@ uint8_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the + * 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning * of each bit. * diff --git a/configs/demo9s12ne64/src/m9s12_buttons.c b/configs/demo9s12ne64/src/m9s12_buttons.c index 2452139174f..addf4af1714 100644 --- a/configs/demo9s12ne64/src/m9s12_buttons.c +++ b/configs/demo9s12ne64/src/m9s12_buttons.c @@ -77,7 +77,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return 0; } diff --git a/configs/dk-tm4c129x/src/tm4c_buttons.c b/configs/dk-tm4c129x/src/tm4c_buttons.c index f5b65bee71b..7a85cda8e84 100644 --- a/configs/dk-tm4c129x/src/tm4c_buttons.c +++ b/configs/dk-tm4c129x/src/tm4c_buttons.c @@ -103,9 +103,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ @@ -137,7 +137,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/ea3131/src/lpc31_buttons.c b/configs/ea3131/src/lpc31_buttons.c index de80fdf1bc5..8b0822e649b 100644 --- a/configs/ea3131/src/lpc31_buttons.c +++ b/configs/ea3131/src/lpc31_buttons.c @@ -49,18 +49,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -77,7 +65,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return 0; } diff --git a/configs/ea3152/src/lpc31_buttons.c b/configs/ea3152/src/lpc31_buttons.c index 28b349abb0b..577692c1a15 100644 --- a/configs/ea3152/src/lpc31_buttons.c +++ b/configs/ea3152/src/lpc31_buttons.c @@ -49,18 +49,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -77,7 +65,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return 0; } diff --git a/configs/ez80f910200zco/src/ez80_buttons.c b/configs/ez80f910200zco/src/ez80_buttons.c index 6bc2aa9462b..ee76218d0d8 100644 --- a/configs/ez80f910200zco/src/ez80_buttons.c +++ b/configs/ez80f910200zco/src/ez80_buttons.c @@ -168,7 +168,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return inp(EZ80_PB_DDR) & 7; } diff --git a/configs/fire-stm32v2/src/stm32_buttons.c b/configs/fire-stm32v2/src/stm32_buttons.c index d2dd07cd8ef..d1fcbda1833 100644 --- a/configs/fire-stm32v2/src/stm32_buttons.c +++ b/configs/fire-stm32v2/src/stm32_buttons.c @@ -91,9 +91,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key. A LOW value means that the key is pressed, */ @@ -121,7 +121,7 @@ uint8_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the + * 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning * of each bit. * diff --git a/configs/freedom-k64f/src/k64_buttons.c b/configs/freedom-k64f/src/k64_buttons.c index 0c9f22e8c86..53caa760b83 100644 --- a/configs/freedom-k64f/src/k64_buttons.c +++ b/configs/freedom-k64f/src/k64_buttons.c @@ -92,9 +92,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; if (kinetis_gpioread(GPIO_SW2)) { @@ -120,7 +120,7 @@ uint8_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may * be called to collect the state of all buttons. board_buttons() returns - * an 8-bit bit set with each bit associated with a button. See the + * an 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning * of each bit. * diff --git a/configs/freedom-k66f/src/k66_buttons.c b/configs/freedom-k66f/src/k66_buttons.c index de70f31dc5f..b186d40b412 100644 --- a/configs/freedom-k66f/src/k66_buttons.c +++ b/configs/freedom-k66f/src/k66_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; if (kinetis_gpioread(GPIO_SW2)) { @@ -124,7 +124,7 @@ uint8_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may * be called to collect the state of all buttons. board_buttons() returns - * an 8-bit bit set with each bit associated with a button. See the + * an 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning * of each bit. * diff --git a/configs/hymini-stm32v/src/stm32_buttons.c b/configs/hymini-stm32v/src/stm32_buttons.c index d92be06ab9d..4dac6fc8f41 100644 --- a/configs/hymini-stm32v/src/stm32_buttons.c +++ b/configs/hymini-stm32v/src/stm32_buttons.c @@ -79,9 +79,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; bool pinValue; /* Check that state of each key */ @@ -120,7 +120,7 @@ uint8_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the + * 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning * of each bit. * diff --git a/configs/kwikstik-k40/src/k40_buttons.c b/configs/kwikstik-k40/src/k40_buttons.c index 7057ab1bd83..c66c2d858cf 100644 --- a/configs/kwikstik-k40/src/k40_buttons.c +++ b/configs/kwikstik-k40/src/k40_buttons.c @@ -74,7 +74,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { /* The KwikStik-K40 board has no standard GPIO contact buttons */ @@ -92,7 +92,7 @@ uint8_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the + * 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning * of each bit. * diff --git a/configs/launchxl-tms57004/src/tms570_buttons.c b/configs/launchxl-tms57004/src/tms570_buttons.c index c0f307d2feb..d84de8f63a4 100644 --- a/configs/launchxl-tms57004/src/tms570_buttons.c +++ b/configs/launchxl-tms57004/src/tms570_buttons.c @@ -154,12 +154,12 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return tms570_gioread(GIO_BUTTON) ? BUTTON_GIOA7_BIT : 0; } diff --git a/configs/lincoln60/src/lpc17_buttons.c b/configs/lincoln60/src/lpc17_buttons.c index bcee2e34f0f..48ea4298262 100644 --- a/configs/lincoln60/src/lpc17_buttons.c +++ b/configs/lincoln60/src/lpc17_buttons.c @@ -127,9 +127,9 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/lpc4330-xplorer/src/lpc43_buttons.c b/configs/lpc4330-xplorer/src/lpc43_buttons.c index 0d0f5db695c..9e09ce07dc0 100644 --- a/configs/lpc4330-xplorer/src/lpc43_buttons.c +++ b/configs/lpc4330-xplorer/src/lpc43_buttons.c @@ -126,9 +126,9 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/lpc4357-evb/src/lpc43_buttons.c b/configs/lpc4357-evb/src/lpc43_buttons.c index c62229d35c5..2ed50974959 100644 --- a/configs/lpc4357-evb/src/lpc43_buttons.c +++ b/configs/lpc4357-evb/src/lpc43_buttons.c @@ -129,10 +129,10 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { #if 0 /* Not yet implemented */ - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/ne64badge/src/m9s12_buttons.c b/configs/ne64badge/src/m9s12_buttons.c index 522d402c491..964b7114b5d 100644 --- a/configs/ne64badge/src/m9s12_buttons.c +++ b/configs/ne64badge/src/m9s12_buttons.c @@ -94,9 +94,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; if (hcs12_gpioread(NE64BADGE_BUTTON1)) { diff --git a/configs/nucleo-144/src/stm32_buttons.c b/configs/nucleo-144/src/stm32_buttons.c index ea520e84731..a8783b4e20c 100644 --- a/configs/nucleo-144/src/stm32_buttons.c +++ b/configs/nucleo-144/src/stm32_buttons.c @@ -77,7 +77,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return stm32_gpioread(GPIO_BTN_USER) ? 1 : 0; } @@ -92,7 +92,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/nucleo-f303re/src/stm32_buttons.c b/configs/nucleo-f303re/src/stm32_buttons.c index 65b046b819e..e40db64c282 100644 --- a/configs/nucleo-f303re/src/stm32_buttons.c +++ b/configs/nucleo-f303re/src/stm32_buttons.c @@ -83,12 +83,12 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit unsigned integer with each bit associated with a button. See the + * 32-bit unsigned integer with each bit associated with a button. See the * BUTTON_*_BIT definitions in board.h for the meaning of each bit. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { /* Check the state of the USER button. A LOW value means that the key is * pressed. diff --git a/configs/nucleo-f4x1re/src/stm32_appinit.c b/configs/nucleo-f4x1re/src/stm32_appinit.c index 5845ad169f3..a76eba4b59e 100644 --- a/configs/nucleo-f4x1re/src/stm32_appinit.c +++ b/configs/nucleo-f4x1re/src/stm32_appinit.c @@ -102,12 +102,6 @@ int board_app_initialize(uintptr_t arg) { int ret = OK; - /* Configure CPU load estimation */ - -#ifdef CONFIG_SCHED_INSTRUMENTATION - cpuload_initialize_once(); -#endif - #ifdef HAVE_MMCSD /* First, get an instance of the SDIO interface */ diff --git a/configs/nucleo-f4x1re/src/stm32_buttons.c b/configs/nucleo-f4x1re/src/stm32_buttons.c index ab019d2a5c3..fe18b0b2163 100644 --- a/configs/nucleo-f4x1re/src/stm32_buttons.c +++ b/configs/nucleo-f4x1re/src/stm32_buttons.c @@ -78,7 +78,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { /* Check that state of each USER button. A LOW value means that the key is * pressed. @@ -98,7 +98,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/nucleo-l476rg/src/stm32_appinit.c b/configs/nucleo-l476rg/src/stm32_appinit.c index ceaa3a76f52..f66fcdb1eca 100644 --- a/configs/nucleo-l476rg/src/stm32_appinit.c +++ b/configs/nucleo-l476rg/src/stm32_appinit.c @@ -120,12 +120,6 @@ int board_app_initialize(uintptr_t arg) (void)ret; -#ifdef CONFIG_SCHED_INSTRUMENTATION - /* Configure CPU load estimation */ - - cpuload_initialize_once(); -#endif - #ifdef HAVE_PROC /* Mount the proc filesystem */ diff --git a/configs/nucleo-l476rg/src/stm32_buttons.c b/configs/nucleo-l476rg/src/stm32_buttons.c index 7da458ffb3c..456795c304e 100644 --- a/configs/nucleo-l476rg/src/stm32_buttons.c +++ b/configs/nucleo-l476rg/src/stm32_buttons.c @@ -78,7 +78,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { /* Check that state of each USER button. A LOW value means that the key is * pressed. @@ -98,7 +98,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c b/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c index e2bcba1a58f..2863a332c18 100644 --- a/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c +++ b/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c @@ -120,14 +120,14 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret; + uint32_t ret; int i; /* Check each button */ diff --git a/configs/olimex-lpc1766stk/src/lpc17_buttons.c b/configs/olimex-lpc1766stk/src/lpc17_buttons.c index 37326a82773..179a6785841 100644 --- a/configs/olimex-lpc1766stk/src/lpc17_buttons.c +++ b/configs/olimex-lpc1766stk/src/lpc17_buttons.c @@ -130,9 +130,9 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/olimex-stm32-e407/src/stm32_buttons.c b/configs/olimex-stm32-e407/src/stm32_buttons.c index 870b1ff8a98..e52d296079b 100644 --- a/configs/olimex-stm32-e407/src/stm32_buttons.c +++ b/configs/olimex-stm32-e407/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key */ @@ -121,7 +121,7 @@ uint8_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON_*_BIT + * 32-bit bit set with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * * board_button_irq() may be called to register an interrupt handler that diff --git a/configs/olimex-stm32-h405/src/stm32_buttons.c b/configs/olimex-stm32-h405/src/stm32_buttons.c index c3b6aa92fee..abcac85c801 100644 --- a/configs/olimex-stm32-h405/src/stm32_buttons.c +++ b/configs/olimex-stm32-h405/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key */ @@ -120,7 +120,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/olimex-stm32-h407/src/stm32_buttons.c b/configs/olimex-stm32-h407/src/stm32_buttons.c index ed33810dd47..1155069e5ef 100644 --- a/configs/olimex-stm32-h407/src/stm32_buttons.c +++ b/configs/olimex-stm32-h407/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key */ @@ -121,7 +121,7 @@ uint8_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON_*_BIT + * 32-bit bit set with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * * board_button_irq() may be called to register an interrupt handler that diff --git a/configs/olimex-stm32-p207/src/stm32_buttons.c b/configs/olimex-stm32-p207/src/stm32_buttons.c index 0002098298f..bde278810b0 100644 --- a/configs/olimex-stm32-p207/src/stm32_buttons.c +++ b/configs/olimex-stm32-p207/src/stm32_buttons.c @@ -102,9 +102,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key */ @@ -156,7 +156,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/olimex-stm32-p407/src/stm32_buttons.c b/configs/olimex-stm32-p407/src/stm32_buttons.c index 6add698e0fa..a7bf89714df 100644 --- a/configs/olimex-stm32-p407/src/stm32_buttons.c +++ b/configs/olimex-stm32-p407/src/stm32_buttons.c @@ -104,9 +104,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key */ @@ -158,7 +158,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/olimex-strp711/src/str71_buttons.c b/configs/olimex-strp711/src/str71_buttons.c index 98537be3883..ec1b18b4d43 100644 --- a/configs/olimex-strp711/src/str71_buttons.c +++ b/configs/olimex-strp711/src/str71_buttons.c @@ -112,9 +112,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; if ((getreg16(STR71X_GPIO0_PD) & STR71X_WAKEUPBUTTON_GPIO0) != 0) { diff --git a/configs/olimexino-stm32/src/stm32_buttons.c b/configs/olimexino-stm32/src/stm32_buttons.c index 971bdb79f22..092383cadeb 100644 --- a/configs/olimexino-stm32/src/stm32_buttons.c +++ b/configs/olimexino-stm32/src/stm32_buttons.c @@ -63,7 +63,7 @@ * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. + * 32-bit bit set with each bit associated with a button. * See the BUTTON_*_BIT definitions in board.h for the meaning of each bit. * * board_button_irq() may be called to register an interrupt handler that @@ -97,12 +97,12 @@ void board_button_initialize(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. + * 32-bit bit set with each bit associated with a button. * See the BUTTON_*_BIT definitions in board.h for the meaning of each bit. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return stm32_gpioread(BUTTON_BOOT0n) ? 0 : BUTTON_BOOT0_MASK; } diff --git a/configs/open1788/src/lpc17_buttons.c b/configs/open1788/src/lpc17_buttons.c index e7a7cf88517..f2e2fb5f27a 100644 --- a/configs/open1788/src/lpc17_buttons.c +++ b/configs/open1788/src/lpc17_buttons.c @@ -149,9 +149,9 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/pcduino-a10/src/a1x_buttons.c b/configs/pcduino-a10/src/a1x_buttons.c index a690ae866dc..4d4feccc0f9 100644 --- a/configs/pcduino-a10/src/a1x_buttons.c +++ b/configs/pcduino-a10/src/a1x_buttons.c @@ -78,13 +78,13 @@ void board_button_initialize(void) * * Description: * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON* definitions * above for the meaning of each bit in the returned value. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { # warning Missing logic } diff --git a/configs/photon/include/board.h b/configs/photon/include/board.h index 8c2fc655e3f..96115ca57f0 100644 --- a/configs/photon/include/board.h +++ b/configs/photon/include/board.h @@ -152,11 +152,44 @@ #undef BOARD_ENABLE_USBOTG_HSULPI /* LED definitions ******************************************************************/ +/* LEDs + * + * A single LED is available driven by PA13. + */ + +/* LED index values for use with board_userled() */ #define BOARD_LED1 0 #define BOARD_NLEDS 1 + +/* LED bits for use with board_userled_all() */ + #define BOARD_LED1_BIT (1 << BOARD_LED1) +/* These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is + * defined. In that case, the usage by the board port is defined in + * include/board.h and src/sam_autoleds.c. The LEDs are used to encode + * OS-related events as follows: + * + * ------------------- ---------------------------- ------ + * SYMBOL Meaning LED + * ------------------- ---------------------------- ------ */ + +#define LED_STARTED 0 /* NuttX has been started OFF */ +#define LED_HEAPALLOCATE 0 /* Heap has been allocated OFF */ +#define LED_IRQSENABLED 0 /* Interrupts enabled OFF */ +#define LED_STACKCREATED 1 /* Idle stack created ON */ +#define LED_INIRQ 2 /* In an interrupt N/C */ +#define LED_SIGNAL 2 /* In a signal handler N/C */ +#define LED_ASSERTION 2 /* An assertion failed N/C */ +#define LED_PANIC 3 /* The system has crashed FLASH */ +#undef LED_IDLE /* MCU is is sleep mode Not used */ + +/* Thus if LED is statically on, NuttX has successfully booted and is, + * apparently, running normally. If LED is flashing at approximately + * 2Hz, then a fatal error has been detected and the system has halted. + */ + /* Button definitions ***************************************************************/ #define BOARD_BUTTON1 0 diff --git a/configs/photon/nsh/defconfig b/configs/photon/nsh/defconfig index f11b644af39..c82bde94e97 100644 --- a/configs/photon/nsh/defconfig +++ b/configs/photon/nsh/defconfig @@ -90,6 +90,7 @@ CONFIG_ARCH="arm" # CONFIG_ARCH_CHIP_LPC2378 is not set # CONFIG_ARCH_CHIP_LPC31XX is not set # CONFIG_ARCH_CHIP_LPC43XX is not set +# CONFIG_ARCH_CHIP_MOXART is not set # CONFIG_ARCH_CHIP_NUC1XX is not set # CONFIG_ARCH_CHIP_SAMA5 is not set # CONFIG_ARCH_CHIP_SAMD is not set @@ -101,7 +102,7 @@ CONFIG_ARCH_CHIP_STM32=y # CONFIG_ARCH_CHIP_STM32L4 is not set # CONFIG_ARCH_CHIP_STR71X is not set # CONFIG_ARCH_CHIP_TMS570 is not set -# CONFIG_ARCH_CHIP_MOXART is not set +# CONFIG_ARCH_CHIP_XMC4 is not set # CONFIG_ARCH_ARM7TDMI is not set # CONFIG_ARCH_ARM926EJS is not set # CONFIG_ARCH_ARM920T is not set @@ -371,9 +372,13 @@ CONFIG_STM32_HAVE_ADC3=y # CONFIG_STM32_HAVE_SDADC3_DMA is not set CONFIG_STM32_HAVE_CAN1=y CONFIG_STM32_HAVE_CAN2=y +# CONFIG_STM32_HAVE_COMP1 is not set # CONFIG_STM32_HAVE_COMP2 is not set +# CONFIG_STM32_HAVE_COMP3 is not set # CONFIG_STM32_HAVE_COMP4 is not set +# CONFIG_STM32_HAVE_COMP5 is not set # CONFIG_STM32_HAVE_COMP6 is not set +# CONFIG_STM32_HAVE_COMP7 is not set CONFIG_STM32_HAVE_DAC1=y CONFIG_STM32_HAVE_DAC2=y CONFIG_STM32_HAVE_RNG=y @@ -387,7 +392,10 @@ CONFIG_STM32_HAVE_SPI3=y # CONFIG_STM32_HAVE_SPI6 is not set # CONFIG_STM32_HAVE_SAIPLL is not set # CONFIG_STM32_HAVE_I2SPLL is not set -# CONFIG_STM32_HAVE_OPAMP is not set +# CONFIG_STM32_HAVE_OPAMP1 is not set +# CONFIG_STM32_HAVE_OPAMP2 is not set +# CONFIG_STM32_HAVE_OPAMP3 is not set +# CONFIG_STM32_HAVE_OPAMP4 is not set # CONFIG_STM32_ADC1 is not set # CONFIG_STM32_ADC2 is not set # CONFIG_STM32_ADC3 is not set @@ -401,6 +409,7 @@ CONFIG_STM32_HAVE_SPI3=y # CONFIG_STM32_I2C1 is not set # CONFIG_STM32_I2C2 is not set # CONFIG_STM32_I2C3 is not set +# CONFIG_STM32_OPAMP is not set # CONFIG_STM32_OTGFS is not set # CONFIG_STM32_OTGHS is not set # CONFIG_STM32_PWR is not set @@ -436,6 +445,7 @@ CONFIG_STM32_IWDG=y # # Alternate Pin Mapping # +# CONFIG_STM32_FLASH_WORKAROUND_DATA_CACHE_CORRUPTION_ON_RWW is not set # CONFIG_STM32_JTAG_DISABLE is not set # CONFIG_STM32_JTAG_FULL_ENABLE is not set # CONFIG_STM32_JTAG_NOJNTRST_ENABLE is not set @@ -569,6 +579,11 @@ CONFIG_ARCH_BOARD="photon" # # Common Board Options # +CONFIG_ARCH_HAVE_LEDS=y +# CONFIG_ARCH_LEDS is not set +CONFIG_ARCH_HAVE_BUTTONS=y +# CONFIG_ARCH_BUTTONS is not set +CONFIG_ARCH_HAVE_IRQBUTTONS=y # # Board-Specific Options @@ -638,6 +653,8 @@ CONFIG_SCHED_WAITPID=y # # CONFIG_PTHREAD_MUTEX_TYPES is not set CONFIG_PTHREAD_MUTEX_ROBUST=y +# CONFIG_PTHREAD_MUTEX_UNSAFE is not set +# CONFIG_PTHREAD_MUTEX_BOTH is not set CONFIG_NPTHREAD_KEYS=4 # CONFIG_PTHREAD_CLEANUP is not set # CONFIG_CANCELLATION_POINTS is not set @@ -755,6 +772,7 @@ CONFIG_WATCHDOG_DEVPATH="/dev/watchdog0" # # LED Support # +# CONFIG_USERLED is not set # CONFIG_RGBLED is not set # CONFIG_PCA9635PW is not set # CONFIG_NCP5623C is not set @@ -818,6 +836,7 @@ CONFIG_USART1_2STOP=0 # CONFIG_PSEUDOTERM is not set # CONFIG_USBDEV is not set # CONFIG_USBHOST is not set +# CONFIG_USBMISC is not set # CONFIG_HAVE_USBTRACE is not set # CONFIG_DRIVERS_WIRELESS is not set # CONFIG_DRIVERS_CONTACTLESS is not set @@ -1042,10 +1061,6 @@ CONFIG_HAVE_CXXINITIALIZE=y # Application Configuration # -# -# NxWidgets/NxWM -# - # # Built-In Applications # @@ -1058,6 +1073,7 @@ CONFIG_BUILTIN_PROXY_STACKSIZE=1024 # # Examples # +# CONFIG_EXAMPLES_BUTTONS is not set # CONFIG_EXAMPLES_CCTYPE is not set # CONFIG_EXAMPLES_CHAT is not set # CONFIG_EXAMPLES_CONFIGDATA is not set @@ -1072,6 +1088,7 @@ CONFIG_BUILTIN_PROXY_STACKSIZE=1024 # CONFIG_EXAMPLES_IGMP is not set # CONFIG_EXAMPLES_JSON is not set # CONFIG_EXAMPLES_KEYPADTEST is not set +# CONFIG_EXAMPLES_LEDS is not set # CONFIG_EXAMPLES_MEDIA is not set # CONFIG_EXAMPLES_MM is not set # CONFIG_EXAMPLES_MODBUS is not set @@ -1106,9 +1123,9 @@ CONFIG_EXAMPLES_NSH=y # CONFIG_EXAMPLES_TIFF is not set # CONFIG_EXAMPLES_TOUCHSCREEN is not set # CONFIG_EXAMPLES_USBSERIAL is not set -# CONFIG_EXAMPLES_USBTERM is not set # CONFIG_EXAMPLES_WATCHDOG is not set # CONFIG_EXAMPLES_WEBSERVER is not set +# CONFIG_EXAMPLES_XBC_TEST is not set # # File System Utilities @@ -1249,6 +1266,10 @@ CONFIG_NSH_ARCHINIT=y # CONFIG_NSH_LOGIN is not set # CONFIG_NSH_CONSOLE_LOGIN is not set +# +# NxWidgets/NxWM +# + # # Platform-specific Support # diff --git a/configs/photon/src/Makefile b/configs/photon/src/Makefile index 5d9501759c7..23f31b44899 100644 --- a/configs/photon/src/Makefile +++ b/configs/photon/src/Makefile @@ -35,18 +35,24 @@ -include $(TOPDIR)/Make.defs ASRCS = -CSRCS = stm32_boot.c +CSRCS = stm32_boot.c stm32_bringup.c ifeq ($(CONFIG_PHOTON_DFU_BOOTLOADER),y) CSRCS += dfu_signature.c endif +ifeq ($(CONFIG_LIB_BOARDCTL),y) +CSRCS += stm32_appinit.c +endif + ifeq ($(CONFIG_BUTTONS),y) CSRCS += stm32_buttons.c endif -ifeq ($(CONFIG_USERLED),y) -CSRCS += stm32_leds.c +ifeq ($(CONFIG_ARCH_LEDS),y) +CSRCS += stm32_autoleds.c +else +CSRCS += stm32_userleds.c endif ifeq ($(CONFIG_PHOTON_WDG),y) @@ -61,8 +67,4 @@ ifeq ($(CONFIG_STM32_OTGHS),y) CSRCS += stm32_usb.c endif -ifeq ($(CONFIG_NSH_LIBRARY),y) -CSRCS += stm32_appinit.c -endif - include $(TOPDIR)/configs/Board.mk diff --git a/configs/photon/src/photon.h b/configs/photon/src/photon.h index 4e0f312b6c4..5628d1b69c1 100644 --- a/configs/photon/src/photon.h +++ b/configs/photon/src/photon.h @@ -89,6 +89,21 @@ * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Called either by board_intialize() if CONFIG_BOARD_INITIALIZE or by + * board_app_initialize if CONFIG_LIB_BOARDCTL is selected. This function + * initializes and configures all on-board features appropriate for the + * selected configuration. + * + ****************************************************************************/ + +#if defined(CONFIG_LIB_BOARDCTL) || defined(CONFIG_BOARD_INITIALIZE) +int stm32_bringup(void); +#endif + /**************************************************************************** * Name: photon_watchdog_initialize() * diff --git a/configs/photon/src/stm32_appinit.c b/configs/photon/src/stm32_appinit.c index dc2899789fe..946dfbe8e2b 100644 --- a/configs/photon/src/stm32_appinit.c +++ b/configs/photon/src/stm32_appinit.c @@ -2,7 +2,7 @@ * config/photon/src/stm32_appinit.c * * Copyright (C) 2017 Gregory Nutt. All rights reserved. - * Author: Simon Piriou + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,23 +38,14 @@ ****************************************************************************/ #include -#include -#include -#include +#include + +#include #include "photon.h" -#include "stm32_wdg.h" -#include -#include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef OK -# define OK 0 -#endif +#ifdef CONFIG_LIB_BOARDCTL /**************************************************************************** * Public Functions @@ -87,65 +78,13 @@ int board_app_initialize(uintptr_t arg) { - int ret = OK; +#ifndef CONFIG_BOARD_INITIALIZE + /* Perform board initialization */ -#ifdef CONFIG_USERLED -#ifdef CONFIG_USERLED_LOWER - /* Register the LED driver */ - - ret = userled_lower_initialize("/dev/userleds"); - if (ret != OK) - { - syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret); - return ret; - } + return stm32_bringup(); #else - board_userled_initialize(); -#endif /* CONFIG_USERLED_LOWER */ -#endif /* CONFIG_USERLED */ - -#ifdef CONFIG_BUTTONS -#ifdef CONFIG_BUTTONS_LOWER - /* Register the BUTTON driver */ - - ret = btn_lower_initialize("/dev/buttons"); - if (ret != OK) - { - syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); - return ret; - } -#else - board_button_initialize(); -#endif /* CONFIG_BUTTONS_LOWER */ -#endif /* CONFIG_BUTTONS */ - -#ifdef CONFIG_STM32_IWDG - stm32_iwdginitialize("/dev/watchdog0", STM32_LSI_FREQUENCY); + return OK; #endif - -#ifdef CONFIG_PHOTON_WDG - - /* Start WDG kicker thread */ - - ret = photon_watchdog_initialize(); - if (ret != OK) - { - syslog(LOG_ERR, "Failed to start watchdog thread: %d\n", ret); - return ret; - } -#endif - -#ifdef CONFIG_PHOTON_WLAN - - /* Initialize wlan driver and hardware */ - - ret = photon_wlan_initialize(); - if (ret != OK) - { - syslog(LOG_ERR, "Failed to initialize wlan: %d\n", ret); - return ret; - } -#endif - - return ret; } + +#endif /* CONFIG_LIB_BOARDCTL */ diff --git a/configs/photon/src/stm32_autoleds.c b/configs/photon/src/stm32_autoleds.c new file mode 100644 index 00000000000..a490fa5432f --- /dev/null +++ b/configs/photon/src/stm32_autoleds.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * configs/photon/src/stm32_autoleds.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. + * + ****************************************************************************/ + +/* LEDs + * + * A single LED is available driven by PA13. + * + * These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is + * defined. In that case, the usage by the board port is defined in + * include/board.h and src/sam_autoleds.c. The LEDs are used to encode + * OS-related events as follows: + * + * ------------------- ----------------------- ------ + * SYMBOL Meaning LED + * ------------------- ----------------------- ------ + * LED_STARTED NuttX has been started OFF + * LED_HEAPALLOCATE Heap has been allocated OFF + * LED_IRQSENABLED Interrupts enabled OFF + * LED_STACKCREATED Idle stack created ON + * LED_INIRQ In an interrupt N/C + * LED_SIGNAL In a signal handler N/C + * LED_ASSERTION An assertion failed N/C + * LED_PANIC The system has crashed FLASH + * + * Thus is LED is statically on, NuttX has successfully booted and is, + * apparently, running normally. If LED is flashing at approximately + * 2Hz, then a fatal error has been detected and the system has halted. + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include +#include + +#include "stm32_gpio.h" +#include "photon.h" + +#ifdef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_autoled_initialize + ****************************************************************************/ + +void board_autoled_initialize(void) +{ + /* Configure Photon LED gpio as output */ + + stm32_configgpio(GPIO_LED1); +} + +/**************************************************************************** + * Name: board_autoled_on + ****************************************************************************/ + +void board_autoled_on(int led) +{ + if (led == 1 || led == 3) + { + stm32_gpiowrite(GPIO_LED1, true); + } +} + +/**************************************************************************** + * Name: board_autoled_off + ****************************************************************************/ + +void board_autoled_off(int led) +{ + if (led == 3) + { + stm32_gpiowrite(GPIO_LED1, false); + } +} + +#endif /* CONFIG_ARCH_LEDS */ diff --git a/configs/photon/src/stm32_boot.c b/configs/photon/src/stm32_boot.c index c9dfe28729a..5adc28f31c2 100644 --- a/configs/photon/src/stm32_boot.c +++ b/configs/photon/src/stm32_boot.c @@ -73,4 +73,32 @@ void stm32_boardinitialize(void) stm32_usbinitialize(); } #endif + +#ifdef CONFIG_ARCH_LEDS + /* Configure on-board LEDs if LED support has been selected. */ + + board_autoled_initialize(); +#endif } + +/**************************************************************************** + * Name: board_initialize + * + * Description: + * If CONFIG_BOARD_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_initialize(). board_initialize() will be + * called immediately after up_intitialize() is called and just before the + * initial application is started. This additional initialization phase + * may be used, for example, to initialize board-specific device drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_INITIALIZE +void board_initialize(void) +{ + /* Perform board initialization */ + + (void)stm32_bringup(); +} +#endif /* CONFIG_BOARD_INITIALIZE */ diff --git a/configs/photon/src/stm32_bringup.c b/configs/photon/src/stm32_bringup.c new file mode 100644 index 00000000000..d55f3bc2915 --- /dev/null +++ b/configs/photon/src/stm32_bringup.c @@ -0,0 +1,147 @@ +/**************************************************************************** + * config/photon/src/stm32_bringup.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Simon Piriou + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include + +#include + +#include "photon.h" +#include "stm32_wdg.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Called either by board_intialize() if CONFIG_BOARD_INITIALIZE or by + * board_app_initialize if CONFIG_LIB_BOARDCTL is selected. This function + * initializes and configures all on-board features appropriate for the + * selected configuration. + * + ****************************************************************************/ + +int stm32_bringup(void) +{ + int ret = OK; + +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = mount(NULL, "/proc", "procfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount procfs at /proc: %d\n", ret); + } +#endif + +#if defined(CONFIG_USERLED) && !defined(CONFIG_ARCH_LEDS) +#ifdef CONFIG_USERLED_LOWER + /* Register the LED driver */ + + ret = userled_lower_initialize("/dev/userleds"); + if (ret != OK) + { + syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret); + return ret; + } +#else + /* Enable USER LED support for some other purpose */ + + board_userled_initialize(); +#endif /* CONFIG_USERLED_LOWER */ +#endif /* CONFIG_USERLED && !CONFIG_ARCH_LEDS */ + +#ifdef CONFIG_BUTTONS +#ifdef CONFIG_BUTTONS_LOWER + /* Register the BUTTON driver */ + + ret = btn_lower_initialize("/dev/buttons"); + if (ret != OK) + { + syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); + return ret; + } +#else + /* Enable BUTTON support for some other purpose */ + + board_button_initialize(); +#endif /* CONFIG_BUTTONS_LOWER */ +#endif /* CONFIG_BUTTONS */ + +#ifdef CONFIG_STM32_IWDG + /* Initialize the watchdog timer */ + + stm32_iwdginitialize("/dev/watchdog0", STM32_LSI_FREQUENCY); +#endif + +#ifdef CONFIG_PHOTON_WDG + /* Start WDG kicker thread */ + + ret = photon_watchdog_initialize(); + if (ret != OK) + { + syslog(LOG_ERR, "Failed to start watchdog thread: %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_PHOTON_WLAN + /* Initialize wlan driver and hardware */ + + ret = photon_wlan_initialize(); + if (ret != OK) + { + syslog(LOG_ERR, "Failed to initialize wlan: %d\n", ret); + return ret; + } +#endif + + return ret; +} diff --git a/configs/photon/src/stm32_buttons.c b/configs/photon/src/stm32_buttons.c index 7c695dd5efa..7a9297eb6b3 100644 --- a/configs/photon/src/stm32_buttons.c +++ b/configs/photon/src/stm32_buttons.c @@ -66,7 +66,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { /* Check the state of the only button */ diff --git a/configs/photon/src/stm32_usb.c b/configs/photon/src/stm32_usb.c index 5dc24d5ed84..6f361a2c3fa 100644 --- a/configs/photon/src/stm32_usb.c +++ b/configs/photon/src/stm32_usb.c @@ -43,18 +43,6 @@ #include #include -/************************************************************************************ - * Pre-processor Definitions - ************************************************************************************/ - -/************************************************************************************ - * Private Data - ************************************************************************************/ - -/************************************************************************************ - * Private Functions - ************************************************************************************/ - /************************************************************************************ * Public Functions ************************************************************************************/ diff --git a/configs/photon/src/stm32_leds.c b/configs/photon/src/stm32_userleds.c similarity index 97% rename from configs/photon/src/stm32_leds.c rename to configs/photon/src/stm32_userleds.c index 076df40ad6c..8c7366f8a99 100644 --- a/configs/photon/src/stm32_leds.c +++ b/configs/photon/src/stm32_userleds.c @@ -1,5 +1,5 @@ /**************************************************************************** - * configs/photon/src/stm32_leds.c + * configs/photon/src/stm32_userleds.c * * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Author: Simon Piriou @@ -45,6 +45,8 @@ #include "stm32_gpio.h" +#ifndef CONFIG_ARCH_LEDS + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -80,3 +82,5 @@ void board_userled_all(uint8_t ledset) { stm32_gpiowrite(GPIO_LED1, !!(ledset & BOARD_LED1_BIT)); } + +#endif /* !CONFIG_ARCH_LEDS */ diff --git a/configs/photon/src/stm32_wdt.c b/configs/photon/src/stm32_wdt.c index 1df96707c6d..8ea352925c5 100644 --- a/configs/photon/src/stm32_wdt.c +++ b/configs/photon/src/stm32_wdt.c @@ -53,11 +53,6 @@ #include #include -/************************************************************************************ - * Pre-processor Definitions - ************************************************************************************/ -/* Configuration *******************************************************************/ - /************************************************************************************ * Public Functions ************************************************************************************/ diff --git a/configs/photon/src/stm32_wlan.c b/configs/photon/src/stm32_wlan.c index a0b19e4e0fb..068561d63a4 100644 --- a/configs/photon/src/stm32_wlan.c +++ b/configs/photon/src/stm32_wlan.c @@ -38,16 +38,19 @@ ****************************************************************************/ #include + #include -#include #include #include -#include "photon.h" + +#include #include "stm32_gpio.h" #include "stm32_sdio.h" +#include "photon.h" + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -105,25 +108,29 @@ int photon_wlan_initialize() struct sdio_dev_s *sdio_dev; /* Initialize sdio interface */ - _info("Initializing SDIO slot %d\n", SDIO_WLAN0_SLOTNO); + + wlinfo("Initializing SDIO slot %d\n", SDIO_WLAN0_SLOTNO); sdio_dev = sdio_initialize(SDIO_WLAN0_SLOTNO); if (!sdio_dev) { - _err("ERROR: Failed to initialize SDIO with slot %d\n", + wlerr("ERROR: Failed to initialize SDIO with slot %d\n", SDIO_WLAN0_SLOTNO); return ERROR; } /* Bind the SDIO interface to the bcmf driver */ + ret = bcmf_sdio_initialize(SDIO_WLAN0_MINOR, sdio_dev); if (ret != OK) { - _err("ERROR: Failed to bind SDIO to bcmf driver\n"); + wlerr("ERROR: Failed to bind SDIO to bcmf driver\n"); + /* FIXME deinitialize sdio device */ return ERROR; } + return OK; } diff --git a/configs/pic32mz-starterkit/src/pic32mz_buttons.c b/configs/pic32mz-starterkit/src/pic32mz_buttons.c index a51ca05f08d..639844a953b 100644 --- a/configs/pic32mz-starterkit/src/pic32mz_buttons.c +++ b/configs/pic32mz-starterkit/src/pic32mz_buttons.c @@ -105,9 +105,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ @@ -140,7 +140,7 @@ uint8_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the + * 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT definitions in board.h for the meaning of each bit. * * board_button_irq() may be called to register an interrupt handler that diff --git a/configs/sam3u-ek/src/sam_buttons.c b/configs/sam3u-ek/src/sam_buttons.c index 520f05e1a54..19a00d97ece 100644 --- a/configs/sam3u-ek/src/sam_buttons.c +++ b/configs/sam3u-ek/src/sam_buttons.c @@ -127,15 +127,15 @@ void board_button_initialize(void) * * Description: * After board_button_initialize() has been called, board_buttons() may be called to collect - * the state of all buttons. board_buttons() returns an 8-bit bit set with each bit + * the state of all buttons. board_buttons() returns an 32-bit bit set with each bit * associated with a button. See the BUTTON* definitions above for the meaning of * each bit in the returned value. * ************************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t retval; + uint32_t retval; retval = sam_gpioread(GPIO_BUTTON1) ? 0 : BUTTON1; retval |= sam_gpioread(GPIO_BUTTON2) ? 0 : BUTTON2; diff --git a/configs/sam4e-ek/src/sam_buttons.c b/configs/sam4e-ek/src/sam_buttons.c index d9fbabeb6d8..ed3690782a2 100644 --- a/configs/sam4e-ek/src/sam_buttons.c +++ b/configs/sam4e-ek/src/sam_buttons.c @@ -130,14 +130,14 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t retval; + uint32_t retval; retval = sam_gpioread(GPIO_SCROLLUP) ? 0 : BUTTON_SCROLLUP; retval |= sam_gpioread(GPIO_SCROLLDWN) ? 0 : BUTTON_SCROLLDOWN; diff --git a/configs/sam4l-xplained/src/sam_buttons.c b/configs/sam4l-xplained/src/sam_buttons.c index 619f7d658ba..78949a1cde0 100644 --- a/configs/sam4l-xplained/src/sam_buttons.c +++ b/configs/sam4l-xplained/src/sam_buttons.c @@ -53,10 +53,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -83,12 +79,12 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_gpioread(GPIO_SW0) ? 0 : BUTTON_SW0_BIT; } diff --git a/configs/sam4s-xplained-pro/src/sam_buttons.c b/configs/sam4s-xplained-pro/src/sam_buttons.c index daae49b89e6..f19f29894ea 100644 --- a/configs/sam4s-xplained-pro/src/sam_buttons.c +++ b/configs/sam4s-xplained-pro/src/sam_buttons.c @@ -81,12 +81,12 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_gpioread(GPIO_SW0) ? 0 : BUTTON_SW0_BIT; } diff --git a/configs/sam4s-xplained/src/sam_buttons.c b/configs/sam4s-xplained/src/sam_buttons.c index 940f97edae5..5b979a1aa95 100644 --- a/configs/sam4s-xplained/src/sam_buttons.c +++ b/configs/sam4s-xplained/src/sam_buttons.c @@ -80,12 +80,12 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_gpioread(GPIO_BP2) ? 0 : BUTTON_BP2_BIT; } diff --git a/configs/sama5d2-xult/src/sam_buttons.c b/configs/sama5d2-xult/src/sam_buttons.c index c93fa6b904e..56548f34804 100644 --- a/configs/sama5d2-xult/src/sam_buttons.c +++ b/configs/sama5d2-xult/src/sam_buttons.c @@ -91,12 +91,12 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_pioread(PIO_BTN_USER) ? 0 : BUTTON_USER_BIT; } diff --git a/configs/sama5d3-xplained/src/sam_buttons.c b/configs/sama5d3-xplained/src/sam_buttons.c index b7fd8245567..768b7b5db7c 100644 --- a/configs/sama5d3-xplained/src/sam_buttons.c +++ b/configs/sama5d3-xplained/src/sam_buttons.c @@ -95,12 +95,12 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_pioread(PIO_USER) ? 0 : BUTTON_USER_BIT; } diff --git a/configs/sama5d3x-ek/src/sam_buttons.c b/configs/sama5d3x-ek/src/sam_buttons.c index 5b7ccc9b908..e76fcd2a0ab 100644 --- a/configs/sama5d3x-ek/src/sam_buttons.c +++ b/configs/sama5d3x-ek/src/sam_buttons.c @@ -95,12 +95,12 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_pioread(PIO_USER1) ? 0 : BUTTON_USER1_BIT; } diff --git a/configs/sama5d4-ek/src/sam_buttons.c b/configs/sama5d4-ek/src/sam_buttons.c index 5696d96de5b..90dff73b160 100644 --- a/configs/sama5d4-ek/src/sam_buttons.c +++ b/configs/sama5d4-ek/src/sam_buttons.c @@ -91,12 +91,12 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_pioread(PIO_BTN_USER) ? 0 : BUTTON_USER_BIT; } diff --git a/configs/samd20-xplained/src/sam_buttons.c b/configs/samd20-xplained/src/sam_buttons.c index 88c24aced7a..334bf8b4038 100644 --- a/configs/samd20-xplained/src/sam_buttons.c +++ b/configs/samd20-xplained/src/sam_buttons.c @@ -79,13 +79,13 @@ void board_button_initialize(void) * * Description: * After board_button_initialize() has been called, board_buttons() may be called to collect - * the state of all buttons. board_buttons() returns an 8-bit bit set with each bit + * the state of all buttons. board_buttons() returns an 32-bit bit set with each bit * associated with a button. See the BUTTON* definitions above for the meaning of * each bit in the returned value. * ************************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_portread(PORT_SW0) ? 0 : BUTTON_SW0_BIT; } diff --git a/configs/samd21-xplained/src/sam_buttons.c b/configs/samd21-xplained/src/sam_buttons.c index aa19ddc008b..8e1789d1c9d 100644 --- a/configs/samd21-xplained/src/sam_buttons.c +++ b/configs/samd21-xplained/src/sam_buttons.c @@ -79,13 +79,13 @@ void board_button_initialize(void) * * Description: * After board_button_initialize() has been called, board_buttons() may be called to collect - * the state of all buttons. board_buttons() returns an 8-bit bit set with each bit + * the state of all buttons. board_buttons() returns an 32-bit bit set with each bit * associated with a button. See the BUTTON* definitions above for the meaning of * each bit in the returned value. * ************************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_portread(PORT_SW0) ? 0 : BUTTON_SW0_BIT; } diff --git a/configs/same70-xplained/src/sam_autoleds.c b/configs/same70-xplained/src/sam_autoleds.c index 64fd6b663c3..51e5272a19c 100644 --- a/configs/same70-xplained/src/sam_autoleds.c +++ b/configs/same70-xplained/src/sam_autoleds.c @@ -1,5 +1,5 @@ /**************************************************************************** - * configs/same70-xplained/include/sam_autoleds.c + * configs/same70-xplained/src/sam_autoleds.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/configs/same70-xplained/src/sam_buttons.c b/configs/same70-xplained/src/sam_buttons.c index 669a6d3bfe4..ab7dfeb8cfc 100644 --- a/configs/same70-xplained/src/sam_buttons.c +++ b/configs/same70-xplained/src/sam_buttons.c @@ -142,12 +142,12 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_gpioread(GPIO_SW0) ? 0 : BUTTON_SW0_BIT; } diff --git a/configs/saml21-xplained/src/sam_buttons.c b/configs/saml21-xplained/src/sam_buttons.c index 437c4d7ec85..407b24bb4d9 100644 --- a/configs/saml21-xplained/src/sam_buttons.c +++ b/configs/saml21-xplained/src/sam_buttons.c @@ -79,13 +79,13 @@ void board_button_initialize(void) * * Description: * After board_button_initialize() has been called, board_buttons() may be called to collect - * the state of all buttons. board_buttons() returns an 8-bit bit set with each bit + * the state of all buttons. board_buttons() returns an 32-bit bit set with each bit * associated with a button. See the BUTTON* definitions above for the meaning of * each bit in the returned value. * ************************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_portread(PORT_SW0) ? 0 : BUTTON_SW0_BIT; } diff --git a/configs/samv71-xult/src/sam_buttons.c b/configs/samv71-xult/src/sam_buttons.c index 7c9a98b52cd..adcd280d73f 100644 --- a/configs/samv71-xult/src/sam_buttons.c +++ b/configs/samv71-xult/src/sam_buttons.c @@ -158,14 +158,14 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t retval; + uint32_t retval; retval = sam_gpioread(GPIO_SW0) ? 0 : BUTTON_SW0_BIT; retval |= sam_gpioread(GPIO_SW1) ? 0 : BUTTON_SW1_BIT; diff --git a/configs/shenzhou/src/stm32_buttons.c b/configs/shenzhou/src/stm32_buttons.c index 515cad297f1..57053359b8f 100644 --- a/configs/shenzhou/src/stm32_buttons.c +++ b/configs/shenzhou/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ @@ -136,7 +136,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/sim/sixlowpan/defconfig b/configs/sim/sixlowpan/defconfig index ac4d9e35ded..0c6809ad43e 100644 --- a/configs/sim/sixlowpan/defconfig +++ b/configs/sim/sixlowpan/defconfig @@ -539,7 +539,7 @@ CONFIG_NET_6LOWPAN_MAXADDRCONTEXT=1 CONFIG_NET_6LOWPAN_MAXADDRCONTEXT_PREFIX_0_0=0xaa CONFIG_NET_6LOWPAN_MAXADDRCONTEXT_PREFIX_0_1=0xaa # CONFIG_NET_6LOWPAN_MAXADDRCONTEXT_PREINIT_1 is not set -CONFIG_NET_6LOWPAN_RIMEADDR_SIZE=2 +# CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED is not set CONFIG_NET_6LOWPAN_MAXAGE=20 CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS=4 CONFIG_NET_6LOWPAN_MAXPAYLOAD=102 diff --git a/configs/skp16c26/src/m16c_buttons.c b/configs/skp16c26/src/m16c_buttons.c index 4841fefe82c..78832b9c598 100644 --- a/configs/skp16c26/src/m16c_buttons.c +++ b/configs/skp16c26/src/m16c_buttons.c @@ -89,9 +89,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t swset = 0; + uint32_t swset = 0; uint8_t regval = getreg8(M16C_P8); if (SW_PRESSED(regval, SW1_BIT)) diff --git a/configs/spark/src/stm32_buttons.c b/configs/spark/src/stm32_buttons.c index e41463d6c9f..3534eeeb6ac 100644 --- a/configs/spark/src/stm32_buttons.c +++ b/configs/spark/src/stm32_buttons.c @@ -80,7 +80,7 @@ void board_button_initialize(void) * N.B The return state in true logic, the button polarity is dealt here in ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return stm32_gpioread(GPIO_BTN)==0 ? BUTTON_USER_BIT : 0; } @@ -95,7 +95,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm3210e-eval/src/stm32_buttons.c b/configs/stm3210e-eval/src/stm32_buttons.c index 043535444c8..f6a8575881f 100644 --- a/configs/stm3210e-eval/src/stm32_buttons.c +++ b/configs/stm3210e-eval/src/stm32_buttons.c @@ -108,9 +108,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ @@ -148,7 +148,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm3220g-eval/src/stm32_buttons.c b/configs/stm3220g-eval/src/stm32_buttons.c index 115fea249ea..9bec8f3c10b 100644 --- a/configs/stm3220g-eval/src/stm32_buttons.c +++ b/configs/stm3220g-eval/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ @@ -136,7 +136,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm3240g-eval/src/stm32_buttons.c b/configs/stm3240g-eval/src/stm32_buttons.c index a20c03f16ae..c543a0b6acb 100644 --- a/configs/stm3240g-eval/src/stm32_buttons.c +++ b/configs/stm3240g-eval/src/stm32_buttons.c @@ -104,9 +104,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ @@ -144,7 +144,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm32butterfly2/src/stm32_buttons.c b/configs/stm32butterfly2/src/stm32_buttons.c index 85e7a0751c4..612776adc59 100644 --- a/configs/stm32butterfly2/src/stm32_buttons.c +++ b/configs/stm32butterfly2/src/stm32_buttons.c @@ -92,9 +92,9 @@ void board_button_initialize(void) * Reads keys ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t rv = 0; + uint32_t rv = 0; int i; for (i = 0; i != NUM_BUTTONS; ++i) diff --git a/configs/stm32f103-minimum/src/stm32_buttons.c b/configs/stm32f103-minimum/src/stm32_buttons.c index ebca1469f1d..154f24225e8 100644 --- a/configs/stm32f103-minimum/src/stm32_buttons.c +++ b/configs/stm32f103-minimum/src/stm32_buttons.c @@ -104,9 +104,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ @@ -140,7 +140,7 @@ uint8_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns - * an 8-bit bit set with each bit associated with a button. See the + * an 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT definitions in board.h for the meaning of each bit. * * board_button_irq() may be called to register an interrupt handler that diff --git a/configs/stm32f3discovery/src/stm32_buttons.c b/configs/stm32f3discovery/src/stm32_buttons.c index f89fd207a3b..a17912bdbd6 100644 --- a/configs/stm32f3discovery/src/stm32_buttons.c +++ b/configs/stm32f3discovery/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ @@ -131,7 +131,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm32f411e-disco/Kconfig b/configs/stm32f411e-disco/Kconfig index c8983191836..4e51f7f5dd3 100644 --- a/configs/stm32f411e-disco/Kconfig +++ b/configs/stm32f411e-disco/Kconfig @@ -5,4 +5,14 @@ if ARCH_BOARD_STM32F411E_DISCO +config STM32F411DISCO_USBHOST_STACKSIZE + int "USB host waiter stack size" + default 1024 + depends on USBHOST + +config STM32F411DISCO_USBHOST_PRIO + int "USB host waiter task priority" + default 100 + depends on USBHOST + endif diff --git a/configs/stm32f411e-disco/src/Makefile b/configs/stm32f411e-disco/src/Makefile index 2ee3b640163..7cc95d6a5d9 100644 --- a/configs/stm32f411e-disco/src/Makefile +++ b/configs/stm32f411e-disco/src/Makefile @@ -1,7 +1,7 @@ ############################################################################ # configs/stm32f411e-disco/src/Makefile # -# Copyright (C) 2016 Gregory Nutt. All rights reserved. +# Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -36,10 +36,14 @@ -include $(TOPDIR)/Make.defs ASRCS = -CSRCS = stm32_boot.c +CSRCS = stm32_boot.c stm32_bringup.c ifeq ($(CONFIG_NSH_LIBRARY),y) CSRCS += stm32_appinit.c endif +ifeq ($(CONFIG_STM32_OTGFS),y) +CSRCS += stm32_usb.c +endif + include $(TOPDIR)/configs/Board.mk diff --git a/configs/stm32f411e-disco/src/stm32_appinit.c b/configs/stm32f411e-disco/src/stm32_appinit.c index 9228ec0366e..984a3d9ab48 100644 --- a/configs/stm32f411e-disco/src/stm32_appinit.c +++ b/configs/stm32f411e-disco/src/stm32_appinit.c @@ -84,11 +84,11 @@ int board_app_initialize(uintptr_t arg) { -#ifdef CONFIG_SCHED_INSTRUMENTATION - /* Configure CPU load estimation */ - - cpuload_initialize_once(); -#endif +#ifndef CONFIG_BOARD_INITIALIZE + /* Perform board-specific initialization */ + return stm32_bringup(); +#else return OK; +#endif } diff --git a/configs/stm32f411e-disco/src/stm32_boot.c b/configs/stm32f411e-disco/src/stm32_boot.c index dec40d4b70b..208f9b9a75d 100644 --- a/configs/stm32f411e-disco/src/stm32_boot.c +++ b/configs/stm32f411e-disco/src/stm32_boot.c @@ -72,18 +72,18 @@ void stm32_boardinitialize(void) board_autoled_initialize(); #endif -#if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || defined(CONFIG_STM32_SPI3) - /* Configure SPI chip selects if 1) SP2 is not disabled, and 2) the weak function - * stm32_spidev_initialize() has been brought into the link. +#if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || \ + defined(CONFIG_STM32_SPI3) + /* Configure SPI chip selects if 1) SP2 is not disabled, and 2) the + * weak function stm32_spidev_initialize() has been brought into the link. */ stm32_spidev_initialize(); #endif -#if defined(CONFIG_USBDEV) && defined(CONFIG_STM32_USB) - /* Initialize USB is 1) USBDEV is selected, 2) the USB controller is not - * disabled, and 3) the weak function stm32_usbinitialize() has been brought - * into the build. +#ifdef CONFIG_STM32_OTGFS + /* Initialize USB if the OTG FS controller is in the configuration. + * Presumably either CONFIG_USBDEV or CONFIG_USBHOST is also selected. */ stm32_usbinitialize(); @@ -106,14 +106,8 @@ void stm32_boardinitialize(void) #ifdef CONFIG_BOARD_INITIALIZE void board_initialize(void) { -#if defined(CONFIG_NSH_LIBRARY) && !defined(CONFIG_LIB_BOARDCTL) - /* Perform NSH initialization here instead of from the NSH. This - * alternative NSH initialization is necessary when NSH is ran in user-space - * but the initialization function must run in kernel space. - */ - - board_app_initialize(0); -#endif + /* Perform board-specific initialization */ + (void)stm32_bringup(); } #endif diff --git a/configs/stm32f411e-disco/src/stm32_bringup.c b/configs/stm32f411e-disco/src/stm32_bringup.c new file mode 100644 index 00000000000..22c0ef501d6 --- /dev/null +++ b/configs/stm32f411e-disco/src/stm32_bringup.c @@ -0,0 +1,100 @@ +/**************************************************************************** + * config/stm32f411e-disco/src/stm32_bringup.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 +#include + +#include "stm32.h" + +#ifdef CONFIG_STM32_OTGFS +# include "stm32_usbhost.h" +#endif + +#include "stm32f411e-disco.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_INITIALIZE=y : + * Called from board_initialize(). + * + * CONFIG_BOARD_INITIALIZE=n && CONFIG_LIB_BOARDCTL=y : + * Called from the NSH library + * + ****************************************************************************/ + +int stm32_bringup(void) +{ + int ret = OK; + +#if defined(CONFIG_STM32_OTGFS) && defined(CONFIG_USBHOST) + /* Initialize USB host operation. stm32_usbhost_initialize() starts a thread + * will monitor for USB connection and disconnection events. + */ + + ret = stm32_usbhost_initialize(); + if (ret != OK) + { + uerr("ERROR: Failed to initialize USB host: %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = mount(NULL, STM32_PROCFS_MOUNTPOINT, "procfs", 0, NULL); + if (ret < 0) + { + ferr("ERROR: Failed to mount procfs at %s: %d\n", + STM32_PROCFS_MOUNTPOINT, ret); + } +#endif + + return ret; +} diff --git a/configs/stm32f411e-disco/src/stm32_usb.c b/configs/stm32f411e-disco/src/stm32_usb.c new file mode 100644 index 00000000000..95cc3da81dc --- /dev/null +++ b/configs/stm32f411e-disco/src/stm32_usb.c @@ -0,0 +1,349 @@ +/************************************************************************************ + * configs/stm32f411e-disco/src/stm32_usb.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Copyright (C) 2017 Brian Webb. All rights reserved. + * Author: Brian Webb + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "up_arch.h" +#include "stm32.h" +#include "stm32_otgfs.h" +#include "stm32f411e-disco.h" + +#ifdef CONFIG_STM32_OTGFS + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +#if !defined(CONFIG_USBDEV) && !defined(CONFIG_USBHOST) +# warning "CONFIG_STM32_OTGFS is enabled but neither CONFIG_USBDEV nor CONFIG_USBHOST" +#endif + +#ifndef CONFIG_STM32F411DISCO_USBHOST_PRIO +# define CONFIG_STM32F411DISCO_USBHOST_PRIO 100 +#endif + +#ifndef CONFIG_STM32F411DISCO_USBHOST_STACKSIZE +# define CONFIG_STM32F411DISCO_USBHOST_STACKSIZE 1024 +#endif + +/************************************************************************************ + * Private Data + ************************************************************************************/ + +#ifdef CONFIG_USBHOST +static struct usbhost_connection_s *g_usbconn; +#endif + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: usbhost_waiter + * + * Description: + * Wait for USB devices to be connected. + * + ************************************************************************************/ + +#ifdef CONFIG_USBHOST +static int usbhost_waiter(int argc, char *argv[]) +{ + struct usbhost_hubport_s *hport; + + uinfo("Running\n"); + for (;;) + { + /* Wait for the device to change state */ + + DEBUGVERIFY(CONN_WAIT(g_usbconn, &hport)); + uinfo("%s\n", hport->connected ? "connected" : "disconnected"); + + /* Did we just become connected? */ + + if (hport->connected) + { + /* Yes.. enumerate the newly connected device */ + + (void)CONN_ENUMERATE(g_usbconn, hport); + } + } + + /* Keep the compiler from complaining */ + + return 0; +} +#endif + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: stm32_usbinitialize + * + * Description: + * Called from stm32_usbinitialize very early in inialization to setup USB-related + * GPIO pins for the STM32F411 Discovery board. + * + ************************************************************************************/ + +void stm32_usbinitialize(void) +{ + /* The OTG FS has an internal soft pull-up. No GPIO configuration is required */ + + /* Configure the OTG FS VBUS sensing GPIO, Power On, and Overcurrent GPIOs */ + +#ifdef CONFIG_STM32_OTGFS + stm32_configgpio(GPIO_OTGFS_VBUS); + stm32_configgpio(GPIO_OTGFS_PWRON); + stm32_configgpio(GPIO_OTGFS_OVER); +#endif +} + +/*********************************************************************************** + * Name: stm32_usbhost_initialize + * + * Description: + * Called at application startup time to initialize the USB host functionality. + * This function will start a thread that will monitor for device + * connection/disconnection events. + * + ***********************************************************************************/ + +#ifdef CONFIG_USBHOST +int stm32_usbhost_initialize(void) +{ + int pid; +#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ + defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) || \ + defined(CONFIG_USBHOST_XBOXCONTROLLER) + int ret; +#endif + + /* First, register all of the class drivers needed to support the drivers + * that we care about: + */ + + uinfo("Register class drivers\n"); + +#ifdef CONFIG_USBHOST_HUB + /* Initialize USB hub class support */ + + ret = usbhost_hub_initialize(); + if (ret < 0) + { + uerr("ERROR: usbhost_hub_initialize failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_USBHOST_MSC + /* Register the USB mass storage class class */ + + ret = usbhost_msc_initialize(); + if (ret != OK) + { + uerr("ERROR: Failed to register the mass storage class: %d\n", ret); + } +#endif + +#ifdef CONFIG_USBHOST_CDCACM + /* Register the CDC/ACM serial class */ + + ret = usbhost_cdcacm_initialize(); + if (ret != OK) + { + uerr("ERROR: Failed to register the CDC/ACM serial class: %d\n", ret); + } +#endif + +#ifdef CONFIG_USBHOST_HIDKBD + /* Initialize the HID keyboard class */ + + ret = usbhost_kbdinit(); + if (ret != OK) + { + uerr("ERROR: Failed to register the HID keyboard class\n"); + } +#endif + +#ifdef CONFIG_USBHOST_HIDMOUSE + /* Initialize the HID mouse class */ + + ret = usbhost_mouse_init(); + if (ret != OK) + { + uerr("ERROR: Failed to register the HID mouse class\n"); + } +#endif + +#ifdef CONFIG_USBHOST_XBOXCONTROLLER + /* Initialize the HID mouse class */ + + ret = usbhost_xboxcontroller_init(); + if (ret != OK) + { + uerr("ERROR: Failed to register the XBox Controller class\n"); + } +#endif + + /* Then get an instance of the USB host interface */ + + uinfo("Initialize USB host\n"); + g_usbconn = stm32_otgfshost_initialize(0); + if (g_usbconn) + { + /* Start a thread to handle device connection. */ + + uinfo("Start usbhost_waiter\n"); + + pid = task_create("usbhost", CONFIG_STM32F411DISCO_USBHOST_PRIO, + CONFIG_STM32F411DISCO_USBHOST_STACKSIZE, + (main_t)usbhost_waiter, (FAR char * const *)NULL); + return pid < 0 ? -ENOEXEC : OK; + } + + return -ENODEV; +} +#endif + +/*********************************************************************************** + * Name: stm32_usbhost_vbusdrive + * + * Description: + * Enable/disable driving of VBUS 5V output. This function must be provided be + * each platform that implements the STM32 OTG FS host interface + * + * "On-chip 5 V VBUS generation is not supported. For this reason, a charge pump + * or, if 5 V are available on the application board, a basic power switch, must + * be added externally to drive the 5 V VBUS line. The external charge pump can + * be driven by any GPIO output. When the application decides to power on VBUS + * using the chosen GPIO, it must also set the port power bit in the host port + * control and status register (PPWR bit in OTG_FS_HPRT). + * + * "The application uses this field to control power to this port, and the core + * clears this bit on an overcurrent condition." + * + * Input Parameters: + * iface - For future growth to handle multiple USB host interface. Should be zero. + * enable - true: enable VBUS power; false: disable VBUS power + * + * Returned Value: + * None + * + ***********************************************************************************/ + +#ifdef CONFIG_USBHOST +void stm32_usbhost_vbusdrive(int iface, bool enable) +{ + DEBUGASSERT(iface == 0); + + if (enable) + { + /* Enable the Power Switch by driving the enable pin low */ + + stm32_gpiowrite(GPIO_OTGFS_PWRON, false); + } + else + { + /* Disable the Power Switch by driving the enable pin high */ + + stm32_gpiowrite(GPIO_OTGFS_PWRON, true); + } +} +#endif + +/************************************************************************************ + * Name: stm32_setup_overcurrent + * + * Description: + * Setup to receive an interrupt-level callback if an overcurrent condition is + * detected. + * + * Input Parameter: + * handler - New overcurrent interrupt handler + * arg - The argument provided for the interrupt handler + * + * Returned value: + * Zero (OK) is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. + * + ************************************************************************************/ + +#ifdef CONFIG_USBHOST +int stm32_setup_overcurrent(xcpt_t handler, void *arg) +{ + return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, arg); +} +#endif + +/************************************************************************************ + * Name: stm32_usbsuspend + * + * Description: + * Board logic must provide the stm32_usbsuspend logic if the USBDEV driver is + * used. This function is called whenever the USB enters or leaves suspend mode. + * This is an opportunity for the board logic to shutdown clocks, power, etc. + * while the USB is suspended. + * + ************************************************************************************/ + +#ifdef CONFIG_USBDEV +void stm32_usbsuspend(FAR struct usbdev_s *dev, bool resume) +{ + uinfo("resume: %d\n", resume); +} +#endif + +#endif /* CONFIG_STM32_OTGFS */ diff --git a/configs/stm32f411e-disco/src/stm32f411e-disco.h b/configs/stm32f411e-disco/src/stm32f411e-disco.h index 5425f291bd3..1d78f4c6b36 100644 --- a/configs/stm32f411e-disco/src/stm32f411e-disco.h +++ b/configs/stm32f411e-disco/src/stm32f411e-disco.h @@ -1,4 +1,4 @@ -/************************************************************************************ +/**************************************************************************** * configs/stm32f411e-disco/src/stm32f411e-disco.h * * Copyright (C) 2016 Gregory Nutt. All rights reserved. @@ -32,28 +32,28 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************************/ + ****************************************************************************/ #ifndef __CONFIGS_STM32F411E_DISCO_SRC_STM32F411E_DISCO_H #define __CONFIGS_STM32F411E_DISCO_SRC_STM32F411E_DISCO_H -/************************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************************/ -/* Configuration ********************************************************************/ + ****************************************************************************/ +/* Configuration ************************************************************/ -/* LED. User LD2: the green LED is a user LED connected to Arduino signal D13 - * corresponding to MCU I/O PA5 (pin 21) or PB13 (pin 34) depending on the STM32 - * target. +/* LED. User LD2: the green LED is a user LED connected to Arduino signal + * D13 corresponding to MCU I/O PA5 (pin 21) or PB13 (pin 34) depending on + * the STM32 target. * * - When the I/O is HIGH value, the LED is on. * - When the I/O is LOW, the LED is off. @@ -85,9 +85,41 @@ #define GPIO_SPI1_SCK_OFF (GPIO_INPUT | GPIO_PULLDOWN | \ GPIO_PORTA | GPIO_PIN5) -/************************************************************************************ +/* USB OTG FS + * + * PA9 OTG_FS_VBUS VBUS sensing (also connected to the green LED) + * PC0 OTG_FS_PowerSwitchOn + * PD5 OTG_FS_Overcurrent + */ + +#define GPIO_OTGFS_VBUS (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|\ + GPIO_OPENDRAIN|GPIO_PORTA|GPIO_PIN9) +#define GPIO_OTGFS_PWRON (GPIO_OUTPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|\ + GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN0) + +#ifdef CONFIG_USBHOST +# define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_EXTI|GPIO_FLOAT|\ + GPIO_SPEED_100MHz|GPIO_PUSHPULL|\ + GPIO_PORTD|GPIO_PIN5) + +#else +# define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|\ + GPIO_PUSHPULL|GPIO_PORTD|GPIO_PIN5) +#endif + +/* procfs File System */ + +#ifdef CONFIG_FS_PROCFS +# ifdef CONFIG_NSH_PROC_MOUNTPOINT +# define STM32_PROCFS_MOUNTPOINT CONFIG_NSH_PROC_MOUNTPOINT +# else +# define STM32_PROCFS_MOUNTPOINT "/proc" +# endif +#endif + +/**************************************************************************** * Public Data - ************************************************************************************/ + ****************************************************************************/ /* Global driver instances */ @@ -98,28 +130,61 @@ extern struct spi_dev_s *g_spi1; extern struct spi_dev_s *g_spi2; #endif -/************************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************************/ + ****************************************************************************/ -/************************************************************************************ +/**************************************************************************** * Name: stm32_spidev_initialize * * Description: * Called to configure SPI chip select GPIO pins. * - ************************************************************************************/ + ****************************************************************************/ void stm32_spidev_initialize(void); -/************************************************************************************ +/**************************************************************************** * Name: stm32_usbinitialize * * Description: - * Called to setup USB-related GPIO pins. + * Called from stm32_boardinitialize very early in initialization to setup + * USB-related GPIO pins for the STM32F4Discovery board. * - ************************************************************************************/ + ****************************************************************************/ +#ifdef CONFIG_STM32_OTGFS void stm32_usbinitialize(void); +#endif + +/**************************************************************************** + * Name: stm32_usbhost_initialize + * + * Description: + * Called at application startup time to initialize the USB host + * functionality. This function will start a thread that will monitor for + * device connection/disconnection events. + * + ****************************************************************************/ + +#if defined(CONFIG_STM32_OTGFS) && defined(CONFIG_USBHOST) +int stm32_usbhost_initialize(void); +#endif + +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_INITIALIZE=y : + * Called from board_initialize(). + * + * CONFIG_BOARD_INITIALIZE=y && CONFIG_LIB_BOARDCTL=y : + * Called from the NSH library + * + ****************************************************************************/ + +int stm32_bringup(void); #endif /* __CONFIGS_STM32F411E_DISCO_SRC_STM32F411E_DISCO_H */ diff --git a/configs/stm32f429i-disco/src/stm32_buttons.c b/configs/stm32f429i-disco/src/stm32_buttons.c index a6ffed5433d..c5ce618d0c7 100644 --- a/configs/stm32f429i-disco/src/stm32_buttons.c +++ b/configs/stm32f429i-disco/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ @@ -131,7 +131,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm32f4discovery/src/stm32_buttons.c b/configs/stm32f4discovery/src/stm32_buttons.c index 449001f13ad..2b805075e00 100644 --- a/configs/stm32f4discovery/src/stm32_buttons.c +++ b/configs/stm32f4discovery/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ @@ -131,7 +131,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm32f746g-disco/src/stm32_buttons.c b/configs/stm32f746g-disco/src/stm32_buttons.c index ec08616aa6c..42faf1d90f3 100644 --- a/configs/stm32f746g-disco/src/stm32_buttons.c +++ b/configs/stm32f746g-disco/src/stm32_buttons.c @@ -77,7 +77,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return stm32_gpioread(GPIO_BTN_USER) ? 1 : 0; } @@ -92,7 +92,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm32l476-mdk/src/stm32_appinit.c b/configs/stm32l476-mdk/src/stm32_appinit.c index 99a42e0a4a4..2633d47302d 100644 --- a/configs/stm32l476-mdk/src/stm32_appinit.c +++ b/configs/stm32l476-mdk/src/stm32_appinit.c @@ -113,12 +113,6 @@ int board_app_initialize(uintptr_t arg) (void)ret; -#ifdef CONFIG_SCHED_INSTRUMENTATION - /* Configure CPU load estimation */ - - cpuload_initialize_once(); -#endif - #ifdef HAVE_PROC /* mount the proc filesystem */ diff --git a/configs/stm32l476-mdk/src/stm32_buttons.c b/configs/stm32l476-mdk/src/stm32_buttons.c index 955cba926d3..58e9079153d 100644 --- a/configs/stm32l476-mdk/src/stm32_buttons.c +++ b/configs/stm32l476-mdk/src/stm32_buttons.c @@ -103,9 +103,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ @@ -138,7 +138,7 @@ uint8_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the + * 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT definitions in board.h for the meaning of each bit. * * board_button_irq() may be called to register an interrupt handler that diff --git a/configs/stm32l476vg-disco/src/stm32_appinit.c b/configs/stm32l476vg-disco/src/stm32_appinit.c index 4cccfd50392..40b204e59ee 100644 --- a/configs/stm32l476vg-disco/src/stm32_appinit.c +++ b/configs/stm32l476vg-disco/src/stm32_appinit.c @@ -140,12 +140,6 @@ FAR struct mtd_dev_s *mtd_temp; int ret; (void)ret; - -#ifdef CONFIG_SCHED_INSTRUMENTATION - /* Configure CPU load estimation */ - - cpuload_initialize_once(); -#endif #ifdef HAVE_PROC /* mount the proc filesystem */ @@ -208,7 +202,7 @@ FAR struct mtd_dev_s *mtd_temp; return ret; } g_mtd_fs = mtd_temp; - + #ifdef CONFIG_MTD_PARTITION { FAR struct mtd_geometry_s geo; @@ -342,7 +336,7 @@ int board_ioctl(unsigned int cmd, uintptr_t arg) * 6 = CONFIG_N25QXXX_DUMMIES; * 0xeb = N25QXXX_FAST_READ_QUADIO; */ - + meminfo.flags = QSPIMEM_READ | QSPIMEM_QUADIO; meminfo.addrlen = 3; meminfo.dummies = 6; //CONFIG_N25QXXX_DUMMIES; @@ -350,17 +344,17 @@ int board_ioctl(unsigned int cmd, uintptr_t arg) meminfo.addr = 0; meminfo.buflen = 0; meminfo.buffer = NULL; - + stm32l4_qspi_enter_memorymapped(g_qspi, &meminfo, 80000000); } break; - + case BIOC_EXIT_MEMMAP: stm32l4_qspi_exit_memorymapped(g_qspi); break; - + #endif - + default: return -EINVAL; break; diff --git a/configs/stm32l476vg-disco/src/stm32_buttons.c b/configs/stm32l476vg-disco/src/stm32_buttons.c index 1d85b278756..18b984d2c1f 100644 --- a/configs/stm32l476vg-disco/src/stm32_buttons.c +++ b/configs/stm32l476vg-disco/src/stm32_buttons.c @@ -261,9 +261,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ @@ -306,7 +306,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm32ldiscovery/src/stm32_buttons.c b/configs/stm32ldiscovery/src/stm32_buttons.c index f599b0c8517..d985c9f4d3d 100644 --- a/configs/stm32ldiscovery/src/stm32_buttons.c +++ b/configs/stm32ldiscovery/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ @@ -131,7 +131,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm32vldiscovery/src/stm32_buttons.c b/configs/stm32vldiscovery/src/stm32_buttons.c index 259cfee756e..95d9f1590c5 100644 --- a/configs/stm32vldiscovery/src/stm32_buttons.c +++ b/configs/stm32vldiscovery/src/stm32_buttons.c @@ -75,9 +75,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; ret = (stm32_gpioread(g_buttons[i]) == false ? 1 : 0); @@ -94,7 +94,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/sure-pic32mx/src/pic32mx_buttons.c b/configs/sure-pic32mx/src/pic32mx_buttons.c index 6c378dd0a6f..e2ee0ac2195 100644 --- a/configs/sure-pic32mx/src/pic32mx_buttons.c +++ b/configs/sure-pic32mx/src/pic32mx_buttons.c @@ -157,9 +157,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int id; /* Configure input pins */ @@ -185,7 +185,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/tm4c123g-launchpad/src/tm4c_buttons.c b/configs/tm4c123g-launchpad/src/tm4c_buttons.c index a61c7e9c78d..24eb21ea04a 100644 --- a/configs/tm4c123g-launchpad/src/tm4c_buttons.c +++ b/configs/tm4c123g-launchpad/src/tm4c_buttons.c @@ -113,14 +113,14 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key. A LOW value means that the key is * pressed. diff --git a/configs/tm4c123g-launchpad/src/tm4c_ssi.c b/configs/tm4c123g-launchpad/src/tm4c_ssi.c index 7b295f76aa8..ce8ce7021c6 100644 --- a/configs/tm4c123g-launchpad/src/tm4c_ssi.c +++ b/configs/tm4c123g-launchpad/src/tm4c_ssi.c @@ -59,7 +59,7 @@ * Pre-processor Definitions ************************************************************************************/ -#ifdef CONFIG_DEBUG_SPI_INFO) +#ifdef CONFIG_DEBUG_SPI_INFO # define ssi_dumpgpio(m) tiva_dumpgpio(SDCCS_GPIO, m) #else # define ssi_dumpgpio(m) diff --git a/configs/tm4c1294-launchpad/src/tm4c_buttons.c b/configs/tm4c1294-launchpad/src/tm4c_buttons.c index 17d83c81f36..5b72e5bb29d 100644 --- a/configs/tm4c1294-launchpad/src/tm4c_buttons.c +++ b/configs/tm4c1294-launchpad/src/tm4c_buttons.c @@ -102,9 +102,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/twr-k60n512/src/k60_buttons.c b/configs/twr-k60n512/src/k60_buttons.c index a952f64828d..99bee759102 100644 --- a/configs/twr-k60n512/src/k60_buttons.c +++ b/configs/twr-k60n512/src/k60_buttons.c @@ -94,9 +94,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; if (kinetis_gpioread(GPIO_SW1)) { @@ -121,7 +121,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/ubw32/src/pic32_buttons.c b/configs/ubw32/src/pic32_buttons.c index f612e1eea4b..469167f1379 100644 --- a/configs/ubw32/src/pic32_buttons.c +++ b/configs/ubw32/src/pic32_buttons.c @@ -132,9 +132,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int id; /* Configure input pins */ @@ -160,7 +160,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT definitions in * board.h for the meaning of each bit. * diff --git a/configs/viewtool-stm32f107/src/stm32_buttons.c b/configs/viewtool-stm32f107/src/stm32_buttons.c index 9039e72e091..086a321755a 100644 --- a/configs/viewtool-stm32f107/src/stm32_buttons.c +++ b/configs/viewtool-stm32f107/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ @@ -132,7 +132,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/xmc4500-relax/src/xmc4_buttons.c b/configs/xmc4500-relax/src/xmc4_buttons.c index 24f9e05a206..881467f11c9 100644 --- a/configs/xmc4500-relax/src/xmc4_buttons.c +++ b/configs/xmc4500-relax/src/xmc4_buttons.c @@ -59,7 +59,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { #warning Missing logic return 0; diff --git a/configs/zkit-arm-1769/src/lpc17_buttons.c b/configs/zkit-arm-1769/src/lpc17_buttons.c index 6c984650323..e93f27734f7 100644 --- a/configs/zkit-arm-1769/src/lpc17_buttons.c +++ b/configs/zkit-arm-1769/src/lpc17_buttons.c @@ -109,9 +109,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; bool released; int i; @@ -142,7 +142,7 @@ uint8_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index d354ab8130b..94380212f67 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -136,6 +136,10 @@ struct skel_driver_s /* A single packet buffer per device is used here. There might be multiple * packet buffers in a more complex, pipelined design. + * + * NOTE that if CONFIG_skeleton_NINTERFACES were greater than 1, you would + * need a minimum on one packetbuffer per instance. Much better to be + * allocated dynamically. */ static uint8_t g_pktbuf[MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE]; @@ -186,13 +190,16 @@ static int skel_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); static void skel_ipv6multicast(FAR struct skel_driver_s *priv); #endif #endif +#ifdef CONFIG_NETDEV_IOCTL +static int skel_ioctl(FAR struct net_driver_s *dev, int cmd, long arg); +#endif /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** - * Function: skel_transmit + * Name: skel_transmit * * Description: * Start hardware transmission. Called either from the txdone interrupt @@ -233,7 +240,7 @@ static int skel_transmit(FAR struct skel_driver_s *priv) } /**************************************************************************** - * Function: skel_txpoll + * Name: skel_txpoll * * Description: * The transmitter is available, check if the network has any outgoing @@ -305,7 +312,7 @@ static int skel_txpoll(FAR struct net_driver_s *dev) } /**************************************************************************** - * Function: skel_receive + * Name: skel_receive * * Description: * An interrupt was received indicating the availability of a new RX packet @@ -447,7 +454,7 @@ static void skel_receive(FAR struct skel_driver_s *priv) } /**************************************************************************** - * Function: skel_txdone + * Name: skel_txdone * * Description: * An interrupt was received indicating that the last TX packet(s) is done @@ -487,7 +494,7 @@ static void skel_txdone(FAR struct skel_driver_s *priv) } /**************************************************************************** - * Function: skel_interrupt_work + * Name: skel_interrupt_work * * Description: * Perform interrupt related work from the worker thread @@ -539,7 +546,7 @@ static void skel_interrupt_work(FAR void *arg) } /**************************************************************************** - * Function: skel_interrupt + * Name: skel_interrupt * * Description: * Hardware interrupt handler @@ -557,7 +564,9 @@ static void skel_interrupt_work(FAR void *arg) static int skel_interrupt(int irq, FAR void *context, FAR void *arg) { - FAR struct skel_driver_s *priv = &g_skel[0]; + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; + + DEBUGASSERT(priv != NULL); /* Disable further Ethernet interrupts. Because Ethernet interrupts are * also disabled if the TX timeout event occurs, there can be no race @@ -584,7 +593,7 @@ static int skel_interrupt(int irq, FAR void *context, FAR void *arg) } /**************************************************************************** - * Function: skel_txtimeout_work + * Name: skel_txtimeout_work * * Description: * Perform TX timeout related work from the worker thread @@ -625,7 +634,7 @@ static void skel_txtimeout_work(FAR void *arg) } /**************************************************************************** - * Function: skel_txtimeout_expiry + * Name: skel_txtimeout_expiry * * Description: * Our TX watchdog timed out. Called from the timer interrupt handler. @@ -660,7 +669,7 @@ static void skel_txtimeout_expiry(int argc, wdparm_t arg, ...) } /**************************************************************************** - * Function: skel_poll_process + * Name: skel_poll_process * * Description: * Perform the periodic poll. This may be called either from watchdog @@ -681,7 +690,7 @@ static inline void skel_poll_process(FAR struct skel_driver_s *priv) } /**************************************************************************** - * Function: skel_poll_work + * Name: skel_poll_work * * Description: * Perform periodic polling from the worker thread @@ -730,7 +739,7 @@ static void skel_poll_work(FAR void *arg) } /**************************************************************************** - * Function: skel_poll_expiry + * Name: skel_poll_expiry * * Description: * Periodic timer handler. Called from the timer interrupt handler. @@ -757,7 +766,7 @@ static void skel_poll_expiry(int argc, wdparm_t arg, ...) } /**************************************************************************** - * Function: skel_ifup + * Name: skel_ifup * * Description: * NuttX Callback: Bring up the Ethernet interface when an IP address is @@ -812,7 +821,7 @@ static int skel_ifup(FAR struct net_driver_s *dev) } /**************************************************************************** - * Function: skel_ifdown + * Name: skel_ifdown * * Description: * NuttX Callback: Stop the interface. @@ -855,7 +864,7 @@ static int skel_ifdown(FAR struct net_driver_s *dev) } /**************************************************************************** - * Function: skel_txavail_work + * Name: skel_txavail_work * * Description: * Perform an out-of-cycle poll on the worker thread. @@ -898,7 +907,7 @@ static void skel_txavail_work(FAR void *arg) } /**************************************************************************** - * Function: skel_txavail + * Name: skel_txavail * * Description: * Driver callback invoked when new TX data is available. This is a @@ -936,7 +945,7 @@ static int skel_txavail(FAR struct net_driver_s *dev) } /**************************************************************************** - * Function: skel_addmac + * Name: skel_addmac * * Description: * NuttX Callback: Add the specified MAC address to the hardware multicast @@ -965,7 +974,7 @@ static int skel_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) #endif /**************************************************************************** - * Function: skel_rmmac + * Name: skel_rmmac * * Description: * NuttX Callback: Remove the specified MAC address from the hardware multicast @@ -994,7 +1003,7 @@ static int skel_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) #endif /**************************************************************************** - * Function: skel_ipv6multicast + * Name: skel_ipv6multicast * * Description: * Configure the IPv6 multicast MAC address. @@ -1067,12 +1076,51 @@ static void skel_ipv6multicast(FAR struct skel_driver_s *priv) } #endif /* CONFIG_NET_ICMPv6 */ +/**************************************************************************** + * Name: skel_ioctl + * + * Description: + * Handle network IOCTL commands directed to this device. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * cmd - The IOCTL command + * arg - The argument for the IOCTL command + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * + ****************************************************************************/ + +#ifdef CONFIG_NETDEV_IOCTL +static int skel_ioctl(FAR struct net_driver_s *dev, int cmd, long arg) +{ + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)dev->d_private; + int ret; + + /* Decode and dispatch the driver-specific IOCTL command */ + + switch (cmd) + { + /* Add cases here to support the IOCTL commands */ + + default: + nerr("ERROR: Unrecognized IOCTL command: %d\n", command); + return -ENOTTY; /* Special return value for this case */ + } + + return OK; +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Function: skel_initialize + * Name: skel_initialize * * Description: * Initialize the Ethernet controller and driver @@ -1101,7 +1149,7 @@ int skel_initialize(int intf) /* Attach the IRQ to the driver */ - if (irq_attach(CONFIG_skeleton_IRQ, skel_interrupt, NULL)) + if (irq_attach(CONFIG_skeleton_IRQ, skel_interrupt, priv)) { /* We could not attach the ISR to the interrupt */ @@ -1118,6 +1166,9 @@ int skel_initialize(int intf) #ifdef CONFIG_NET_IGMP priv->sk_dev.d_addmac = skel_addmac; /* Add multicast MAC address */ priv->sk_dev.d_rmmac = skel_rmmac; /* Remove multicast MAC address */ +#endif +#ifdef CONFIG_NETDEV_IOCTL + priv->sk_dev.d_ioctl = skel_ioctl; /* Handle network IOCTL commands */ #endif priv->sk_dev.d_private = (FAR void *)g_skel; /* Used to recover private state from dev */ diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 47630871627..968a9e21221 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1159,7 +1159,12 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg) int intf; FAR struct ifreq *ifr = (FAR struct ifreq *)arg; +#ifdef CONFIG_NET_MULTILINK + if (!ifr || ((ifr->ifr_flags & IFF_MASK) != IFF_TUN && + (ifr->ifr_flags & IFF_MASK) != IFF_TAP)) +#else if (!ifr || (ifr->ifr_flags & IFF_MASK) != IFF_TUN) +#endif { return -EINVAL; } @@ -1191,6 +1196,25 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg) priv = filep->f_priv; strncpy(ifr->ifr_name, priv->dev.d_ifname, IFNAMSIZ); +#ifdef CONFIG_NET_MULTILINK + if ((ifr->ifr_flags & IFF_MASK) == IFF_TAP) + { + /* TAP device -> handling raw Ethernet packets + * -> set appropriate Ethernet header length + */ + + priv->dev.d_llhdrlen = ETH_HDRLEN; + } + else if ((ifr->ifr_flags & IFF_MASK) == IFF_TUN) + { + /* TUN device -> handling an application data stream + * -> no header + */ + + priv->dev.d_llhdrlen = 0; + } +#endif + tundev_unlock(tun); return OK; diff --git a/include/nuttx/board.h b/include/nuttx/board.h index 0525499021f..c00d09ce3c2 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -581,7 +581,7 @@ void board_button_initialize(void); * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. A bit set to + * 32-bit bit set with each bit associated with a button. A bit set to * "1" means that the button is depressed; a bit set to "0" means that * the button is released. The correspondence of the each button bit * and physical buttons is board-specific. @@ -593,7 +593,7 @@ void board_button_initialize(void); ****************************************************************************/ #ifdef CONFIG_ARCH_BUTTONS -uint8_t board_buttons(void); +uint32_t board_buttons(void); #endif /**************************************************************************** diff --git a/include/nuttx/input/buttons.h b/include/nuttx/input/buttons.h index 3012ba98577..13ba28c3aae 100644 --- a/include/nuttx/input/buttons.h +++ b/include/nuttx/input/buttons.h @@ -96,7 +96,7 @@ * from the button driver. */ -typedef uint8_t btn_buttonset_t; +typedef uint32_t btn_buttonset_t; /* A reference to this structure is provided with the BTNIOC_POLLEVENTS IOCTL * command and describes the conditions under which the client would like diff --git a/include/nuttx/net/arp.h b/include/nuttx/net/arp.h index 4a33994a1b7..477240a5d68 100644 --- a/include/nuttx/net/arp.h +++ b/include/nuttx/net/arp.h @@ -69,6 +69,7 @@ */ #define ARPHRD_ETHER 1 /* Ethernet */ +#define ARPHRD_IEEE80211    801 /* IEEE 802.11 */ #define ARPHRD_IEEE802154 804 /* IEEE 802.15.4 */ /**************************************************************************** diff --git a/include/nuttx/net/netconfig.h b/include/nuttx/net/netconfig.h index 9bbd0e9929c..99f00e38563 100644 --- a/include/nuttx/net/netconfig.h +++ b/include/nuttx/net/netconfig.h @@ -295,16 +295,13 @@ #endif /* The UDP maximum packet size. This is should not be to set to more - * than NET_DEV_MTU(d) - NET_LL_HDRLEN(dev) - IPv*_HDRLEN. - * - * REVISIT: It is unclear to me if the UDP_HDRLEN should subtracted - * or not. + * than NET_DEV_MTU(d) - NET_LL_HDRLEN(dev) - UDP_HDRLEN - IPv*_HDRLEN. */ -#define UDP_MSS(d,h) (NET_DEV_MTU(d) - NET_LL_HDRLEN(d) (h)) +#define UDP_MSS(d,h) (NET_DEV_MTU(d) - NET_LL_HDRLEN(d) - UDP_HDRLEN (h)) #ifdef CONFIG_NET_ETHERNET -# define ETH_UDP_MSS(h) (CONFIG_NET_ETH_MTU - ETH_HDRLEN - (h)) +# define ETH_UDP_MSS(h) (CONFIG_NET_ETH_MTU - ETH_HDRLEN - UDP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_UDP_MSS(h) ETH_UDP_MSS(h) # define __MAX_UDP_MSS(h) ETH_UDP_MSS(h) @@ -312,7 +309,7 @@ #endif #ifdef CONFIG_NET_6LOWPAN -# define IEEE802154_UDP_MSS(h) (CONFIG_NET_6LOWPAN_MAXPAYLOAD - (h)) +# define IEEE802154_UDP_MSS(h) (CONFIG_NET_6LOWPAN_MAXPAYLOAD - UDP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_UDP_MSS(h) IEEE802154_UDP_MSS(h) # define __MAX_UDP_MSS(h) IEEE802154_UDP_MSS(h) @@ -320,7 +317,7 @@ #endif #ifdef CONFIG_NET_LOOPBACK -# define LO_UDP_MSS(h) (NET_LO_MTU - (h)) +# define LO_UDP_MSS(h) (NET_LO_MTU - UDP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_UDP_MSS(h) LO_UDP_MSS(h) # define __MAX_UDP_MSS(h) LO_UDP_MSS(h) @@ -328,7 +325,7 @@ #endif #ifdef CONFIG_NET_SLIP -# define SLIP_UDP_MSS(h) (CONFIG_NET_SLIP_MTU - (h)) +# define SLIP_UDP_MSS(h) (CONFIG_NET_SLIP_MTU - UDP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_UDP_MSS(h) SLIP_UDP_MSS(h) # define __MAX_UDP_MSS(h) SLIP_UDP_MSS(h) @@ -383,27 +380,25 @@ # endif #endif -/* NOTE: MSS calcuation excludes the UDP_HDRLEN. */ - #ifdef CONFIG_NET_IPv4 -# define UDP_IPv4_MSS(d) UDP_MSS(d,IPv4_HDRLEN) -# define ETH_IPv4_UDP_MSS ETH_UDP_MSS(IPv4_HDRLEN) -# define SLIP_IPv4_UDP_MSS SLIP_UDP_MSS(IPv4_HDRLEN) +# define UDP_IPv4_MSS(d) UDP_MSS(d,IPv4_HDRLEN) +# define ETH_IPv4_UDP_MSS ETH_UDP_MSS(IPv4_HDRLEN) +# define SLIP_IPv4_UDP_MSS SLIP_UDP_MSS(IPv4_HDRLEN) -# define MIN_IPv4_UDP_MSS __MIN_UDP_MSS(IPv4_HDRLEN) -# define MIN_UDP_MSS __MIN_UDP_MSS(IPv4_HDRLEN) +# define MIN_IPv4_UDP_MSS __MIN_UDP_MSS(IPv4_HDRLEN) +# define MIN_UDP_MSS __MIN_UDP_MSS(IPv4_HDRLEN) # undef MAX_UDP_MSS -# define MAX_IPv4_UDP_MSS __MAX_UDP_MSS(IPv4_HDRLEN) -# define MAX_UDP_MSS __MAX_UDP_MSS(IPv4_HDRLEN) +# define MAX_IPv4_UDP_MSS __MAX_UDP_MSS(IPv4_HDRLEN) +# define MAX_UDP_MSS __MAX_UDP_MSS(IPv4_HDRLEN) #endif /* If IPv6 is support, it will have the smaller MSS */ #ifdef CONFIG_NET_IPv6 # undef MIN_UDP_MSS -# define MIN_IPv6_UDP_MSS __MIN_UDP_MSS(IPv6_HDRLEN) -# define MIN_UDP_MSS __MIN_UDP_MSS(IPv6_HDRLEN) +# define MIN_IPv6_UDP_MSS __MIN_UDP_MSS(IPv6_HDRLEN) +# define MIN_UDP_MSS __MIN_UDP_MSS(IPv6_HDRLEN) #endif /* TCP configuration options */ @@ -473,17 +468,15 @@ * may support a different UDP MSS value. Here we arbitrarily select * the minimum MSS for that case. * - * REVISIT: It is unclear to me if the TCP_HDRLEN should subtracted - * or not. + * REVISIT: TCP_HDRLEN is not really a constant! */ -#define TCP_MSS(d,h) (NET_DEV_MTU(d) - NET_LL_HDRLEN(d) - (h)) -#define LO_TCP_MSS(h) (NET_LO_MTU - (h)) +#define TCP_MSS(d,h) (NET_DEV_MTU(d) - NET_LL_HDRLEN(d) - TCP_HDRLEN - (h)) /* Get the smallest and largest MSS */ #ifdef CONFIG_NET_ETHERNET -# define ETH_TCP_MSS(h) (CONFIG_NET_ETH_MTU - ETH_HDRLEN - (h)) +# define ETH_TCP_MSS(h) (CONFIG_NET_ETH_MTU - ETH_HDRLEN - TCP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_TCP_MSS(h) ETH_TCP_MSS(h) # define __MAX_TCP_MSS(h) ETH_TCP_MSS(h) @@ -491,7 +484,7 @@ #endif #ifdef CONFIG_NET_6LOWPAN -# define IEEE802154_TCP_MSS(h) CONFIG_NET_6LOWPAN_MAXPAYLOAD +# define IEEE802154_TCP_MSS(h) (CONFIG_NET_6LOWPAN_MAXPAYLOAD - TCP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_TCP_MSS(h) IEEE802154_TCP_MSS(h) # define __MAX_TCP_MSS(h) IEEE802154_TCP_MSS(h) @@ -499,7 +492,7 @@ #endif #ifdef CONFIG_NET_LOOPBACK -# define LO_TCP_MSS(h) (NET_LO_MTU - (h)) +# define LO_TCP_MSS(h) (NET_LO_MTU - TCP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_TCP_MSS(h) LO_TCP_MSS(h) # define __MAX_TCP_MSS(h) LO_TCP_MSS(h) @@ -507,7 +500,7 @@ #endif #ifdef CONFIG_NET_SLIP -# define SLIP_TCP_MSS(h) (CONFIG_NET_SLIP_MTU - (h)) +# define SLIP_TCP_MSS(h) (CONFIG_NET_SLIP_MTU - TCP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_TCP_MSS(h) SLIP_TCP_MSS(h) # define __MAX_TCP_MSS(h) SLIP_TCP_MSS(h) @@ -568,26 +561,26 @@ */ #ifdef CONFIG_NET_IPv6 -# define TCP_IPv6_MSS(d) TCP_MSS(d,IPv6_HDRLEN) -# define ETH_IPv6_TCP_MSS ETH_TCP_MSS(IPv6_HDRLEN) -# define SLIP_IPv6_TCP_MSS SLIP_TCP_MSS(IPv6_HDRLEN) -# define MAX_TCP_MSS __MAX_TCP_MSS(IPv6_HDRLEN) +# define TCP_IPv6_MSS(d) TCP_MSS(d,IPv6_HDRLEN) +# define ETH_IPv6_TCP_MSS ETH_TCP_MSS(IPv6_HDRLEN) +# define SLIP_IPv6_TCP_MSS SLIP_TCP_MSS(IPv6_HDRLEN) +# define MAX_TCP_MSS __MAX_TCP_MSS(IPv6_HDRLEN) #endif #ifdef CONFIG_NET_IPv4 -# define TCP_IPv4_MSS(d) TCP_MSS(d,IPv4_HDRLEN) -# define ETH_IPv4_TCP_MSS ETH_TCP_MSS(IPv4_HDRLEN) -# define SLIP_IPv4_TCP_MSS SLIP_TCP_MSS(IPv4_HDRLEN) -# define MIN_TCP_MSS __MIN_TCP_MSS(IPv4_HDRLEN) +# define TCP_IPv4_MSS(d) TCP_MSS(d,IPv4_HDRLEN) +# define ETH_IPv4_TCP_MSS ETH_TCP_MSS(IPv4_HDRLEN) +# define SLIP_IPv4_TCP_MSS SLIP_TCP_MSS(IPv4_HDRLEN) +# define MIN_TCP_MSS __MIN_TCP_MSS(IPv4_HDRLEN) # undef MAX_TCP_MSS -# define MAX_TCP_MSS __MAX_TCP_MSS(IPv4_HDRLEN) +# define MAX_TCP_MSS __MAX_TCP_MSS(IPv4_HDRLEN) #endif /* If IPv6 is supported, it will have the smaller MSS */ #ifdef CONFIG_NET_IPv6 # undef MIN_TCP_MSS -# define MIN_TCP_MSS __MIN_TCP_MSS(IPv6_HDRLEN) +# define MIN_TCP_MSS __MIN_TCP_MSS(IPv6_HDRLEN) #endif /* The size of the advertised receiver's window. @@ -614,22 +607,28 @@ #endif #if defined(CONFIG_NET_MULTILINK) - /* We are supporting multiple network devices using different link layer - * protocols. Get the size of the receive window from the device structure. - */ + /* We are supporting multiple network devices using different link layer + * protocols. Get the size of the receive window from the device + * structure. + */ # define NET_DEV_RCVWNDO(d) ((d)->d_recvwndo) -#elif defined(CONFIG_NET_SLIP) - /* Only SLIP.. use the configured SLIP receive window size */ - -# define NET_DEV_RCVWNDO(d) CONFIG_NET_SLIP_TCP_RECVWNDO - #elif defined(CONFIG_NET_ETHERNET) /* Only Ethernet.. use the configured SLIP receive window size */ # define NET_DEV_RCVWNDO(d) CONFIG_NET_ETH_TCP_RECVWNDO +#elif defined(CONFIG_NET_6LOWPAN) + /* Only 6loWPAN.. use the configured 6loWPAN receive window size */ + +# define NET_DEV_RCVWNDO(d) CONFIG_NET_6LOWPAN_TCP_RECVWNDO + +#elif defined(CONFIG_NET_SLIP) + /* Only SLIP.. use the configured SLIP receive window size */ + +# define NET_DEV_RCVWNDO(d) CONFIG_NET_SLIP_TCP_RECVWNDO + #else /* if defined(CONFIG_NET_LOOPBACK) */ /* Only loal loopback.. use the fixed loopback receive window size */ diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index 0211d17ce6f..e2f3eaf1f7d 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -63,6 +63,94 @@ * Pre-processor Definitions ****************************************************************************/ +/* By default, a 2-byte Rime address is used for the IEEE802.15.4 MAC + * device's link layer address. If CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED + * is selected, then an 8-byte Rime address will be used. + */ + +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED +# define NET_6LOWPAN_RIMEADDR_SIZE 8 +#else +# define NET_6LOWPAN_RIMEADDR_SIZE 2 +#endif + +/* Frame format definitions *************************************************/ +/* Fragment header. + * + * The fragment header is used when the payload is too large to fit in a + * single IEEE 802.15.4 frame. The fragment header contains three fields: + * Datagram size, datagram tag and datagram offset. + * + * 1. Datagram size describes the total (un-fragmented) payload. + * 2. Datagram tag identifies the set of fragments and is used to match + * fragments of the same payload. + * 3. Datagram offset identifies the fragment’s offset within the un- + * fragmented payload. + * + * The fragment header length is 4 bytes for the first header and 5 + * bytes for all subsequent headers. + */ + +#define RIME_FRAG_DISPATCH_SIZE 0 /* 16 bit */ +#define RIME_FRAG_TAG 2 /* 16 bit */ +#define RIME_FRAG_OFFSET 4 /* 8 bit */ + +/* Define the Rime buffer as a byte array */ + +#define RIME_HC1_DISPATCH 0 /* 8 bit */ +#define RIME_HC1_ENCODING 1 /* 8 bit */ +#define RIME_HC1_TTL 2 /* 8 bit */ + +#define RIME_HC1_HC_UDP_DISPATCH 0 /* 8 bit */ +#define RIME_HC1_HC_UDP_HC1_ENCODING 1 /* 8 bit */ +#define RIME_HC1_HC_UDP_UDP_ENCODING 2 /* 8 bit */ +#define RIME_HC1_HC_UDP_TTL 3 /* 8 bit */ +#define RIME_HC1_HC_UDP_PORTS 4 /* 8 bit */ +#define RIME_HC1_HC_UDP_CHKSUM 5 /* 16 bit */ + +/* These are some definitions of element values used in the FCF. See the + * IEEE802.15.4 spec for details. + */ + +#define FRAME802154_FRAMETYPE_SHIFT (0) /* Bits 0-2: Frame type */ +#define FRAME802154_FRAMETYPE_MASK (7 << FRAME802154_FRAMETYPE_SHIFT) +#define FRAME802154_SECENABLED_SHIFT (3) /* Bit 3: Security enabled */ +#define FRAME802154_FRAMEPENDING_SHIFT (4) /* Bit 4: Frame pending */ +#define FRAME802154_ACKREQUEST_SHIFT (5) /* Bit 5: ACK request */ +#define FRAME802154_PANIDCOMP_SHIFT (6) /* Bit 6: PANID compression */ + /* Bits 7-9: Reserved */ +#define FRAME802154_DSTADDR_SHIFT (2) /* Bits 10-11: Dest address mode */ +#define FRAME802154_DSTADDR_MASK (3 << FRAME802154_DSTADDR_SHIFT) +#define FRAME802154_VERSION_SHIFT (4) /* Bit 12-13: Frame version */ +#define FRAME802154_VERSION_MASK (3 << FRAME802154_VERSION_SHIFT) +#define FRAME802154_SRCADDR_SHIFT (6) /* Bits 14-15: Source address mode */ +#define FRAME802154_SRCADDR_MASK (3 << FRAME802154_SRCADDR_SHIFT) + +/* Unshifted values for use in struct frame802154_fcf_s */ + +#define FRAME802154_BEACONFRAME (0) +#define FRAME802154_DATAFRAME (1) +#define FRAME802154_ACKFRAME (2) +#define FRAME802154_CMDFRAME (3) + +#define FRAME802154_BEACONREQ (7) + +#define FRAME802154_IEEERESERVED (0) +#define FRAME802154_NOADDR (0) /* Only valid for ACK or Beacon frames */ +#define FRAME802154_SHORTADDRMODE (2) +#define FRAME802154_LONGADDRMODE (3) + +#define FRAME802154_NOBEACONS 0x0f + +#define FRAME802154_BROADCASTADDR 0xffff +#define FRAME802154_BROADCASTPANDID 0xffff + +#define FRAME802154_IEEE802154_2003 (0) +#define FRAME802154_IEEE802154_2006 (1) + +#define FRAME802154_SECURITY_LEVEL_NONE (0) +#define FRAME802154_SECURITY_LEVEL_128 (3) + /* Min and Max compressible UDP ports - HC06 */ #define SIXLOWPAN_UDP_4_BIT_PORT_MIN 0xf0b0 @@ -80,7 +168,7 @@ #define SIXLOWPAN_DISPATCH_FRAG1 0xc0 /* 11000xxx */ #define SIXLOWPAN_DISPATCH_FRAGN 0xe0 /* 11100xxx */ -#define SIXLOWPAN_DISPATCH_FRAG_MASK 0xf1 /* 11111000 */ +#define SIXLOWPAN_DISPATCH_FRAG_MASK 0xf8 /* 11111000 */ /* HC1 encoding */ @@ -171,9 +259,71 @@ #define SIXLOWPAN_MAC_STDFRAME 127 -/* Frame buffer helper macros. +/* Address compressibility test macros **************************************/ + +/* Check whether we can compress the IID in address 'a' to 16 bits. This is + * used for unicast addresses only, and is true if the address is on the + * format ::0000:00ff:fe00:XXXX * - * The IEEE802.15.4 MAC driver structures includes a list of IOB + * NOTE: we currently assume 64-bits prefixes + */ + +/* Check whether we can compress the IID in address 'a' to 16 bits. This is + * used for unicast addresses only, and is true if the address is on the + * format ::0000:00ff:fe00:XXXX. + * + * NOTE: we currently assume 64-bits prefixes. Big-endian, network order is + * assumed. + */ + +#define SIXLOWPAN_IS_IID_16BIT_COMPRESSABLE(a) \ + ((((a)[4]) == 0x0000) && (((a)[5]) == HTONS(0x00ff)) && \ + (((a)[6]) == 0xfe00)) + +/* Check whether the 9-bit group-id of the compressed multicast address is + * known. It is true if the 9-bit group is the all nodes or all routers + * group. Parameter 'a' is typed uint8_t * + */ + +#define SIXLOWPAN_IS_MCASTADDR_DECOMPRESSABLE(a) \ + (((*a & 0x01) == 0) && \ + ((*(a + 1) == 0x01) || (*(a + 1) == 0x02))) + +/* Check whether the 112-bit group-id of the multicast address is mappable + * to a 9-bit group-id. It is true if the group is the all nodes or all + * routers group: + * + * XXXX:0000:0000:0000:0000:0000:0000:0001 All nodes address + * XXXX:0000:0000:0000:0000:0000:0000:0002 All routers address + */ + +#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE(a) \ + ((a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ + (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && \ + ((a)[7] == HTONS(0x0001) || (a)[7] == HTONS(0x0002))) + +/* FFXX:0000:0000:0000:0000:00XX:XXXX:XXXX */ + +#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE48(a) \ + ((a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ + (a)[4] == 0 && (((a)[5] & HTONS(0xff00)) == 0)) + +/* FFXX:0000:0000:0000:0000:0000:00XX:XXXX */ + +#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE32(a) \ + ((a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ + (a)[4] == 0 && (a)[5] == 0 && ((a)[6] & HTONS(0xff00)) == 0) + +/* FF02:0000:0000:0000:0000:0000:0000:00XX */ + +#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE8(a) \ + ((((a)[0] & HTONS(0x00ff)) == HTONS(0x0002)) && \ + (a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ + (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && \ + (((a)[7] & HTONS(0xff00)) == 0x0000)) + +/* Frame buffer helper macros ***********************************************/ +/* The IEEE802.15.4 MAC driver structures includes a list of IOB * structures, i_framelist, containing frames to be sent by the driver or * that were received by the driver. The IOB structure is defined in * include/nuttx/net/iob.h. The length of data in the IOB is provided by @@ -235,7 +385,7 @@ struct rimeaddr_s { - uint8_t u8[CONFIG_NET_6LOWPAN_RIMEADDR_SIZE]; + uint8_t u8[NET_6LOWPAN_RIMEADDR_SIZE]; }; /* The device structure for IEEE802.15.4 MAC network device differs from the @@ -376,27 +526,43 @@ struct ieee802154_driver_s /* i_dgramtag. Datagram tag to be put in the header of the set of * fragments. It is used by the recipient to match fragments of the * same payload. + * + * This is the sender's copy of the tag. It is incremented after each + * fragmented packet is sent so that it will be unique to that + * sequence fragmentation. Its value is then persistent, the values of + * other fragmentatin variables are valid on during a single + * fragmentation sequence (while i_accumlen > 0) */ uint16_t i_dgramtag; + /* i_reasstag. Each frame in the reassembly has a tag. That tag must + * match the reassembly tag in the fragments being merged. + * + * This is the same tag as i_dgramtag but is saved on the receiving + * side to match all of the fragments of the packet. + */ + + uint16_t i_reasstag; + /* i_pktlen. The total length of the IPv6 packet to be re-assembled in - * d_buf. + * d_buf. Used to determine when the re-assembly is complete. */ uint16_t i_pktlen; /* The current accumulated length of the packet being received in d_buf. - * Included IPv6 and protocol headers. + * Included IPv6 and protocol headers. Currently used only to determine + * there is a fragmentation sequence in progress. */ uint16_t i_accumlen; - /* i_reasstag. Each frame in the reassembly has a tag. That tag must - * match the reassembly tag in the fragments being merged. + /* i_boffset. Offset to the beginning of data in d_buf. As each fragment + * is received, data is placed at an appriate offset added to this. */ - uint16_t i_reasstag; + uint16_t i_boffset; /* The source MAC address of the fragments being merged */ diff --git a/include/nuttx/wireless/wireless.h b/include/nuttx/wireless/wireless.h index 6ab0b0b3d11..bd9f93ba8f7 100644 --- a/include/nuttx/wireless/wireless.h +++ b/include/nuttx/wireless/wireless.h @@ -203,6 +203,37 @@ #define IW_ESSID_MAX_SIZE 32 +/* Modes of operation */ + +#define IW_MODE_AUTO 0 /* Let the driver decides */ +#define IW_MODE_ADHOC 1 /* Single cell network */ +#define IW_MODE_INFRA 2 /* Multi cell network, roaming, ... */ +#define IW_MODE_MASTER 3 /* Synchronisation master or Access Point */ +#define IW_MODE_REPEAT 4 /* Wireless Repeater (forwarder) */ +#define IW_MODE_SECOND 5 /* Secondary master/repeater (backup) */ +#define IW_MODE_MONITOR 6 /* Passive monitor (listen only) */ +#define IW_MODE_MESH 7 /* Mesh (IEEE 802.11s) network */ +#define IW_MODE_NFLAGS 8 + +/* Frequency flags */ + +#define IW_FREQ_AUTO 0 /* Let the driver decides */ +#define IW_FREQ_FIXED 1 /* Force a specific value */ +#define IW_FREQ_NFLAGS 2 + +#define IW_MAX_FREQUENCIES 32 /* Max. frequencies in struct iw_range */ + +/* Transmit Power flags available */ + +#define IW_TXPOW_DBM 0 /* Value is in dBm */ +#define IW_TXPOW_MWATT 1 /* Value is in mW */ +#define IW_TXPOW_RELATIVE 2 /* Value is in arbitrary units */ +#define IW_TXPOW_NFLAGS 3 + +/* Scan-related */ + +#define IW_SCAN_MAX_DATA 4096 /* Maximum size of returned data */ + /************************************************************************************ * Public Types ************************************************************************************/ @@ -296,15 +327,32 @@ union iwreq_data struct iw_param param; /* Other small parameters */ struct iw_point data; /* Other large parameters */ }; - + /* This is the structure used to exchange data in wireless IOCTLs. This structure * is the same as 'struct ifreq', but defined for use with wireless IOCTLs. */ struct iwreq { - char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "eth0" */ - union iwreq_data u; /* Data payload */ + char ifr_name[IFNAMSIZ]; /* Interface name, e.g. "eth0" */ + union iwreq_data u; /* Data payload */ +}; + +/* Range of parameters (currently only frequencies) */ + +struct iw_range +{ + uint8_t num_frequency; /* Number of frequencies in the freq[] list */ + struct iw_freq freq[IW_MAX_FREQUENCIES]; +}; + +/* A Wireless Event. */ + +struct iw_event +{ + uint16_t len; /* Real length of ata */ + uint16_t cmd; /* Wireless IOCTL command*/ + union iwreq_data u; /* Fixed IOCTL payload */ }; #endif /* CONFIG_DRIVERS_WIRELESS */ diff --git a/include/pthread.h b/include/pthread.h index af6ef51e23e..e70ad06e5be 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -337,6 +337,23 @@ typedef struct pthread_barrier_s pthread_barrier_t; typedef bool pthread_once_t; #define __PTHREAD_ONCE_T_DEFINED 1 +struct pthread_rwlock_s +{ + pthread_mutex_t lock; + pthread_cond_t cv; + unsigned int num_readers; + unsigned int num_writers; + bool write_in_progress; +}; + +typedef struct pthread_rwlock_s pthread_rwlock_t; + +typedef int pthread_rwlockattr_t; + +#define PTHREAD_RWLOCK_INITIALIZER {PTHREAD_MUTEX_INITIALIZER, \ + PTHREAD_COND_INITIALIZER, \ + 0, 0, false} + #ifdef CONFIG_PTHREAD_CLEANUP /* This type describes the pthread cleanup callback (non-standard) */ @@ -539,8 +556,8 @@ int pthread_barrierattr_setpshared(FAR pthread_barrierattr_t *attr, int pthread_barrier_destroy(FAR pthread_barrier_t *barrier); int pthread_barrier_init(FAR pthread_barrier_t *barrier, - FAR const pthread_barrierattr_t *attr, - unsigned int count); + FAR const pthread_barrierattr_t *attr, + unsigned int count); int pthread_barrier_wait(FAR pthread_barrier_t *barrier); /* Pthread initialization */ @@ -548,6 +565,21 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier); int pthread_once(FAR pthread_once_t *once_control, CODE void (*init_routine)(void)); +/* Pthread rwlock */ + +int pthread_rwlock_destroy(FAR pthread_rwlock_t *rw_lock); +int pthread_rwlock_init(FAR pthread_rwlock_t *rw_lock, + FAR const pthread_rwlockattr_t *attr); +int pthread_rwlock_rdlock(pthread_rwlock_t *lock); +int pthread_rwlock_timedrdlock(FAR pthread_rwlock_t *lock, + FAR const struct timespec *abstime); +int pthread_rwlock_tryrdlock(FAR pthread_rwlock_t *lock); +int pthread_rwlock_wrlock(FAR pthread_rwlock_t *lock); +int pthread_rwlock_timedwrlock(FAR pthread_rwlock_t *lock, + FAR const struct timespec *abstime); +int pthread_rwlock_trywrlock(FAR pthread_rwlock_t *lock); +int pthread_rwlock_unlock(FAR pthread_rwlock_t *lock); + /* Pthread signal management APIs */ int pthread_kill(pthread_t thread, int sig); diff --git a/libc/netdb/lib_dnsquery.c b/libc/netdb/lib_dnsquery.c index 21ed201ba80..3602a5c8dd5 100644 --- a/libc/netdb/lib_dnsquery.c +++ b/libc/netdb/lib_dnsquery.c @@ -494,7 +494,7 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr, nerr("ERROR: IPv4 dns_recv_response failed: %d\n", ret); - if (ret != -EADDRNOTAVAIL) + if (ret == -EADDRNOTAVAIL) { /* The IPv4 address is not available. Return zero to * continue the tranversal with the next nameserver @@ -575,7 +575,7 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr, nerr("ERROR: IPv6 dns_recv_response failed: %d\n", ret); - if (ret != -EADDRNOTAVAIL) + if (ret == -EADDRNOTAVAIL) { /* The IPv6 address is not available. Return zero to * continue the tranversal with the next nameserver diff --git a/libc/pthread/Make.defs b/libc/pthread/Make.defs index b8be2927d2f..291dfdfd4e6 100644 --- a/libc/pthread/Make.defs +++ b/libc/pthread/Make.defs @@ -52,6 +52,7 @@ CSRCS += pthread_mutexattr_settype.c pthread_mutexattr_gettype.c CSRCS += pthread_mutexattr_setrobust.c pthread_mutexattr_getrobust.c CSRCS += pthread_setcancelstate.c pthread_setcanceltype.c CSRCS += pthread_testcancel.c +CSRCS += pthread_rwlock.c pthread_rwlock_rdlock.c pthread_rwlock_wrlock.c ifeq ($(CONFIG_SMP),y) CSRCS += pthread_attr_getaffinity.c pthread_attr_setaffinity.c diff --git a/libc/pthread/pthread_rwlock.c b/libc/pthread/pthread_rwlock.c new file mode 100644 index 00000000000..b40b655b26d --- /dev/null +++ b/libc/pthread/pthread_rwlock.c @@ -0,0 +1,128 @@ +/**************************************************************************** + * libc/pthread/pthread_rwlock.c + * + * Copyright (C) 2017 Mark Schulte. All rights reserved. + * Author: Mark Schulte + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int pthread_rwlock_init(FAR pthread_rwlock_t *lock, + FAR const pthread_rwlockattr_t *attr) +{ + int err; + + if (attr != NULL) + { + return -ENOSYS; + } + + lock->num_readers = 0; + lock->num_writers = 0; + lock->write_in_progress = false; + + err = pthread_cond_init(&lock->cv, NULL); + if (err != 0) + { + return err; + } + + err = pthread_mutex_init(&lock->lock, NULL); + if (err != 0) + { + pthread_cond_destroy(&lock->cv); + return err; + } + + return err; +} + +int pthread_rwlock_destroy(FAR pthread_rwlock_t *lock) +{ + int cond_err = pthread_cond_destroy(&lock->cv); + int mutex_err = pthread_mutex_destroy(&lock->lock); + + if (mutex_err) + { + return mutex_err; + } + + return cond_err; +} + +int pthread_rwlock_unlock(FAR pthread_rwlock_t *rw_lock) +{ + int err; + + err = pthread_mutex_lock(&rw_lock->lock); + if (err != 0) + { + return err; + } + + if (rw_lock->num_readers > 0) + { + rw_lock->num_readers--; + + if (rw_lock->num_readers == 0) + { + err = pthread_cond_broadcast(&rw_lock->cv); + } + } + else if (rw_lock->write_in_progress) + { + rw_lock->write_in_progress = false; + + err = pthread_cond_broadcast(&rw_lock->cv); + } + else + { + err = EINVAL; + } + + pthread_mutex_unlock(&rw_lock->lock); + return err; +} diff --git a/libc/pthread/pthread_rwlock_rdlock.c b/libc/pthread/pthread_rwlock_rdlock.c new file mode 100644 index 00000000000..4eadfedccb5 --- /dev/null +++ b/libc/pthread/pthread_rwlock_rdlock.c @@ -0,0 +1,158 @@ +/**************************************************************************** + * libc/pthread/pthread_rwlock_rdlock.c + * + * Copyright (C) 2017 Mark Schulte. All rights reserved. + * Author: Mark Schulte + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#ifdef CONFIG_PTHREAD_CLEANUP +static void rdlock_cleanup(FAR void *arg) +{ + FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg; + + (void)pthread_mutex_unlock(&rw_lock->lock); +} +#endif + +static int tryrdlock(FAR pthread_rwlock_t *rw_lock) +{ + int err; + + if (rw_lock->num_writers > 0 || rw_lock->write_in_progress) + { + err = EBUSY; + } + else if (rw_lock->num_readers == UINT_MAX) + { + err = EAGAIN; + } + else + { + rw_lock->num_readers++; + err = OK; + } + + return err; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pthread_rwlock_rdlock + * + * Description: + * Locks a read/write lock for reading + * + * Parameters: + * None + * + * Return Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_rwlock_tryrdlock(FAR pthread_rwlock_t *rw_lock) +{ + int err = pthread_mutex_trylock(&rw_lock->lock); + + if (err != 0) + { + return err; + } + + err = tryrdlock(rw_lock); + + pthread_mutex_unlock(&rw_lock->lock); + return err; +} + +int pthread_rwlock_timedrdlock(FAR pthread_rwlock_t *rw_lock, + FAR const struct timespec *ts) +{ + int err = pthread_mutex_lock(&rw_lock->lock); + + if (err != 0) + { + return err; + } + +#ifdef CONFIG_PTHREAD_CLEANUP + pthread_cleanup_push(&rdlock_cleanup, rw_lock); +#endif + while ((err = tryrdlock(rw_lock)) == EBUSY) + { + if (ts != NULL) + { + err = pthread_cond_timedwait(&rw_lock->cv, &rw_lock->lock, ts); + } + else + { + err = pthread_cond_wait(&rw_lock->cv, &rw_lock->lock); + } + + if (err != 0) + { + break; + } + } +#ifdef CONFIG_PTHREAD_CLEANUP + pthread_cleanup_pop(0); +#endif + + pthread_mutex_unlock(&rw_lock->lock); + return err; +} + +int pthread_rwlock_rdlock(FAR pthread_rwlock_t * rw_lock) +{ + return pthread_rwlock_timedrdlock(rw_lock, NULL); +} diff --git a/libc/pthread/pthread_rwlock_wrlock.c b/libc/pthread/pthread_rwlock_wrlock.c new file mode 100644 index 00000000000..c9f4f3a7c56 --- /dev/null +++ b/libc/pthread/pthread_rwlock_wrlock.c @@ -0,0 +1,167 @@ +/**************************************************************************** + * libc/pthread/pthread_rwlock_wrlock.c + * + * Copyright (C) 2017 Mark Schulte. All rights reserved. + * Author: Mark Schulte + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#ifdef CONFIG_PTHREAD_CLEANUP +static void wrlock_cleanup(FAR void *arg) +{ + FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg; + + rw_lock->num_writers--; + (void)pthread_mutex_unlock(&rw_lock->lock); +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pthread_rwlock_wrlock + * + * Description: + * Locks a read/write lock for writing + * + * Parameters: + * None + * + * Return Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_rwlock_trywrlock(FAR pthread_rwlock_t *rw_lock) +{ + int err = pthread_mutex_trylock(&rw_lock->lock); + + if (err != 0) + { + return err; + } + + if (rw_lock->num_readers > 0 || rw_lock->write_in_progress) + { + err = EBUSY; + } + else + { + rw_lock->write_in_progress = true; + } + + pthread_mutex_unlock(&rw_lock->lock); + return err; +} + +int pthread_rwlock_timedwrlock(FAR pthread_rwlock_t *rw_lock, + FAR const struct timespec *ts) +{ + int err = pthread_mutex_lock(&rw_lock->lock); + + if (err != 0) + { + return err; + } + + if (rw_lock->num_writers == UINT_MAX) + { + err = EAGAIN; + goto exit_with_mutex; + } + + rw_lock->num_writers++; + +#ifdef CONFIG_PTHREAD_CLEANUP + pthread_cleanup_push(&wrlock_cleanup, rw_lock); +#endif + while (rw_lock->write_in_progress || rw_lock->num_readers > 0) + { + if (ts != NULL) + { + err = pthread_cond_timedwait(&rw_lock->cv, &rw_lock->lock, ts); + } + else + { + err = pthread_cond_wait(&rw_lock->cv, &rw_lock->lock); + } + + if (err != 0) + { + break; + } + } +#ifdef CONFIG_PTHREAD_CLEANUP + pthread_cleanup_pop(0); +#endif + + if (err == 0) + { + rw_lock->write_in_progress = true; + } + else + { + /* In case of error, notify any blocked readers. */ + + (void) pthread_cond_broadcast(&rw_lock->cv); + } + + rw_lock->num_writers--; + +exit_with_mutex: + pthread_mutex_unlock(&rw_lock->lock); + return err; +} + +int pthread_rwlock_wrlock(FAR pthread_rwlock_t *rw_lock) +{ + return pthread_rwlock_timedwrlock(rw_lock, NULL); +} diff --git a/libxx/Makefile b/libxx/Makefile index 766bd5d62d3..9f5ba9c9ac7 100644 --- a/libxx/Makefile +++ b/libxx/Makefile @@ -50,13 +50,19 @@ endif ifeq (,$(findstring y,$(CONFIG_UCLIBCXX) $(CONFIG_LIBCXX))) CXXSRCS += libxx_delete.cxx libxx_deletea.cxx libxx_new.cxx libxx_newa.cxx -CXXSRCS += libxx_stdthrow.cxx libxx_cxa_guard.cxx +CXXSRCS += libxx_stdthrow.cxx else ifeq (,$(findstring y,$(CONFIG_UCLIBCXX_EXCEPTION) $(CONFIG_LIBCXX_EXCEPTION))) CXXSRCS += libxx_stdthrow.cxx endif endif +# uClibc++ doesn't need this file + +ifneq ($(CONFIG_UCLIBCXX),y) +CXXSRCS += libxx_cxa_guard.cxx +endif + # Paths DEPPATH = --dep-path . diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 413a5d10fc8..1a845774fcd 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -739,7 +739,7 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd, req->ifr_hwaddr.sa_family = AF_INETX; memcpy(req->ifr_hwaddr.sa_data, ieee->i_nodeaddr.u8, - CONFIG_NET_6LOWPAN_RIMEADDR_SIZE); + NET_6LOWPAN_RIMEADDR_SIZE); ret = OK; } else @@ -782,7 +782,7 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd, req->ifr_hwaddr.sa_family = AF_INETX; memcpy(ieee->i_nodeaddr.u8, req->ifr_hwaddr.sa_data, - CONFIG_NET_6LOWPAN_RIMEADDR_SIZE); + NET_6LOWPAN_RIMEADDR_SIZE); ret = OK; } else diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index 737d51195ba..01a61b5b8ec 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -251,7 +251,8 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) #ifdef CONFIG_NET_TUN case NET_LL_TUN: /* Virtual Network Device (TUN) */ - dev->d_llhdrlen = 0; + dev->d_llhdrlen = 0; /* This will be overwritten by tun_ioctl + * if used as a TAP (layer 2) device */ dev->d_mtu = CONFIG_NET_TUN_MTU; #ifdef CONFIG_NET_TCP dev->d_recvwndo = CONFIG_NET_TUN_TCP_RECVWNDO; diff --git a/net/procfs/netdev_statistics.c b/net/procfs/netdev_statistics.c index d7673507b73..f4927eab2fe 100644 --- a/net/procfs/netdev_statistics.c +++ b/net/procfs/netdev_statistics.c @@ -62,7 +62,9 @@ static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile); static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile); - +#ifdef CONFIG_NET_IPv6 +static int netprocfs_dripaddress(FAR struct netprocfs_file_s *netfile); +#endif #ifdef CONFIG_NETDEV_STATISTICS static int netprocfs_rxstatistics_header(FAR struct netprocfs_file_s *netfile); static int netprocfs_rxstatistics(FAR struct netprocfs_file_s *netfile); @@ -83,6 +85,9 @@ static const linegen_t g_linegen[] = { netprocfs_linklayer, netprocfs_ipaddresses +#ifdef CONFIG_NET_IPv6 + , netprocfs_dripaddress +#endif #ifdef CONFIG_NETDEV_STATISTICS , netprocfs_rxstatistics_header, netprocfs_rxstatistics, @@ -151,12 +156,7 @@ static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile) { ieee = (FAR struct ieee802154_driver_s *)dev; -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - len += snprintf(&netfile->line[len], NET_LINELEN - len, - "%s\tLink encap:6loWPAN HWaddr %02x:%02x", - dev->d_ifname, - ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1]); -#else /* CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 */ +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED len += snprintf(&netfile->line[len], NET_LINELEN - len, "%s\tLink encap:6loWPAN HWaddr " "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", @@ -165,6 +165,11 @@ static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile) ieee->i_nodeaddr.u8[2], ieee->i_nodeaddr.u8[3], ieee->i_nodeaddr.u8[4], ieee->i_nodeaddr.u8[5], ieee->i_nodeaddr.u8[6], ieee->i_nodeaddr.u8[7]); +#else + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:6loWPAN HWaddr %02x:%02x", + dev->d_ifname, + ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1]); #endif } break; @@ -215,22 +220,22 @@ static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile) #elif defined(CONFIG_NET_6LOWPAN) ieee = (FAR struct ieee802154_driver_s *)dev; -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - len += snprintf(&netfile->line[len], NET_LINELEN - len, - "%s\tLink encap:6loWPAN HWaddr %02x:%02x at %s", - dev->d_ifname, - ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1], - status); -#else /* CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 */ +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED len += snprintf(&netfile->line[len], NET_LINELEN - len, "%s\tLink encap:6loWPAN HWaddr " - "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x at %s", + "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x at %s\n", dev->d_ifname, ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1], ieee->i_nodeaddr.u8[2], ieee->i_nodeaddr.u8[3], ieee->i_nodeaddr.u8[4], ieee->i_nodeaddr.u8[5], ieee->i_nodeaddr.u8[6], ieee->i_nodeaddr.u8[7], status); +#else + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:6loWPAN HWaddr %02x:%02x at %s\n", + dev->d_ifname, + ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1], + status); #endif #elif defined(CONFIG_NET_LOOPBACK) len += snprintf(&netfile->line[len], NET_LINELEN - len, @@ -292,7 +297,7 @@ static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile) addr.s_addr = dev->d_netmask; len += snprintf(&netfile->line[len], NET_LINELEN - len, - "Mask:%s\n", inet_ntoa(addr)); + "Mask:%s\n\n", inet_ntoa(addr)); #endif #ifdef CONFIG_NET_IPv6 @@ -307,19 +312,42 @@ static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile) len += snprintf(&netfile->line[len], NET_LINELEN - len, "\tinet6 addr:%s/%d\n", addrstr, preflen); } +#endif - /* REVISIT: Show the IPv6 default router address */ + return len; +} + +/**************************************************************************** + * Name: netprocfs_dripaddress + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv6 +static int netprocfs_dripaddress(FAR struct netprocfs_file_s *netfile) +{ + FAR struct net_driver_s *dev; + char addrstr[INET6_ADDRSTRLEN]; + uint8_t preflen; + int len = 0; + + DEBUGASSERT(netfile != NULL && netfile->dev != NULL); + dev = netfile->dev; + + /* Convert the 128 network mask to a human friendly prefix length */ + + preflen = net_ipv6_mask2pref(dev->d_ipv6netmask); + + + /* Show the IPv6 default router address */ if (inet_ntop(AF_INET6, dev->d_ipv6draddr, addrstr, INET6_ADDRSTRLEN)) { len += snprintf(&netfile->line[len], NET_LINELEN - len, - "\tinet6 DRaddr:%s/%d\n", addrstr, preflen); + "\tinet6 DRaddr:%s/%d\n\n", addrstr, preflen); } -#endif - len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n"); return len; } +#endif /**************************************************************************** * Name: netprocfs_rxstatistics_header @@ -443,7 +471,7 @@ static int netprocfs_txstatistics_header(FAR struct netprocfs_file_s *netfile) DEBUGASSERT(netfile != NULL); return snprintf(netfile->line, NET_LINELEN, "\tTX: %-8s %-8s %-8s %-8s\n", - "Queued", "Sent", "Erorts", "Timeouts"); + "Queued", "Sent", "Errors", "Timeouts"); } #endif /* CONFIG_NETDEV_STATISTICS */ diff --git a/net/sixlowpan/Kconfig b/net/sixlowpan/Kconfig index 02d17a42f1c..a5eed25dd76 100644 --- a/net/sixlowpan/Kconfig +++ b/net/sixlowpan/Kconfig @@ -133,12 +133,13 @@ config NET_6LOWPAN_MAXADDRCONTEXT_PREFIX_2_1 endif # NET_6LOWPAN_MAXADDRCONTEXT_PREINIT_0 endif # NET_6LOWPAN_COMPRESSION_HC06 -config NET_6LOWPAN_RIMEADDR_SIZE - int "Rime address size" - default 2 - range 2 8 +config NET_6LOWPAN_RIMEADDR_EXTENDED + int "Extended Rime address" + default n ---help--- - Only the values 2 and 8 are supported + By default, a 2-byte Rime address is used for the IEEE802.15.4 MAC + device's link layer address. If this option is selected, then an + 8-byte Rime address will be used. config NET_6LOWPAN_MAXAGE int "Packet reassembly timeout" diff --git a/net/sixlowpan/README.txt b/net/sixlowpan/README.txt new file mode 100644 index 00000000000..643735dd869 --- /dev/null +++ b/net/sixlowpan/README.txt @@ -0,0 +1,73 @@ +Optimal 6loWPAN Configuration +----------------------------- + +1. Link local IP addresses: + + 128 112 96 80 64 48 32 16 + fe80 0000 0000 0000 xxxx xxxx xxxx xxxx + +2. MAC-based IP addresses: + + 128 112 96 80 64 48 32 16 + ---- ---- ---- ---- ---- ---- ---- ---- + xxxx xxxx xxxx xxxx xxxx 00ff fe00 MMMM 2-byte Rime address IEEE 48-bit MAC + fe80 0000 0000 0000 NNNN NNNN NNNN NNNN 8-byte Rime address IEEE EUI-64 + + Where MMM is the 2-byte rime address XOR 0x0200. For example, the MAC + address of 0xabcd would be 0xa9cd. And NNNN NNNN NNNN NNNN is the 8-byte + rime address address XOR 02000 0000 0000 0000 + +3. MAC based link-local addresses + + 128 112 96 80 64 48 32 16 + ---- ---- ---- ---- ---- ---- ---- ---- + fe80 0000 0000 0000 0000 00ff fe00 MMMM 2-byte Rime address IEEE 48-bit MAC + fe80 0000 0000 0000 NNNN NNNN NNNN NNNN 8-byte Rime address IEEE EUI-64 + +4. Compressable port numbers in the rangs 0xf0b0-0xf0bf + +5. IOBs: Must be big enough to hold one IEEE802.15.4 frame (CONFIG_NET_6LOWPAN_FRAMELEN, + typically 127). There must be enough IOBs to decompose the largest IPv6 + packet (CONFIG_NET_6LOWPAN_MTU, default 1294, plus per frame overhead). + +Fragmentation Headers +--------------------- +A fragment header is placed at the beginning of the outgoing packet when the +payload is too large to fit in a single IEEE 802.15.4 frame. The fragment +header contains three fields: Datagram size, datagram tag and datagram +offset. + +1. Datagram size describes the total (un-fragmented) payload. +2. Datagram tag identifies the set of fragments and is used to match + fragments of the same payload. +3. Datagram offset identifies the fragment’s offset within the un- + fragmented payload (in units of 8 bytes). + +The length of the fragment header length is four bytes for the first header +(FRAG1) and five bytes for all subsequent headers (FRAGN). For example, +this is a HC1 compressed first frame of a packet + + c50e 000b ### 4-byte FRAG1 header + 01 08 01 0000 3412 ### 7-byte FCF header + 42 ### SIXLOWPAN_DISPATCH_HC1 + fb ### RIME_HC1_HC_UDP_HC1_ENCODING + e0 ### RIME_HC1_HC_UDP_UDP_ENCODING + 00 ### RIME_HC1_HC_UDP_TTL + 10 ### RIME_HC1_HC_UDP_PORTS + 0000 ### RIME_HC1_HC_UDP_CHKSUM + 4f4e452064617920 48656e6e792d7065 6e6e792077617320 7069636b696e6720 ### 80 byte payload + 757020636f726e20 696e207468652063 6f726e7961726420 7768656e2d2d7768 + 61636b212d2d736f 6d657468696e6720 g + +This is the second frame of the same transfer: + + e50e 000b 0a ### 5 byte FRAGN header + 01 08 01 0000 3412 ### 7-byte FCF header + 6869742068657220 75706f6e20746865 20686561642e2027 476f6f646e657373 ### 88 byte payload + 2067726163696f75 73206d6521272073 6169642048656e6e 792d70656e6e793b + 202774686520736b 79277320612d676f 696e6720746f2066 + +The payload length is encoded in the LS 11-bits of the first 16-bit value: +In this example the payload size is 0x050e or 1,294. The tag is 0x000b. In +the second frame, the fifth byte contains the offset 0x0a which is 10 << 3 = +80 bytes, the size of the payload on the first packet. diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 8995048b007..d8b751e8a75 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -101,19 +101,19 @@ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * Input Parameters: - * ieee - Pointer to IEEE802.15.4 MAC driver structure. - * destip - Pointer to the IPv6 header to "compress" - * fptr - Pointer to the beginning of the frame under construction + * ipv6hdr - Pointer to the IPv6 header to "compress" + * fptr - Pointer to the beginning of the frame under construction * * Returned Value: * None * ****************************************************************************/ -static void sixlowpan_compress_ipv6hdr(FAR struct ieee802154_driver_s *ieee, - FAR const struct ipv6_hdr_s *destip, +static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr, FAR uint8_t *fptr) { + uint16_t protosize; + /* Indicate the IPv6 dispatch and length */ fptr[g_frame_hdrlen] = SIXLOWPAN_DISPATCH_IPV6; @@ -121,9 +121,52 @@ static void sixlowpan_compress_ipv6hdr(FAR struct ieee802154_driver_s *ieee, /* Copy the IPv6 header and adjust pointers */ - memcpy(&fptr[g_frame_hdrlen] , destip, IPv6_HDRLEN); + memcpy(&fptr[g_frame_hdrlen] , ipv6hdr, IPv6_HDRLEN); g_frame_hdrlen += IPv6_HDRLEN; g_uncomp_hdrlen += IPv6_HDRLEN; + + /* Copy the following protocol header, */ + + switch (ipv6hdr->proto) + { +#ifdef CONFIG_NET_TCP + case IP_PROTO_TCP: + { + FAR struct tcp_hdr_s *tcp = &((FAR struct ipv6tcp_hdr_s *)ipv6hdr)->tcp; + + /* The TCP header length is encoded in the top 4 bits of the + * tcpoffset field (in units of 32-bit words). + */ + + protosize = ((uint16_t)tcp->tcpoffset >> 4) << 2; + } + break; +#endif + +#ifdef CONFIG_NET_UDP + case IP_PROTO_UDP: + protosize = sizeof(struct udp_hdr_s); + break; +#endif + +#ifdef CONFIG_NET_ICMPv6 + case IP_PROTO_ICMP6: + protosize = sizeof(struct icmpv6_hdr_s); + break; +#endif + + default: + nwarn("WARNING: Unrecognized proto: %u\n", ipv6hdr->proto); + return; + } + + /* Copy the protocol header. */ + + memcpy(fptr + g_frame_hdrlen, (FAR uint8_t *)ipv6hdr + g_uncomp_hdrlen, + protosize); + + g_frame_hdrlen += protosize; + g_uncomp_hdrlen += protosize; } /**************************************************************************** @@ -172,6 +215,8 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, FAR uint8_t *fptr; int framer_hdrlen; struct rimeaddr_s bcastmac; + uint16_t pktlen; + uint16_t paysize; #ifdef CONFIG_NET_6LOWPAN_FRAG uint16_t outlen = 0; #endif @@ -267,7 +312,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, { /* Small.. use IPv6 dispatch (no compression) */ - sixlowpan_compress_ipv6hdr(ieee, destip, fptr); + sixlowpan_compress_ipv6hdr(destip, fptr); } ninfo("Header of length %d\n", g_frame_hdrlen); @@ -276,9 +321,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Check if we need to fragment the packet into several frames */ - if ((int)buflen - (int)g_uncomp_hdrlen > - (int)CONFIG_NET_6LOWPAN_MAXPAYLOAD - framer_hdrlen - - (int)g_frame_hdrlen) + if (buflen > (CONFIG_NET_6LOWPAN_MAXPAYLOAD - g_frame_hdrlen)) { #ifdef CONFIG_NET_6LOWPAN_FRAG /* ieee->i_framelist will hold the generated frames; frames will be @@ -286,6 +329,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, */ FAR struct iob_s *qtail; + FAR uint8_t *frame1; int verify; /* The outbound IPv6 packet is too large to fit into a single 15.4 @@ -295,7 +339,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, * The following fragments contain only the fragn dispatch. */ - ninfo("Fragmentation sending packet length %d\n", buflen); + ninfo("Sending fragmented packet length %d\n", buflen); /* Create 1st Fragment */ /* Add the frame header using the pre-allocated IOB. */ @@ -304,7 +348,9 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, DEBUGASSERT(verify == framer_hdrlen); UNUSED(verify); - /* Move HC1/HC06/IPv6 header */ + /* Move HC1/HC06/IPv6 header to make space for the FRAG1 header at the + * beginning of the frame. + */ memmove(fptr + SIXLOWPAN_FRAG1_HDR_LEN, fptr, g_frame_hdrlen); @@ -323,27 +369,27 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, * bytes for all subsequent headers. */ + pktlen = buflen + g_uncomp_hdrlen; PUTINT16(fptr, RIME_FRAG_DISPATCH_SIZE, - ((SIXLOWPAN_DISPATCH_FRAG1 << 8) | buflen)); + ((SIXLOWPAN_DISPATCH_FRAG1 << 8) | pktlen)); PUTINT16(fptr, RIME_FRAG_TAG, ieee->i_dgramtag); - ieee->i_dgramtag++; - /* Copy payload and enqueue */ + g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; - g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; - g_rime_payloadlen = - (CONFIG_NET_6LOWPAN_MAXPAYLOAD - framer_hdrlen - g_frame_hdrlen) & 0xf8; + /* Copy payload and enqueue. NOTE that the size is a multiple of eight + * bytes. + */ - memcpy(fptr + g_frame_hdrlen, - (FAR uint8_t *)destip + g_uncomp_hdrlen, g_rime_payloadlen); - iob->io_len += g_rime_payloadlen + g_frame_hdrlen; + paysize = (CONFIG_NET_6LOWPAN_MAXPAYLOAD - g_frame_hdrlen) & ~7; + memcpy(fptr + g_frame_hdrlen, buf, paysize); /* Set outlen to what we already sent from the IP payload */ - outlen = g_rime_payloadlen + g_uncomp_hdrlen; + iob->io_len = paysize + g_frame_hdrlen; + outlen = paysize; ninfo("First fragment: length %d, tag %d\n", - g_rime_payloadlen, ieee->i_dgramtag); + paysize, ieee->i_dgramtag); sixlowpan_dumpbuffer("Outgoing frame", (FAR const uint8_t *)iob->io_data, iob->io_len); @@ -358,10 +404,11 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Create following fragments */ - g_frame_hdrlen = SIXLOWPAN_FRAGN_HDR_LEN; - + frame1 = iob->io_data; while (outlen < buflen) { + uint16_t fragn_hdrlen; + /* Allocate an IOB to hold the next fragment, waiting if * necessary. */ @@ -377,47 +424,45 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, iob->io_pktlen = 0; fptr = iob->io_data; - /* Add the frame header */ + /* Copy the frame header from first frame, into the correct + * location after the FRAGN header. + */ - verify = sixlowpan_framecreate(ieee, iob, ieee->i_panid); - DEBUGASSERT(verify == framer_hdrlen); - UNUSED(verify); + memmove(fptr + SIXLOWPAN_FRAGN_HDR_LEN, + frame1 + SIXLOWPAN_FRAG1_HDR_LEN, + framer_hdrlen); + fragn_hdrlen = framer_hdrlen; - /* Move HC1/HC06/IPv6 header */ - - memmove(fptr + SIXLOWPAN_FRAGN_HDR_LEN, fptr, g_frame_hdrlen); - - /* Setup up the fragment header */ + /* Setup up the FRAGN header at the beginning of the frame */ PUTINT16(fptr, RIME_FRAG_DISPATCH_SIZE, - ((SIXLOWPAN_DISPATCH_FRAGN << 8) | buflen)); + ((SIXLOWPAN_DISPATCH_FRAGN << 8) | pktlen)); PUTINT16(fptr, RIME_FRAG_TAG, ieee->i_dgramtag); fptr[RIME_FRAG_OFFSET] = outlen >> 3; + fragn_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN; + /* Copy payload and enqueue */ + /* Check for the last fragment */ - if (buflen - outlen < g_rime_payloadlen) + paysize = (CONFIG_NET_6LOWPAN_MAXPAYLOAD - fragn_hdrlen) & + SIXLOWPAN_DISPATCH_FRAG_MASK; + if (buflen - outlen < paysize) { - /* Last fragment */ + /* Last fragment, truncate to the correct length */ - g_rime_payloadlen = buflen - outlen; - } - else - { - g_rime_payloadlen = - (CONFIG_NET_6LOWPAN_MAXPAYLOAD - framer_hdrlen - g_frame_hdrlen) & 0xf8; + paysize = buflen - outlen; } - memcpy(fptr + g_frame_hdrlen, (FAR uint8_t *)destip + outlen, - g_rime_payloadlen); - iob->io_len = g_rime_payloadlen + g_frame_hdrlen; + memcpy(fptr + fragn_hdrlen, buf + outlen, paysize); /* Set outlen to what we already sent from the IP payload */ - outlen += (g_rime_payloadlen + g_uncomp_hdrlen); + iob->io_len = paysize + fragn_hdrlen; + outlen += paysize; - ninfo("sixlowpan output: fragment offset %d, length %d, tag %d\n", - outlen >> 3, g_rime_payloadlen, ieee->i_dgramtag); + ninfo("Fragment offset=%d, paysize=%d, i_dgramtag=%d\n", + outlen >> 3, paysize, ieee->i_dgramtag); sixlowpan_dumpbuffer("Outgoing frame", (FAR const uint8_t *)iob->io_data, iob->io_len); @@ -425,11 +470,16 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Add the next frame to the tail of the IOB queue */ qtail->io_flink = iob; + qtail = iob; /* Keep track of the total amount of data queue */ ieee->i_framelist->io_pktlen += iob->io_len; } + + /* Update the datagram TAG value */ + + ieee->i_dgramtag++; #else nerr("ERROR: Packet too large: %d\n", buflen); nerr(" Cannot to be sent without fragmentation support\n"); @@ -454,9 +504,8 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Copy the payload and queue */ - memcpy(fptr + g_frame_hdrlen, (FAR uint8_t *)destip + g_uncomp_hdrlen, - buflen - g_uncomp_hdrlen); - iob->io_len = buflen - g_uncomp_hdrlen + g_frame_hdrlen; + memcpy(fptr + g_frame_hdrlen, buf, buflen); + iob->io_len = buflen + g_frame_hdrlen; ninfo("Non-fragmented: length %d\n", iob->io_len); sixlowpan_dumpbuffer("Outgoing frame", diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index b0953db648c..746d6dc1139 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -125,11 +125,7 @@ static inline uint8_t sixlowpan_addrlen(uint8_t addrmode) static bool sixlowpan_addrnull(FAR uint8_t *addr) { -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - int i = 2; -#else - int i = 8; -#endif + int i = NET_6LOWPAN_RIMEADDR_SIZE; while (i-- > 0) { @@ -354,10 +350,10 @@ static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee, /* Use short address mode if so configured */ -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - params->fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; -#else +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED params->fcf.dest_addr_mode = FRAME802154_LONGADDRMODE; +#else + params->fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; #endif } @@ -543,14 +539,14 @@ int sixlowpan_framecreate(FAR struct ieee802154_driver_s *ieee, wlinfo("Frame type: %02x hdrlen: %d\n", params.fcf.frame_type, hdrlen); -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - wlinfo("Dest address: %02x:%02x\n", - params.dest_addr[0], params.dest_addr[1]); -#else +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED wlinfo("Dest address: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", params.dest_addr[0], params.dest_addr[1], params.dest_addr[2], params.dest_addr[3], params.dest_addr[4], params.dest_addr[5], params.dest_addr[6], params.dest_addr[7]); +#else + wlinfo("Dest address: %02x:%02x\n", + params.dest_addr[0], params.dest_addr[1]); #endif return hdrlen; diff --git a/net/sixlowpan/sixlowpan_globals.c b/net/sixlowpan/sixlowpan_globals.c index 8f48ade9f2f..aac17f7eb9c 100644 --- a/net/sixlowpan/sixlowpan_globals.c +++ b/net/sixlowpan/sixlowpan_globals.c @@ -54,15 +54,6 @@ * during that processing */ -/* The length of the payload in the Rime buffer. - * - * The payload is what comes after the compressed or uncompressed headers - * (can be the IP payload if the IP header only is compressed or the UDP - * payload if the UDP header is also compressed) - */ - -uint8_t g_rime_payloadlen; - /* g_uncomp_hdrlen is the length of the headers before compression (if HC2 * is used this includes the UDP header in addition to the IP header). */ diff --git a/net/sixlowpan/sixlowpan_hc06.c b/net/sixlowpan/sixlowpan_hc06.c index 9e51f88c17b..d449f829360 100644 --- a/net/sixlowpan/sixlowpan_hc06.c +++ b/net/sixlowpan/sixlowpan_hc06.c @@ -440,7 +440,7 @@ void sixlowpan_hc06_initialize(void) * ipv6 - The IPv6 header to be compressed * destmac - L2 destination address, needed to compress the IP * destination field - * fptr - Pointer to frame data payload. + * fptr - Pointer to frame to be compressed. * * Returned Value: * None @@ -840,7 +840,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, * inferred from the L2 length), non 0 if the packet is a first * fragment. * iob - Pointer to the IOB containing the received frame. - * payptr - Pointer to the frame data payload. + * fptr - Pointer to frame to be compressed. * * Returned Value: * None @@ -849,7 +849,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee, uint16_t iplen, FAR struct iob_s *iob, - FAR uint8_t *payptr) + FAR uint8_t *fptr) { FAR struct ipv6_hdr_s *ipv6 = IPv6BUF(ieee); FAR uint8_t *iphc; @@ -857,18 +857,18 @@ void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee, uint8_t iphc1; uint8_t tmp; - /* payptr points to IPHC. At least two byte will be used for the encoding. */ + /* iphc points to IPHC. At least two byte will be used for the encoding. */ - iphc = payptr; + iphc = fptr + g_frame_hdrlen; iphc0 = iphc[0]; iphc1 = iphc[1]; /* g_hc96ptr points to just after the 2-byte minimum IPHC */ - g_hc06ptr = payptr + 2; + g_hc06ptr = iphc + 2; - ninfo("payptr=%p g_frame_hdrlen=%u iphc=%02x:%02x:%02x g_hc06ptr=%p\n", - payptr, g_frame_hdrlen, iphc[0], iphc[1], iphc[2], g_hc06ptr); + ninfo("fptr=%p g_frame_hdrlen=%u iphc=%02x:%02x:%02x g_hc06ptr=%p\n", + fptr, g_frame_hdrlen, iphc[0], iphc[1], iphc[2], g_hc06ptr); /* Another if the CID flag is set */ @@ -1171,7 +1171,7 @@ void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee, } } - g_frame_hdrlen = g_hc06ptr - payptr; + g_frame_hdrlen = g_hc06ptr - fptr; /* IP length field. */ diff --git a/net/sixlowpan/sixlowpan_hc1.c b/net/sixlowpan/sixlowpan_hc1.c index 6626501363c..9f657a12dc6 100644 --- a/net/sixlowpan/sixlowpan_hc1.c +++ b/net/sixlowpan/sixlowpan_hc1.c @@ -258,7 +258,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, * inferred from the L2 length), non 0 if the packet is a 1st * fragment. * iob - Pointer to the IOB containing the received frame. - * payptr - Pointer to the frame data payload. + * fptr - Pointer to frame to be uncompressed. * * Returned Value: * Zero (OK) is returned on success, on failure a negater errno value is @@ -268,10 +268,10 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee, uint16_t iplen, FAR struct iob_s *iob, - FAR uint8_t *payptr) + FAR uint8_t *fptr) { FAR struct ipv6_hdr_s *ipv6 = IPv6BUF(&ieee->i_dev); - FAR uint8_t *hc1 = payptr + g_frame_hdrlen; + FAR uint8_t *hc1 = fptr + g_frame_hdrlen; /* Format the IPv6 header in the device d_buf */ /* Set version, traffic clase, and flow label */ @@ -312,7 +312,7 @@ int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee, case SIXLOWPAN_HC1_NH_UDP: { FAR struct udp_hdr_s *udp = UDPIPv6BUF(&ieee->i_dev); - FAR uint8_t *hcudp = payptr + g_frame_hdrlen; + FAR uint8_t *hcudp = fptr + g_frame_hdrlen; ipv6->proto = IP_PROTO_UDP; if ((hcudp[RIME_HC1_HC_UDP_HC1_ENCODING] & 0x01) != 0) diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index 257e7b48c9e..b19fa8ffba0 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -86,6 +86,7 @@ /* Buffer access helpers */ #define IPv6BUF(dev) ((FAR struct ipv6_hdr_s *)((dev)->d_buf)) +#define TCPBUF(dev) ((FAR struct tcp_hdr_s *)&(dev)->d_buf[IPv6_HDRLEN]) /**************************************************************************** * Private Functions @@ -111,12 +112,26 @@ int sixlowpan_recv_hdrlen(FAR const uint8_t *fptr) { - uint16_t hdrlen; + uint16_t hdrlen = 0; uint8_t addrmode; + uint8_t tmp; + + /* Check for a fragment header preceding the IEEE802.15.4 FCF */ + + tmp = *fptr & SIXLOWPAN_DISPATCH_FRAG_MASK; + if (tmp == SIXLOWPAN_DISPATCH_FRAG1) + { + hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; + } + else if (tmp == SIXLOWPAN_DISPATCH_FRAGN) + { + hdrlen += SIXLOWPAN_FRAGN_HDR_LEN; + } /* Minimum header: 2 byte FCF + 1 byte sequence number */ - hdrlen = 3; + fptr += hdrlen; + hdrlen += 3; /* Account for destination address size */ @@ -175,6 +190,91 @@ int sixlowpan_recv_hdrlen(FAR const uint8_t *fptr) return 0; } +/**************************************************************************** + * Name: sixlowpan_compress_ipv6hdr + * + * Description: + * IPv6 dispatch "compression" function. Packets "Compression" when only + * IPv6 dispatch is used + * + * There is no compression in this case, all fields are sent + * inline. We just add the IPv6 dispatch byte before the packet. + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | IPv6 Dsp | IPv6 header and payload ... + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + * Input Parameters: + * ieee - The IEEE802.15.4 MAC network driver interface. + * fptr - Pointer to the beginning of the frame under construction + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void sixlowpan_uncompress_ipv6hdr(FAR struct ieee802154_driver_s *ieee, + FAR uint8_t *fptr) +{ + FAR struct ipv6_hdr_s *ipv6 = IPv6BUF(&ieee->i_dev); + uint16_t protosize; + + /* Put uncompressed IPv6 header in d_buf. */ + + g_frame_hdrlen += SIXLOWPAN_IPV6_HDR_LEN; + memcpy(ipv6, fptr + g_frame_hdrlen, IPv6_HDRLEN); + + /* Update g_uncomp_hdrlen and g_frame_hdrlen. */ + + g_frame_hdrlen += IPv6_HDRLEN; + g_uncomp_hdrlen += IPv6_HDRLEN; + + /* Copy the following protocol header, */ + + switch (ipv6->proto) + { +#ifdef CONFIG_NET_TCP + case IP_PROTO_TCP: + { + FAR struct tcp_hdr_s *tcp = &((FAR struct ipv6tcp_hdr_s *)ipv6)->tcp; + + /* The TCP header length is encoded in the top 4 bits of the + * tcpoffset field (in units of 32-bit words). + */ + + protosize = ((uint16_t)tcp->tcpoffset >> 4) << 2; + } + break; +#endif + +#ifdef CONFIG_NET_UDP + case IP_PROTO_UDP: + protosize = sizeof(struct udp_hdr_s); + break; +#endif + +#ifdef CONFIG_NET_ICMPv6 + case IP_PROTO_ICMP6: + protosize = sizeof(struct icmpv6_hdr_s); + break; +#endif + + default: + nwarn("WARNING: Unrecognized proto: %u\n", ipv6->proto); + return; + } + + /* Copy the protocol header. */ + + memcpy((FAR uint8_t *)ipv6 + g_uncomp_hdrlen, fptr + g_frame_hdrlen, + protosize); + + g_frame_hdrlen += protosize; + g_uncomp_hdrlen += protosize; +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -209,10 +309,10 @@ int sixlowpan_recv_hdrlen(FAR const uint8_t *fptr) static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, FAR struct iob_s *iob) { - FAR uint8_t *payptr; /* Pointer to the frame payload */ + FAR uint8_t *fptr; /* Convenience pointer to beginning of the frame */ FAR uint8_t *hc1; /* Convenience pointer to HC1 data */ - uint16_t fragsize = 0; /* Size of the IP packet (read from fragment) */ + uint16_t paysize; /* Size of the data payload */ uint8_t fragoffset = 0; /* Offset of the fragment in the IP packet */ int reqsize; /* Required buffer size */ int hdrsize; /* Size of the IEEE802.15.4 header */ @@ -220,14 +320,16 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, #ifdef CONFIG_NET_6LOWPAN_FRAG bool isfrag = false; bool isfirstfrag = false; - bool islastfrag = false; uint16_t fragtag = 0; /* Tag of the fragment */ systime_t elapsed; /* Elapsed time */ #endif /* CONFIG_NET_6LOWPAN_FRAG */ - /* Get a pointer to the payload following the IEEE802.15.4 frame header. */ + /* Get a pointer to the payload following the IEEE802.15.4 frame header(s). + * This size includes both fragmentation and FCF headers. + */ - hdrsize = sixlowpan_recv_hdrlen(iob->io_data); + fptr = iob->io_data; + hdrsize = sixlowpan_recv_hdrlen(fptr); if (hdrsize < 0) { nwarn("Invalid IEEE802.15.2 header: %d\n", hdrsize); @@ -241,16 +343,13 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, g_uncomp_hdrlen = 0; g_frame_hdrlen = hdrsize; - /* Payload starts after the IEEE802.15.4 header */ - - payptr = &iob->io_data[hdrsize]; - #ifdef CONFIG_NET_6LOWPAN_FRAG /* Since we don't support the mesh and broadcast header, the first header - * we look for is the fragmentation header + * we look for is the fragmentation header. NOTE that g_frame_hdrlen + * already includes the fragementation header, if presetn. */ - switch ((GETINT16(payptr, RIME_FRAG_DISPATCH_SIZE) & 0xf800) >> 8) + switch ((GETINT16(fptr, RIME_FRAG_DISPATCH_SIZE) & 0xf800) >> 8) { /* First fragment of new reassembly */ @@ -258,15 +357,12 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, { /* Set up for the reassembly */ - fragoffset = 0; - fragsize = GETINT16(payptr, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; - fragtag = GETINT16(payptr, RIME_FRAG_TAG); + fragsize = GETINT16(fptr, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; + fragtag = GETINT16(fptr, RIME_FRAG_TAG); - ninfo("FRAG1: size %d, tag %d, offset %d\n", + ninfo("FRAG1: fragsize=%d fragtag=%d fragoffset=%d\n", fragsize, fragtag, fragoffset); - g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; - /* Indicate the first fragment of the reassembly */ isfirstfrag = true; @@ -278,32 +374,18 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, { /* Set offset, tag, size. Offset is in units of 8 bytes. */ - fragoffset = payptr[RIME_FRAG_OFFSET]; - fragtag = GETINT16(payptr, RIME_FRAG_TAG); - fragsize = GETINT16(payptr, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; + fragoffset = fptr[RIME_FRAG_OFFSET]; + fragtag = GETINT16(fptr, RIME_FRAG_TAG); + fragsize = GETINT16(fptr, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; - ninfo("FRAGN: size %d, tag %d, offset %d\n", + ninfo("FRAGN: fragsize=%d fragtag=%d fragoffset=%d\n", fragsize, fragtag, fragoffset); - - g_frame_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN; - - ninfo("FRAGN: i_accumlen %d g_rime_payloadlen %d fragsize %d\n", + ninfo("FRAGN: i_accumlen=%d paysize=%u fragsize=%u\n", ieee->i_accumlen, iob->io_len - g_frame_hdrlen, fragsize); /* Indicate that this frame is a another fragment for reassembly */ isfrag = true; - - /* Check if it is the last fragement to be processed. - * - * If this is the last fragment, we may shave off any extrenous - * bytes at the end. We must be liberal in what we accept. - */ - - if (ieee->i_accumlen + iob->io_len - g_frame_hdrlen >= fragsize) - { - islastfrag = true; - } } break; @@ -392,6 +474,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, * compression dispatch logic. */ + g_uncomp_hdrlen = ieee->i_boffset; goto copypayload; } } @@ -412,41 +495,34 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, return OK; } - /* Start reassembly if we received a non-zero length, first fragment */ + /* Drop the packet if it cannot fit into the d_buf */ - if (fragsize > 0) + if (fragsize > CONFIG_NET_6LOWPAN_MTU) { - /* Drop the packet if it cannot fit into the d_buf */ - - if (fragsize > CONFIG_NET_6LOWPAN_MTU) - { - nwarn("WARNING: Reassembled packet size exeeds CONFIG_NET_6LOWPAN_MTU\n"); - return OK; - } - - /* Set up for the reassembly */ - - ieee->i_pktlen = fragsize; - ieee->i_reasstag = fragtag; - ieee->i_time = clock_systimer(); - - ninfo("Starting reassembly: i_pktlen %d, i_pktlen %d\n", - ieee->i_pktlen, ieee->i_reasstag); - - rimeaddr_copy(&ieee->i_fragsrc, &g_pktaddrs[PACKETBUF_ADDR_SENDER]); + nwarn("WARNING: Reassembled packet size exeeds CONFIG_NET_6LOWPAN_MTU\n"); + return OK; } + + ieee->i_pktlen = fragsize; + ieee->i_reasstag = fragtag; + ieee->i_time = clock_systimer(); + + ninfo("Starting reassembly: i_pktlen %u, i_reasstag %d\n", + ieee->i_pktlen, ieee->i_reasstag); + + rimeaddr_copy(&ieee->i_fragsrc, &g_pktaddrs[PACKETBUF_ADDR_SENDER]); } #endif /* CONFIG_NET_6LOWPAN_FRAG */ /* Process next dispatch and headers */ - hc1 = &iob->io_data[g_frame_hdrlen]; + hc1 = fptr + g_frame_hdrlen; #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06 if ((hc1[RIME_HC1_DISPATCH] & SIXLOWPAN_DISPATCH_IPHC_MASK) == SIXLOWPAN_DISPATCH_IPHC) { ninfo("IPHC Dispatch\n"); - sixlowpan_uncompresshdr_hc06(ieee, fragsize, iob, payptr); + sixlowpan_uncompresshdr_hc06(ieee, fragsize, iob, fptr); } else #endif /* CONFIG_NET_6LOWPAN_COMPRESSION_HC06 */ @@ -455,33 +531,15 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, if (hc1[RIME_HC1_DISPATCH] == SIXLOWPAN_DISPATCH_HC1) { ninfo("HC1 Dispatch\n"); - sixlowpan_uncompresshdr_hc1(ieee, fragsize, iob, payptr); + sixlowpan_uncompresshdr_hc1(ieee, fragsize, iob, fptr); } else #endif /* CONFIG_NET_6LOWPAN_COMPRESSION_HC1 */ if (hc1[RIME_HC1_DISPATCH] == SIXLOWPAN_DISPATCH_IPV6) { - FAR struct ipv6_hdr_s *ipv6 = IPv6BUF(&ieee->i_dev); - ninfo("IPv6 Dispatch\n"); - g_frame_hdrlen += SIXLOWPAN_IPV6_HDR_LEN; - - /* payptr was set up to begin just after the IPHC bytes. However, - * those bytes are not present for the case of IPv6 dispatch. Just - * reset back to the begnning of the buffer. - */ - - payptr = iob->io_data; - - /* Put uncompressed IP header in d_buf. */ - - memcpy(ipv6, payptr + g_frame_hdrlen, IPv6_HDRLEN); - - /* Update g_uncomp_hdrlen and g_frame_hdrlen. */ - - g_frame_hdrlen += IPv6_HDRLEN; - g_uncomp_hdrlen += IPv6_HDRLEN; + sixlowpan_uncompress_ipv6hdr(ieee, fptr); } else { @@ -492,6 +550,18 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, } #ifdef CONFIG_NET_6LOWPAN_FRAG + /* Non-fragmented and FRAG1 frames pass through here. Remember the + * offset from the beginning of d_buf where be begin placing the data + * payload. + */ + + if (isfirstfrag) + { + ieee->i_boffset = g_uncomp_hdrlen; + } + + /* We branch to here on all good FRAGN frames */ + copypayload: #endif /* CONFIG_NET_6LOWPAN_FRAG */ @@ -501,28 +571,27 @@ copypayload: * and g_frame_hdrlen are non-zerio, fragoffset is. */ - g_rime_payloadlen = iob->io_len - g_frame_hdrlen; - if (g_rime_payloadlen > CONFIG_NET_6LOWPAN_MTU) + paysize = iob->io_len - g_frame_hdrlen; + if (paysize > CONFIG_NET_6LOWPAN_MTU) { nwarn("WARNING: Packet dropped due to payload (%u) > packet buffer (%u)\n", - g_rime_payloadlen, CONFIG_NET_6LOWPAN_MTU); + paysize, CONFIG_NET_6LOWPAN_MTU); return OK; } /* Sanity-check size of incoming packet to avoid buffer overflow */ - reqsize = g_uncomp_hdrlen + (uint16_t) (fragoffset << 3) + g_rime_payloadlen; + reqsize = g_uncomp_hdrlen + (fragoffset << 3) + paysize; if (reqsize > CONFIG_NET_6LOWPAN_MTU) { - ninfo("Required buffer size: %d+%d+%d=%d Available: %d\n", - g_uncomp_hdrlen, (int)(fragoffset << 3), g_rime_payloadlen, + ninfo("Required buffer size: %u+%u+%u=%u Available=%u\n", + g_uncomp_hdrlen, (fragoffset << 3), paysize, reqsize, CONFIG_NET_6LOWPAN_MTU); return -ENOMEM; } - memcpy((FAR uint8_t *)ieee->i_dev.d_buf + g_uncomp_hdrlen + - (int)(fragoffset << 3), payptr + g_frame_hdrlen, - g_rime_payloadlen); + memcpy(ieee->i_dev.d_buf + g_uncomp_hdrlen + (fragoffset << 3), + fptr + g_frame_hdrlen, paysize); #ifdef CONFIG_NET_6LOWPAN_FRAG /* Update ieee->i_accumlen if the frame is a fragment, ieee->i_pktlen @@ -531,42 +600,27 @@ copypayload: if (isfrag) { - /* Add the size of the header only for the first fragment. */ - - if (isfirstfrag) - { - ieee->i_accumlen += g_uncomp_hdrlen; - } - - /* For the last fragment, we are OK if there is extraneous bytes at the - * end of the packet. + /* Check if it is the last fragment to be processed. + * + * If this is the last fragment, we may shave off any extrenous + * bytes at the end. We must be liberal in what we accept. */ - if (islastfrag) - { - ieee->i_accumlen = fragsize; - } - else - { - ieee->i_accumlen += g_rime_payloadlen; - } - - ninfo("i_accumlen %d, g_rime_payloadlen %d\n", - ieee->i_accumlen, g_rime_payloadlen); + ieee->i_accumlen = g_uncomp_hdrlen + (fragoffset << 3) + paysize; } else { - ieee->i_pktlen = g_rime_payloadlen + g_uncomp_hdrlen; + ieee->i_pktlen = paysize + g_uncomp_hdrlen; } /* If we have a full IP packet in sixlowpan_buf, deliver it to * the IP stack */ - ninfo("sixlowpan_init i_accumlen %d, ieee->i_pktlen %d\n", - ieee->i_accumlen, ieee->i_pktlen); + ninfo("i_accumlen=%d i_pktlen=%d paysize=%d\n", + ieee->i_accumlen, ieee->i_pktlen, paysize); - if (ieee->i_accumlen == 0 || ieee->i_accumlen == ieee->i_pktlen) + if (ieee->i_accumlen == 0 || ieee->i_accumlen >= ieee->i_pktlen) { ninfo("IP packet ready (length %d)\n", ieee->i_pktlen); @@ -580,7 +634,7 @@ copypayload: #else /* Deliver the packet to the IP stack */ - ieee->i_dev.d_len = g_rime_payloadlen + g_uncomp_hdrlen; + ieee->i_dev.d_len = paysize + g_uncomp_hdrlen; return INPUT_COMPLETE; #endif /* CONFIG_NET_6LOWPAN_FRAG */ } @@ -699,13 +753,16 @@ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee) FRAME_IOB_REMOVE(ieee, iob); DEBUGASSERT(iob != NULL); - sixlowpan_dumpbuffer("Incoming frame", - (FAR const uint8_t *)iob->io_data, iob->io_len); + sixlowpan_dumpbuffer("Incoming frame", iob->io_data, iob->io_len); /* Process the frame, decompressing it into the packet buffer */ ret = sixlowpan_frame_process(ieee, iob); + /* Free the IOB the held the consumed frame */ + + iob_free(iob); + /* Was the frame successfully processed? Is the packet in d_buf fully * reassembled? */ @@ -734,7 +791,7 @@ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee) * layer protocol header. */ - ipv6hdr = (FAR struct ipv6_hdr_s *)(ieee->i_dev.d_buf); + ipv6hdr = IPv6BUF(&ieee->i_dev); /* Get the Rime MAC address of the destination. This * assumes an encoding of the MAC address in the IPv6 @@ -749,7 +806,15 @@ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee) if (ipv6hdr->proto != IP_PROTO_TCP) { - hdrlen = IPv6_HDRLEN + TCP_HDRLEN; + FAR struct tcp_hdr_s *tcp = TCPBUF(&ieee->i_dev); + uint16_t tcplen; + + /* The TCP header length is encoded in the top 4 bits + * of the tcpoffset field (in units of 32-bit words). + */ + + tcplen = ((uint16_t)tcp->tcpoffset >> 4) << 2; + hdrlen = IPv6_HDRLEN + tcplen; } else if (ipv6hdr->proto != IP_PROTO_UDP) { diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index d6a795c5540..be29abc8cae 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -74,92 +74,16 @@ /* Rime addres macros */ /* Copy a Rime address */ -#define rimeaddr_copy(dest,src) \ - memcpy(dest, src, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE) +#define rimeaddr_copy(dest,src) \ + memcpy(dest, src, NET_6LOWPAN_RIMEADDR_SIZE) /* Compare two Rime addresses */ #define rimeaddr_cmp(addr1,addr2) \ - (memcmp(addr1, addr2, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE) == 0) + (memcmp(addr1, addr2, NET_6LOWPAN_RIMEADDR_SIZE) == 0) /* Pointers in the Rime buffer */ -/* Fragment header. - * - * The fragment header is used when the payload is too large to fit in a - * single IEEE 802.15.4 frame. The fragment header contains three fields: - * Datagram size, datagram tag and datagram offset. - * - * 1. Datagram size describes the total (un-fragmented) payload. - * 2. Datagram tag identifies the set of fragments and is used to match - * fragments of the same payload. - * 3. Datagram offset identifies the fragment’s offset within the un- - * fragmented payload. - * - * The fragment header length is 4 bytes for the first header and 5 - * bytes for all subsequent headers. - */ - -#define RIME_FRAG_DISPATCH_SIZE 0 /* 16 bit */ -#define RIME_FRAG_TAG 2 /* 16 bit */ -#define RIME_FRAG_OFFSET 4 /* 8 bit */ - -/* Define the Rime buffer as a byte array */ - -#define RIME_HC1_DISPATCH 0 /* 8 bit */ -#define RIME_HC1_ENCODING 1 /* 8 bit */ -#define RIME_HC1_TTL 2 /* 8 bit */ - -#define RIME_HC1_HC_UDP_DISPATCH 0 /* 8 bit */ -#define RIME_HC1_HC_UDP_HC1_ENCODING 1 /* 8 bit */ -#define RIME_HC1_HC_UDP_UDP_ENCODING 2 /* 8 bit */ -#define RIME_HC1_HC_UDP_TTL 3 /* 8 bit */ -#define RIME_HC1_HC_UDP_PORTS 4 /* 8 bit */ -#define RIME_HC1_HC_UDP_CHKSUM 5 /* 16 bit */ - -/* These are some definitions of element values used in the FCF. See the - * IEEE802.15.4 spec for details. - */ - -#define FRAME802154_FRAMETYPE_SHIFT (0) /* Bits 0-2: Frame type */ -#define FRAME802154_FRAMETYPE_MASK (7 << FRAME802154_FRAMETYPE_SHIFT) -#define FRAME802154_SECENABLED_SHIFT (3) /* Bit 3: Security enabled */ -#define FRAME802154_FRAMEPENDING_SHIFT (4) /* Bit 4: Frame pending */ -#define FRAME802154_ACKREQUEST_SHIFT (5) /* Bit 5: ACK request */ -#define FRAME802154_PANIDCOMP_SHIFT (6) /* Bit 6: PANID compression */ - /* Bits 7-9: Reserved */ -#define FRAME802154_DSTADDR_SHIFT (2) /* Bits 10-11: Dest address mode */ -#define FRAME802154_DSTADDR_MASK (3 << FRAME802154_DSTADDR_SHIFT) -#define FRAME802154_VERSION_SHIFT (4) /* Bit 12-13: Frame version */ -#define FRAME802154_VERSION_MASK (3 << FRAME802154_VERSION_SHIFT) -#define FRAME802154_SRCADDR_SHIFT (6) /* Bits 14-15: Source address mode */ -#define FRAME802154_SRCADDR_MASK (3 << FRAME802154_SRCADDR_SHIFT) - -/* Unshifted values for use in struct frame802154_fcf_s */ - -#define FRAME802154_BEACONFRAME (0) -#define FRAME802154_DATAFRAME (1) -#define FRAME802154_ACKFRAME (2) -#define FRAME802154_CMDFRAME (3) - -#define FRAME802154_BEACONREQ (7) - -#define FRAME802154_IEEERESERVED (0) -#define FRAME802154_NOADDR (0) /* Only valid for ACK or Beacon frames */ -#define FRAME802154_SHORTADDRMODE (2) -#define FRAME802154_LONGADDRMODE (3) - -#define FRAME802154_NOBEACONS 0x0f - -#define FRAME802154_BROADCASTADDR 0xffff -#define FRAME802154_BROADCASTPANDID 0xffff - -#define FRAME802154_IEEE802154_2003 (0) -#define FRAME802154_IEEE802154_2006 (1) - -#define FRAME802154_SECURITY_LEVEL_NONE (0) -#define FRAME802154_SECURITY_LEVEL_128 (3) - /* Packet buffer Definitions */ #define PACKETBUF_ATTR_PACKET_TYPE_DATA 0 @@ -168,7 +92,7 @@ #define PACKETBUF_ATTR_PACKET_TYPE_STREAM_END 3 #define PACKETBUF_ATTR_PACKET_TYPE_TIMESTAMP 4 -/* Packet buffer attributes (indices into i_pktattr) */ +/* Packet buffer attributes (indices into g_pktattrs) */ #define PACKETBUF_ATTR_NONE 0 @@ -206,7 +130,7 @@ #define PACKETBUF_NUM_ATTRS 24 -/* Addresses (indices into i_pktaddr) */ +/* Addresses (indices into g_pktaddrs) */ #define PACKETBUF_ADDR_SENDER 0 #define PACKETBUF_ADDR_RECEIVER 1 @@ -215,69 +139,6 @@ #define PACKETBUF_NUM_ADDRS 4 -/* Address compressibility test macros **************************************/ - -/* Check whether we can compress the IID in address 'a' to 16 bits. This is - * used for unicast addresses only, and is true if the address is on the - * format ::0000:00ff:fe00:XXXX - * - * NOTE: we currently assume 64-bits prefixes - */ - -/* Check whether we can compress the IID in address 'a' to 16 bits. This is - * used for unicast addresses only, and is true if the address is on the - * format ::0000:00ff:fe00:XXXX. - * - * NOTE: we currently assume 64-bits prefixes. Big-endian, network order is - * assumed. - */ - -#define SIXLOWPAN_IS_IID_16BIT_COMPRESSABLE(a) \ - ((((a)[4]) == 0x0000) && (((a)[5]) == HTONS(0x00ff)) && \ - (((a)[6]) == 0xfe00)) - -/* Check whether the 9-bit group-id of the compressed multicast address is - * known. It is true if the 9-bit group is the all nodes or all routers - * group. Parameter 'a' is typed uint8_t * - */ - -#define SIXLOWPAN_IS_MCASTADDR_DECOMPRESSABLE(a) \ - (((*a & 0x01) == 0) && \ - ((*(a + 1) == 0x01) || (*(a + 1) == 0x02))) - -/* Check whether the 112-bit group-id of the multicast address is mappable - * to a 9-bit group-id. It is true if the group is the all nodes or all - * routers group: - * - * XXXX:0000:0000:0000:0000:0000:0000:0001 All nodes address - * XXXX:0000:0000:0000:0000:0000:0000:0002 All routers address - */ - -#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE(a) \ - ((a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ - (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && \ - ((a)[7] == HTONS(0x0001) || (a)[7] == HTONS(0x0002))) - -/* FFXX:0000:0000:0000:0000:00XX:XXXX:XXXX */ - -#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE48(a) \ - ((a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ - (a)[4] == 0 && (((a)[5] & HTONS(0xff00)) == 0)) - -/* FFXX:0000:0000:0000:0000:0000:00XX:XXXX */ - -#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE32(a) \ - ((a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ - (a)[4] == 0 && (a)[5] == 0 && ((a)[6] & HTONS(0xff00)) == 0) - -/* FF02:0000:0000:0000:0000:0000:0000:00XX */ - -#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE8(a) \ - ((((a)[0] & HTONS(0x00ff)) == HTONS(0x0002)) && \ - (a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ - (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && \ - (((a)[7] & HTONS(0xff00)) == 0x0000)) - /* General helper macros ****************************************************/ #define GETINT16(ptr,index) \ @@ -409,15 +270,6 @@ struct frame802154_s extern FAR uint8_t *g_rimeptr; -/* The length of the payload in the Rime buffer. - * - * The payload is what comes after the compressed or uncompressed headers - * (can be the IP payload if the IP header only is compressed or the UDP - * payload if the UDP header is also compressed) - */ - -extern uint8_t g_rime_payloadlen; - /* g_uncomp_hdrlen is the length of the headers before compression (if HC2 * is used this includes the UDP header in addition to the IP header). */ @@ -650,7 +502,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, * inferred from the L2 length), non 0 if the packet is a first * fragment. * iob - Pointer to the IOB containing the received frame. - * payptr - Pointer to the frame data payload. + * fptr - Pointer to frame to be uncompressed. * * Returned Value: * None @@ -660,7 +512,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06 void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee, uint16_t iplen, FAR struct iob_s *iob, - FAR uint8_t *payptr); + FAR uint8_t *fptr); #endif /**************************************************************************** @@ -710,7 +562,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, * inferred from the L2 length), non 0 if the packet is a first * fragment. * iob - Pointer to the IOB containing the received frame. - * payptr - Pointer to the frame data payload. + * fptr - Pointer to frame to be uncompressed. * * Returned Value: * None @@ -720,7 +572,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1 int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee, uint16_t ip_len, FAR struct iob_s *iob, - FAR uint8_t *payptr); + FAR uint8_t *fptr); #endif /**************************************************************************** diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index a34bfe0666e..3ee39e72ed6 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -88,6 +88,7 @@ static uint16_t sixlowpan_tcp_chksum(FAR struct ipv6tcp_hdr_s *ipv6tcp, FAR const uint8_t *buf, uint16_t buflen) { uint16_t upperlen; + uint16_t tcplen; uint16_t sum; /* The length reported in the IPv6 header is the length of the payload @@ -115,9 +116,14 @@ static uint16_t sixlowpan_tcp_chksum(FAR struct ipv6tcp_hdr_s *ipv6tcp, sum = chksum(sum, (FAR uint8_t *)ipv6tcp->ipv6.srcipaddr, 2 * sizeof(net_ipv6addr_t)); - /* Sum the TCP header */ + /* Sum the TCP header + * + * The TCP header length is encoded in the top 4 bits of the tcpoffset + * field (in units of 32-bit words). + */ - sum = chksum(sum, (FAR uint8_t *)&ipv6tcp->tcp, TCP_HDRLEN); + tcplen = ((uint16_t)ipv6tcp->tcp.tcpoffset >> 4) << 2; + sum = chksum(sum, (FAR uint8_t *)&ipv6tcp->tcp, tcplen); /* Sum payload data. */ @@ -383,38 +389,62 @@ void sixlowpan_tcp_send(FAR struct net_driver_s *dev) if (dev != NULL && dev->d_len > 0) { - FAR struct ipv6_hdr_s *ipv6hdr; + FAR struct ipv6tcp_hdr_s *ipv6hdr; /* The IPv6 header followed by a TCP headers should lie at the * beginning of d_buf since there is no link layer protocol header * and the TCP state machine should only response with TCP packets. */ - ipv6hdr = (FAR struct ipv6_hdr_s *)(dev->d_buf); + ipv6hdr = (FAR struct ipv6tcp_hdr_s *)(dev->d_buf); /* The TCP data payload should follow the IPv6 header plus the * protocol header. */ - if (ipv6hdr->proto != IP_PROTO_TCP) + if (ipv6hdr->ipv6.proto != IP_PROTO_TCP) { - nwarn("WARNING: Expected TCP protoype: %u\n", ipv6hdr->proto); + nwarn("WARNING: Expected TCP protoype: %u vs %s\n", + ipv6hdr->ipv6.proto, IP_PROTO_TCP); } else { struct rimeaddr_s destmac; + FAR uint8_t *buf; + uint16_t hdrlen; + uint16_t buflen; /* Get the Rime MAC address of the destination. This assumes an * encoding of the MAC address in the IPv6 address. */ - sixlowpan_rimefromip(ipv6hdr->destipaddr, &destmac); + sixlowpan_rimefromip(ipv6hdr->ipv6.destipaddr, &destmac); - /* Convert the outgoing packet into a frame list. */ + /* Get the IPv6 + TCP combined header length. The size of the TCP + * header is encoded in the top 4 bits of the tcpoffset field (in + * units of 32-bit words). + */ - (void)sixlowpan_queue_frames( - (FAR struct ieee802154_driver_s *)dev, ipv6hdr, - dev->d_buf, dev->d_len, &destmac); + hdrlen = IPv6_HDRLEN + (((uint16_t)ipv6hdr->tcp.tcpoffset >> 4) << 2); + + /* Drop the packet if the buffer length is less than this. */ + + if (hdrlen > dev->d_len) + { + nwarn("WARNING: Dropping small TCP packet: %u < %u\n", + buflen, hdrlen); + } + else + { + /* Convert the outgoing packet into a frame list. */ + + buf = dev->d_buf + hdrlen; + buflen = dev->d_len - hdrlen; + + (void)sixlowpan_queue_frames( + (FAR struct ieee802154_driver_s *)dev, &ipv6hdr->ipv6, + buf, buflen, &destmac); + } } } diff --git a/net/sixlowpan/sixlowpan_utils.c b/net/sixlowpan/sixlowpan_utils.c index fc322ec38e1..dcda6be652d 100644 --- a/net/sixlowpan/sixlowpan_utils.c +++ b/net/sixlowpan/sixlowpan_utils.c @@ -88,14 +88,14 @@ void sixlowpan_ipfromrime(FAR const struct rimeaddr_s *rime, memset(ipaddr, 0, sizeof(net_ipv6addr_t)); ipaddr[0] = HTONS(0xfe80); -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED + memcpy(&ipaddr[4], rime, NET_6LOWPAN_RIMEADDR_SIZE); + ipaddr[4] ^= HTONS(0x0200); +#else ipaddr[5] = HTONS(0x00ff); ipaddr[6] = HTONS(0xfe00); - memcpy(&ipaddr[7], rime, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE); + memcpy(&ipaddr[7], rime, NET_6LOWPAN_RIMEADDR_SIZE); ipaddr[7] ^= HTONS(0x0200); -#else - memcpy(&ipaddr[4], rime, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE); - ipaddr[4] ^= HTONS(0x0200); #endif } @@ -119,10 +119,10 @@ void sixlowpan_rimefromip(const net_ipv6addr_t ipaddr, DEBUGASSERT(ipaddr[0] == HTONS(0xfe80)); -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - memcpy(rime, &ipaddr[7], CONFIG_NET_6LOWPAN_RIMEADDR_SIZE); +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED + memcpy(rime, &ipaddr[4], NET_6LOWPAN_RIMEADDR_SIZE); #else - memcpy(rime, &ipaddr[4], CONFIG_NET_6LOWPAN_RIMEADDR_SIZE); + memcpy(rime, &ipaddr[7], NET_6LOWPAN_RIMEADDR_SIZE); #endif rime->u8[0] ^= 0x02; } @@ -145,14 +145,14 @@ bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, { FAR const uint8_t *rimeptr = rime->u8; -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - return (ipaddr[5] == HTONS(0x00ff) && ipaddr[6] == HTONS(0xfe00) && - ipaddr[7] == htons((GETINT16(rimeptr, 0) ^ 0x0200))); -#else /* CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 */ +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED return (ipaddr[4] == htons((GETINT16(rimeptr, 0) ^ 0x0200)) && ipaddr[5] == GETINT16(rimeptr, 2) && ipaddr[6] == GETINT16(rimeptr, 4) && ipaddr[7] == GETINT16(rimeptr, 6)); +#else + return (ipaddr[5] == HTONS(0x00ff) && ipaddr[6] == HTONS(0xfe00) && + ipaddr[7] == htons((GETINT16(rimeptr, 0) ^ 0x0200))); #endif } diff --git a/sched/Kconfig b/sched/Kconfig index 50613fb44d3..6cefe0e121f 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -601,8 +601,6 @@ config PTHREAD_CLEANUP_STACKSIZE 8 for a CPU with 32-bit addressing and 4 for a CPU with 16-bit addressing. -endmenu # Pthread Options - config CANCELLATION_POINTS bool "Cancellation points" default n @@ -611,6 +609,8 @@ config CANCELLATION_POINTS cancellation points will also used with the () task_delete() API even if pthreads are not enabled. +endmenu # Pthread Options + menu "Performance Monitoring" config SCHED_CPULOAD diff --git a/sched/pthread/pthread.h b/sched/pthread/pthread.h index b4e87d95339..69e08e1445a 100644 --- a/sched/pthread/pthread.h +++ b/sched/pthread/pthread.h @@ -121,6 +121,14 @@ void pthread_mutex_inconsistent(FAR struct pthread_tcb_s *tcb); # define pthread_mutex_give(m) pthread_givesemaphore(&(m)->sem) #endif +#ifdef CONFIG_CANCELLATION_POINTS +uint16_t pthread_disable_cancel(void); +void pthread_enable_cancel(uint16_t oldstate); +#else +# define pthread_disable_cancel() (0) +# define pthread_enable_cancel(s) UNUSED(s) +#endif + #ifdef CONFIG_PTHREAD_MUTEX_TYPES int pthread_mutexattr_verifytype(int type); #endif diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c index e2cad60ebbf..20e6f838b73 100644 --- a/sched/pthread/pthread_cancel.c +++ b/sched/pthread/pthread_cancel.c @@ -150,9 +150,9 @@ int pthread_cancel(pthread_t thread) * * REVISIT: In this case, the clean-up callback will execute on the * thread of the caller of pthread cancel, not on the thread of - * the thread-to-be-canceled. Is that an issue? Presumably they - * are both within the same group and within the same process address - * space. + * the thread-to-be-canceled. This is a problem when deferred + * cancellation is not supported because, for example, the clean-up + * function will be unable to unlock its own mutexes. */ pthread_cleanup_popall(tcb); diff --git a/sched/pthread/pthread_condtimedwait.c b/sched/pthread/pthread_condtimedwait.c index 4ed8c5aed6e..22ce470770a 100644 --- a/sched/pthread/pthread_condtimedwait.c +++ b/sched/pthread/pthread_condtimedwait.c @@ -167,9 +167,10 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, FAR const struct timespec *abstime) { FAR struct tcb_s *rtcb = this_task(); + irqstate_t flags; + uint16_t oldstate; int ticks; int mypid = (int)getpid(); - irqstate_t flags; int ret = OK; int status; @@ -316,7 +317,11 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, /* Reacquire the mutex (retaining the ret). */ sinfo("Re-locking...\n"); + + oldstate = pthread_disable_cancel(); status = pthread_mutex_take(mutex, false); + pthread_enable_cancel(oldstate); + if (status == OK) { mutex->pid = mypid; diff --git a/sched/pthread/pthread_condwait.c b/sched/pthread/pthread_condwait.c index 9bcba234a5f..91138215fa3 100644 --- a/sched/pthread/pthread_condwait.c +++ b/sched/pthread/pthread_condwait.c @@ -95,6 +95,8 @@ int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex) } else { + uint16_t oldstate; + /* Give up the mutex */ sinfo("Give up mutex / take cond\n"); @@ -117,12 +119,17 @@ int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex) /* Reacquire the mutex. * - * REVISIT: When cancellation points are enabled, we will almost - * certainly hold the mutex when the pthread is canceled. + * When cancellation points are enabled, we need to + * hold the mutex when the pthread is canceled and + * cleanup handlers, if any, are entered. */ sinfo("Reacquire mutex...\n"); + + oldstate = pthread_disable_cancel(); status = pthread_mutex_take(mutex, false); + pthread_enable_cancel(oldstate); + if (ret == OK) { /* Report the first failure that occurs */ diff --git a/sched/pthread/pthread_mutex.c b/sched/pthread/pthread_mutex.c index f11a5b01f6f..45c4ffd3fa8 100644 --- a/sched/pthread/pthread_mutex.c +++ b/sched/pthread/pthread_mutex.c @@ -95,8 +95,8 @@ static void pthread_mutex_add(FAR struct pthread_mutex_s *mutex) * mutex to the list of mutexes held by this thread. * * Parameters: - * mutex - The mux to be locked - * intr - false: ignore EINTR errors when locking; true tread EINTR as + * mutex - The mutex to be locked + * intr - false: ignore EINTR errors when locking; true treat EINTR as * other errors by returning the errno value * * Return Value: @@ -125,14 +125,12 @@ int pthread_mutex_take(FAR struct pthread_mutex_s *mutex, bool intr) } else { - /* Take semaphore underlying the mutex */ + /* Take semaphore underlying the mutex. pthread_takesemaphore + * returns zero on success and a positive errno value on failure. + */ ret = pthread_takesemaphore(&mutex->sem, intr); - if (ret < OK) - { - ret = get_errno(); - } - else + if (ret == OK) { /* Check if the holder of the mutex has terminated without * releasing. In that case, the state of the mutex is @@ -167,8 +165,8 @@ int pthread_mutex_take(FAR struct pthread_mutex_s *mutex, bool intr) * mutex to the list of mutexes held by this thread. * * Parameters: - * mutex - The mux to be locked - * intr - false: ignore EINTR errors when locking; true tread EINTR as + * mutex - The mutex to be locked + * intr - false: ignore EINTR errors when locking; true treat EINTR as * other errors by returning the errno value * * Return Value: @@ -281,3 +279,70 @@ int pthread_mutex_give(FAR struct pthread_mutex_s *mutex) return ret; } +/**************************************************************************** + * Name: pthread_disable_cancel() and pthread_enable_cancel() + * + * Description: + * Temporarily disable cancellation and return old cancel state, which + * can later be restored. This is useful when a cancellation point + * function is called from within the OS by a non-cancellation point: + * In certain such cases, we need to defer the cancellation to prevent + * bad things from happening. + * + * Parameters: + * saved cancel flags for pthread_enable_cancel() + * + * Return Value: + * old cancel flags for pthread_disable_cancel() + * + ****************************************************************************/ + +#ifdef CONFIG_CANCELLATION_POINTS +uint16_t pthread_disable_cancel(void) +{ + FAR struct pthread_tcb_s *tcb = (FAR struct pthread_tcb_s *)this_task(); + irqstate_t flags; + uint16_t old; + + /* We need perform the following operations from within a critical section + * because it can compete with interrupt level activity. + */ + + flags = enter_critical_section(); + old = tcb->cmn.flags & (TCB_FLAG_CANCEL_PENDING | TCB_FLAG_NONCANCELABLE); + tcb->cmn.flags &= ~(TCB_FLAG_CANCEL_PENDING | TCB_FLAG_NONCANCELABLE); + leave_critical_section(flags); + return old; +} + +void pthread_enable_cancel(uint16_t cancelflags) +{ + FAR struct pthread_tcb_s *tcb = (FAR struct pthread_tcb_s *)this_task(); + irqstate_t flags; + + /* We need perform the following operations from within a critical section + * because it can compete with interrupt level activity. + */ + + flags = enter_critical_section(); + tcb->cmn.flags |= cancelflags; + + /* What should we do if there is a pending cancellation? + * + * If the thread is executing with deferred cancellation, we need do + * nothing more; the cancellation cannot occur until the next + * cancellation point. + * + * However, if the thread is executing in asynchronous cancellation mode, + * then we need to terminate now by simply calling pthread_exit(). + */ + + if ((tcb->cmn.flags & TCB_FLAG_CANCEL_DEFERRED) == 0 && + (tcb->cmn.flags & TCB_FLAG_CANCEL_PENDING) != 0) + { + pthread_exit(NULL); + } + + leave_critical_section(flags); +} +#endif /* CONFIG_CANCELLATION_POINTS */ diff --git a/sched/pthread/pthread_mutexconsistent.c b/sched/pthread/pthread_mutexconsistent.c index 77d9bede3e5..dac4fcf0438 100644 --- a/sched/pthread/pthread_mutexconsistent.c +++ b/sched/pthread/pthread_mutexconsistent.c @@ -104,13 +104,14 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex) DEBUGASSERT(mutex->pid != 0); /* < 0: available, >0 owned, ==0 error */ if (mutex->pid >= 0) { - /* No.. Verify that the PID still exists. We may be destroying - * the mutex after cancelling a pthread and the mutex may have - * been in a bad state owned by the dead pthread. NOTE: The - * folling is unspecified behavior (see pthread_mutex_consistent()). + /* No.. Verify that the thread associated with the PID still + * exists. We may be destroying the mutex after cancelling a + * pthread and the mutex may have been in a bad state owned by + * the dead pthread. NOTE: The following is unspecified behavior + * (see pthread_mutex_consistent()). * * If the holding thread is still valid, then we should be able to - * map its PID to the underlying TCB. That is what sched_gettcb() + * map its PID to the underlying TCB. That is what sched_gettcb() * does. */ @@ -130,6 +131,21 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex) status = sem_reset((FAR sem_t *)&mutex->sem, 1); ret = (status != OK) ? get_errno() : OK; } + + /* Otherwise the mutex is held by some active thread. Let's not + * touch anything! + */ + } + else + { + /* There is no holder of the mutex. Just make sure the + * inconsistent flag is cleared and the number of locks is zero. + */ + + mutex->flags &= _PTHREAD_MFLAGS_ROBUST; +#ifdef CONFIG_PTHREAD_MUTEX_TYPES + mutex->nlocks = 0; +#endif } sched_unlock(); diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index 1f8dc4e8c38..71255f0d604 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -185,65 +185,78 @@ static int lo_txpoll(FAR struct net_driver_s *dev) /* Find the tail of the IOB queue */ for (tail = NULL, iob = head; - iob != NULL; - tail = iob, iob = iob->io_flink); + iob != NULL; + tail = iob, iob = iob->io_flink); /* Loop while there frames to be sent, i.e., while the IOB list is not * emtpy. Sending, of course, just means relaying back through the network * for this driver. */ - while (!FRAME_IOB_EMPTY(&priv->lo_ieee)) + while (head != NULL) { - /* Remove the IOB from the queue */ + /* Increment statistics */ - FRAME_IOB_REMOVE(&priv->lo_ieee, iob); + NETDEV_RXPACKETS(&priv->lo_ieee.i_dev); - /* Is the queue now empty? */ + /* Remove the IOB from the queue */ - if (FRAME_IOB_EMPTY(&priv->lo_ieee)) - { - tail = NULL; - } + iob = head; + head = iob->io_flink; + iob->io_flink = NULL; - /* Return the next frame to the network */ + /* Is the queue now empty? */ - iob->io_flink = NULL; - priv->lo_ieee.i_framelist = iob; + if (head == NULL) + { + tail = NULL; + } - ninfo("Send frame %p to the network. Length=%u\n", iob, iob->io_len); - ret = sixlowpan_input(&priv->lo_ieee); - if (ret < 0) - { - nerr("ERROR: sixlowpan_input returned %d\n", ret); - } + /* Return the next frame to the network */ - /* What if the network responds with more frames to send? */ + iob->io_flink = NULL; + priv->lo_ieee.i_framelist = iob; - if (priv->lo_ieee.i_framelist != NULL) - { - /* Append the new list to the tail of the queue */ + ninfo("Send frame %p to the network. Length=%u\n", iob, iob->io_len); + ret = sixlowpan_input(&priv->lo_ieee); - iob = priv->lo_ieee.i_framelist; - priv->lo_ieee.i_framelist = NULL; + /* Increment statistics */ - if (tail == NULL) - { - head = iob; - } - else - { - tail->io_flink = iob; - } + NETDEV_TXPACKETS(&priv->lo_ieee.i_dev); - /* Find the new tail of the IOB queue */ + if (ret < 0) + { + nerr("ERROR: sixlowpan_input returned %d\n", ret); + NETDEV_TXERRORS(&priv->lo_ieee.i_dev); + NETDEV_ERRORS(&priv->lo_ieee.i_dev); + } - for (tail = iob, iob = iob->io_flink; - iob != NULL; - tail = iob, iob = iob->io_flink); - } + /* What if the network responds with more frames to send? */ - priv->lo_txdone = true; + if (priv->lo_ieee.i_framelist != NULL) + { + /* Append the new list to the tail of the queue */ + + iob = priv->lo_ieee.i_framelist; + priv->lo_ieee.i_framelist = NULL; + + if (tail == NULL) + { + head = iob; + } + else + { + tail->io_flink = iob; + } + + /* Find the new tail of the IOB queue */ + + for (tail = iob, iob = iob->io_flink; + iob != NULL; + tail = iob, iob = iob->io_flink); + } + + priv->lo_txdone = true; } return 0; @@ -350,17 +363,17 @@ static int lo_ifup(FAR struct net_driver_s *dev) dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[5], dev->d_ipv6addr[6], dev->d_ipv6addr[7]); -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - ninfo(" Node: %02x:%02x PANID=%04x\n", - priv->lo_ieee.i_nodeaddr.u8[0], priv->lo_ieee.i_nodeaddr.u8[1], - priv->lo_ieee.i_panid); -#else /* CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 */ +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED ninfo(" Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x PANID=%04x\n", priv->lo_ieee.i_nodeaddr.u8[0], priv->lo_ieee.i_nodeaddr.u8[1], priv->lo_ieee.i_nodeaddr.u8[2], priv->lo_ieee.i_nodeaddr.u8[3], priv->lo_ieee.i_nodeaddr.u8[4], priv->lo_ieee.i_nodeaddr.u8[5], priv->lo_ieee.i_nodeaddr.u8[6], priv->lo_ieee.i_nodeaddr.u8[7], priv->lo_ieee.i_panid); +#else + ninfo(" Node: %02x:%02x PANID=%04x\n", + priv->lo_ieee.i_nodeaddr.u8[0], priv->lo_ieee.i_nodeaddr.u8[1], + priv->lo_ieee.i_panid); #endif /* Set and activate a timer process */ @@ -506,12 +519,12 @@ static int lo_txavail(FAR struct net_driver_s *dev) #if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) static int lo_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) { -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - ninfo("MAC: %02x:%02x\n", - mac[0], mac[1]); -#else /* CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 */ +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED ninfo("MAC: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], mac[6], mac[7]); +#else + ninfo("MAC: %02x:%02x\n", + mac[0], mac[1]); #endif /* There is no multicast support in the loopback driver */ @@ -541,12 +554,12 @@ static int lo_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) #ifdef CONFIG_NET_IGMP static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) { -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - ninfo("MAC: %02x:%02x\n", - mac[0], mac[1]); -#else /* CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 */ +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED ninfo("MAC: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], mac[6], mac[7]); +#else + ninfo("MAC: %02x:%02x\n", + mac[0], mac[1]); #endif /* There is no multicast support in the loopback driver */ @@ -590,7 +603,7 @@ int ieee8021514_loopback(void) memset(priv, 0, sizeof(struct lo_driver_s)); - dev = &priv->lo_ieee.i_dev; + dev = &priv->lo_ieee.i_dev; dev->d_ifup = lo_ifup; /* I/F up (new IP address) callback */ dev->d_ifdown = lo_ifdown; /* I/F down callback */ dev->d_txavail = lo_txavail; /* New TX data callback */