Merge remote-tracking branch 'origin/master' into ieee802154

This commit is contained in:
Gregory Nutt 2017-04-28 12:32:59 -06:00
commit 22615d0d6d
6 changed files with 114 additions and 71 deletions

View File

@ -149,8 +149,8 @@
/* STM32L496xx/4A6xx only: */ /* STM32L496xx/4A6xx only: */
#define STM32L4_IRQ_HASH_CRS (STM32L4_IRQ_FIRST+82) /* 82: HASH and CRS global interrupt */ #define STM32L4_IRQ_HASH_CRS (STM32L4_IRQ_FIRST+82) /* 82: HASH and CRS global interrupt */
#define STM32L4_IRQ_I2C4_EV (STM32L4_IRQ_FIRST+83) /* 83: I2C4 event interrupt */ #define STM32L4_IRQ_I2C4EV (STM32L4_IRQ_FIRST+83) /* 83: I2C4 event interrupt */
#define STM32L4_IRQ_I2C4_ER (STM32L4_IRQ_FIRST+84) /* 84: I2C4 error interrupt */ #define STM32L4_IRQ_I2C4ER (STM32L4_IRQ_FIRST+84) /* 84: I2C4 error interrupt */
#define STM32L4_IRQ_DCMI (STM32L4_IRQ_FIRST+85) /* 85: DCMI global interrupt */ #define STM32L4_IRQ_DCMI (STM32L4_IRQ_FIRST+85) /* 85: DCMI global interrupt */
#define STM32L4_IRQ_CAN2TX (STM32L4_IRQ_FIRST+86) /* 86: CAN2 TX interrupts */ #define STM32L4_IRQ_CAN2TX (STM32L4_IRQ_FIRST+86) /* 86: CAN2 TX interrupts */
#define STM32L4_IRQ_CAN2RX0 (STM32L4_IRQ_FIRST+87) /* 87: CAN2 RX0 interrupts */ #define STM32L4_IRQ_CAN2RX0 (STM32L4_IRQ_FIRST+87) /* 87: CAN2 RX0 interrupts */

View File

@ -26,7 +26,7 @@ SRAM2 : OK; can be included in MM region or left separate for special app
: purposes : purposes
FIREWALL : Code written, to be tested, requires support from ldscript FIREWALL : Code written, to be tested, requires support from ldscript
SPI : OK, tested (Including DMA) SPI : OK, tested (Including DMA)
I2C : Code written, to be tested (I2C4 missing) I2C : Code written, to be tested
RTC : works RTC : works
QSPI : works in polling, interrupt, DMA, and also memory-mapped modes QSPI : works in polling, interrupt, DMA, and also memory-mapped modes
CAN : OK, tested CAN : OK, tested
@ -57,7 +57,7 @@ SWP : TODO (Single wire protocol master, to connect with NFC enabled
LPUART : TODO (Low power UART working with LSE at low baud rates) LPUART : TODO (Low power UART working with LSE at low baud rates)
LPTIMER : TODO (Low power TIMER) LPTIMER : TODO (Low power TIMER)
OPAMP : TODO (Analog operational amplifier) OPAMP : TODO (Analog operational amplifier)
COMP : TODO (Analog comparators) COMP : There is some code (Analog comparators)
DFSDM : TODO (Digital Filter and Sigma-Delta Modulator) DFSDM : TODO (Digital Filter and Sigma-Delta Modulator)
LCD : TODO (Segment LCD controller) LCD : TODO (Segment LCD controller)
SAIPLL : works (PLL For Digital Audio interfaces, and other things) SAIPLL : works (PLL For Digital Audio interfaces, and other things)

View File

@ -96,7 +96,8 @@
/* At least one I2C peripheral must be enabled */ /* At least one I2C peripheral must be enabled */
#if defined(CONFIG_STM32L4_I2C1) || defined(CONFIG_STM32L4_I2C2) || defined(CONFIG_STM32L4_I2C3) #if defined(CONFIG_STM32L4_I2C1) || defined(CONFIG_STM32L4_I2C2) || \
defined(CONFIG_STM32L4_I2C3) || defined(CONFIG_STM32L4_I2C4)
/************************************************************************************ /************************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
@ -214,7 +215,6 @@ struct stm32l4_i2c_config_s
uint32_t scl_pin; /* GPIO configuration for SCL as SCL */ uint32_t scl_pin; /* GPIO configuration for SCL as SCL */
uint32_t sda_pin; /* GPIO configuration for SDA as SDA */ uint32_t sda_pin; /* GPIO configuration for SDA as SDA */
#ifndef CONFIG_I2C_POLLED #ifndef CONFIG_I2C_POLLED
int (*isr)(int, void *, void *); /* Interrupt handler */
uint32_t ev_irq; /* Event IRQ */ uint32_t ev_irq; /* Event IRQ */
uint32_t er_irq; /* Error IRQ */ uint32_t er_irq; /* Error IRQ */
#endif #endif
@ -289,17 +289,9 @@ static inline void stm32l4_i2c_sendstart(FAR struct stm32l4_i2c_priv_s *priv);
static inline void stm32l4_i2c_clrstart(FAR struct stm32l4_i2c_priv_s *priv); static inline void stm32l4_i2c_clrstart(FAR struct stm32l4_i2c_priv_s *priv);
static inline void stm32l4_i2c_sendstop(FAR struct stm32l4_i2c_priv_s *priv); static inline void stm32l4_i2c_sendstop(FAR struct stm32l4_i2c_priv_s *priv);
static inline uint32_t stm32l4_i2c_getstatus(FAR struct stm32l4_i2c_priv_s *priv); static inline uint32_t stm32l4_i2c_getstatus(FAR struct stm32l4_i2c_priv_s *priv);
static int stm32l4_i2c_isr(struct stm32l4_i2c_priv_s * priv); static int stm32l4_i2c_isr_process(struct stm32l4_i2c_priv_s *priv);
#ifndef CONFIG_I2C_POLLED #ifndef CONFIG_I2C_POLLED
#ifdef CONFIG_STM32L4_I2C1 static int stm32l4_i2c_isr(int irq, void *context, FAR void *arg);
static int stm32l4_i2c1_isr(int irq, void *context, FAR void *arg);
#endif
#ifdef CONFIG_STM32L4_I2C2
static int stm32l4_i2c2_isr(int irq, void *context, FAR void *arg);
#endif
#ifdef CONFIG_STM32L4_I2C3
static int stm32l4_i2c3_isr(int irq, void *context, FAR void *arg);
#endif
#endif #endif
static int stm32l4_i2c_init(FAR struct stm32l4_i2c_priv_s *priv); static int stm32l4_i2c_init(FAR struct stm32l4_i2c_priv_s *priv);
static int stm32l4_i2c_deinit(FAR struct stm32l4_i2c_priv_s *priv); static int stm32l4_i2c_deinit(FAR struct stm32l4_i2c_priv_s *priv);
@ -332,7 +324,6 @@ static const struct stm32l4_i2c_config_s stm32l4_i2c1_config =
.scl_pin = GPIO_I2C1_SCL, .scl_pin = GPIO_I2C1_SCL,
.sda_pin = GPIO_I2C1_SDA, .sda_pin = GPIO_I2C1_SDA,
#ifndef CONFIG_I2C_POLLED #ifndef CONFIG_I2C_POLLED
.isr = stm32l4_i2c1_isr,
.ev_irq = STM32L4_IRQ_I2C1EV, .ev_irq = STM32L4_IRQ_I2C1EV,
.er_irq = STM32L4_IRQ_I2C1ER .er_irq = STM32L4_IRQ_I2C1ER
#endif #endif
@ -362,7 +353,6 @@ static const struct stm32l4_i2c_config_s stm32l4_i2c2_config =
.scl_pin = GPIO_I2C2_SCL, .scl_pin = GPIO_I2C2_SCL,
.sda_pin = GPIO_I2C2_SDA, .sda_pin = GPIO_I2C2_SDA,
#ifndef CONFIG_I2C_POLLED #ifndef CONFIG_I2C_POLLED
.isr = stm32l4_i2c2_isr,
.ev_irq = STM32L4_IRQ_I2C2EV, .ev_irq = STM32L4_IRQ_I2C2EV,
.er_irq = STM32L4_IRQ_I2C2ER .er_irq = STM32L4_IRQ_I2C2ER
#endif #endif
@ -392,7 +382,6 @@ static const struct stm32l4_i2c_config_s stm32l4_i2c3_config =
.scl_pin = GPIO_I2C3_SCL, .scl_pin = GPIO_I2C3_SCL,
.sda_pin = GPIO_I2C3_SDA, .sda_pin = GPIO_I2C3_SDA,
#ifndef CONFIG_I2C_POLLED #ifndef CONFIG_I2C_POLLED
.isr = stm32l4_i2c3_isr,
.ev_irq = STM32L4_IRQ_I2C3EV, .ev_irq = STM32L4_IRQ_I2C3EV,
.er_irq = STM32L4_IRQ_I2C3ER .er_irq = STM32L4_IRQ_I2C3ER
#endif #endif
@ -413,6 +402,35 @@ struct stm32l4_i2c_priv_s stm32l4_i2c3_priv =
}; };
#endif #endif
#ifdef CONFIG_STM32L4_I2C4
static const struct stm32l4_i2c_config_s stm32l4_i2c4_config =
{
.base = STM32L4_I2C4_BASE,
.clk_bit = RCC_APB1ENR2_I2C4EN,
.reset_bit = RCC_APB1RSTR2_I2C4RST,
.scl_pin = GPIO_I2C4_SCL,
.sda_pin = GPIO_I2C4_SDA,
#ifndef CONFIG_I2C_POLLED
.ev_irq = STM32L4_IRQ_I2C4EV,
.er_irq = STM32L4_IRQ_I2C4ER
#endif
};
struct stm32l4_i2c_priv_s stm32l4_i2c4_priv =
{
.ops = &stm32l4_i2c_ops,
.config = &stm32l4_i2c4_config,
.refs = 0,
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
.ptr = NULL,
.dcnt = 0,
.flags = 0,
.status = 0
};
#endif
/************************************************************************************ /************************************************************************************
* Private Functions * Private Functions
************************************************************************************/ ************************************************************************************/
@ -656,7 +674,7 @@ static inline int stm32l4_i2c_sem_waitdone(FAR struct stm32l4_i2c_priv_s *priv)
* reports that it is done. * reports that it is done.
*/ */
stm32l4_i2c_isr(priv); stm32l4_i2c_isr_process(priv);
} }
/* Loop until the transfer is complete. */ /* Loop until the transfer is complete. */
@ -1265,7 +1283,7 @@ static inline uint32_t stm32l4_i2c_getstatus(FAR struct stm32l4_i2c_priv_s *priv
} }
/************************************************************************************ /************************************************************************************
* Name: stm32l4_i2c_isr * Name: stm32l4_i2c_isr_startmessage
* *
* Description: * Description:
* Common logic when a message is started. Just adds the even to the trace buffer * Common logic when a message is started. Just adds the even to the trace buffer
@ -1298,14 +1316,14 @@ static inline void stm32l4_i2c_clearinterrupts(struct stm32l4_i2c_priv_s *priv)
} }
/************************************************************************************ /************************************************************************************
* Name: stm32l4_i2c_isr * Name: stm32l4_i2c_isr_process
* *
* Description: * Description:
* Common Interrupt Service Routine * I2C processing logic common to polled and non-polled operation.
* *
************************************************************************************/ ************************************************************************************/
static int stm32l4_i2c_isr(struct stm32l4_i2c_priv_s *priv) static int stm32l4_i2c_isr_process(struct stm32l4_i2c_priv_s *priv)
{ {
uint32_t status = stm32l4_i2c_getstatus(priv); uint32_t status = stm32l4_i2c_getstatus(priv);
@ -1507,56 +1525,23 @@ static int stm32l4_i2c_isr(struct stm32l4_i2c_priv_s *priv)
} }
/************************************************************************************ /************************************************************************************
* Name: stm32l4_i2c1_isr * Name: stm32l4_i2c_isr
* *
* Description: * Description:
* I2C1 interrupt service routine * I2C interrupt service routine
*
************************************************************************************/
#ifndef CONFIG_I2C_POLLED
#ifdef CONFIG_STM32L4_I2C1
static int stm32l4_i2c1_isr(int irq, void *context, FAR void *arg)
{
return stm32l4_i2c_isr(&stm32l4_i2c1_priv);
}
#endif
/************************************************************************************
* Name: stm32l4_i2c2_isr
*
* Description:
* I2C2 interrupt service routine
* *
************************************************************************************/ ************************************************************************************/
#ifdef CONFIG_STM32L4_I2C2 #ifdef CONFIG_STM32L4_I2C2
static int stm32l4_i2c2_isr(int irq, void *context, FAR void *arg) static int stm32l4_i2c_isr(int irq, void *context, FAR void *arg)
{ {
return stm32l4_i2c_isr(&stm32l4_i2c2_priv); struct stm32l4_i2c_priv_s *priv = (struct stm32l4_i2c_priv_s *priv)arg;
DEBUGASSERT(priv != NULL);
return stm32l4_i2c_isr_process(priv);
} }
#endif #endif
/************************************************************************************
* Name: stm32l4_i2c3_isr
*
* Description:
* I2C2 interrupt service routine
*
************************************************************************************/
#ifdef CONFIG_STM32L4_I2C3
static int stm32l4_i2c3_isr(int irq, void *context, FAR void *arg)
{
return stm32l4_i2c_isr(&stm32l4_i2c3_priv);
}
#endif
#endif
/************************************************************************************
* Private Initialization and Deinitialization
************************************************************************************/
/************************************************************************************ /************************************************************************************
* Name: stm32l4_i2c_init * Name: stm32l4_i2c_init
* *
@ -1591,8 +1576,8 @@ static int stm32l4_i2c_init(FAR struct stm32l4_i2c_priv_s *priv)
/* Attach ISRs */ /* Attach ISRs */
#ifndef CONFIG_I2C_POLLED #ifndef CONFIG_I2C_POLLED
irq_attach(priv->config->ev_irq, priv->config->isr, NULL); irq_attach(priv->config->ev_irq, stm32l4_i2c_isr, priv);
irq_attach(priv->config->er_irq, priv->config->isr, NULL); irq_attach(priv->config->er_irq, stm32l4_i2c_isr, priv);
up_enable_irq(priv->config->ev_irq); up_enable_irq(priv->config->ev_irq);
up_enable_irq(priv->config->er_irq); up_enable_irq(priv->config->er_irq);
#endif #endif
@ -2009,6 +1994,11 @@ FAR struct i2c_master_s *stm32l4_i2cbus_initialize(int port)
case 3: case 3:
priv = (struct stm32l4_i2c_priv_s *)&stm32l4_i2c3_priv; priv = (struct stm32l4_i2c_priv_s *)&stm32l4_i2c3_priv;
break; break;
#endif
#ifdef CONFIG_STM32L4_I2C4
case 4:
priv = (struct stm32l4_i2c_priv_s *)&stm32l4_i2c4_priv;
break;
#endif #endif
default: default:
return NULL; return NULL;
@ -2072,5 +2062,5 @@ int stm32l4_i2cbus_uninitialize(FAR struct i2c_master_s * dev)
return OK; return OK;
} }
#endif /* CONFIG_STM32L4_I2C1 || CONFIG_STM32L4_I2C2 || CONFIG_STM32L4_I2C3 */ #endif /* CONFIG_STM32L4_I2C1 || CONFIG_STM32L4_I2C2 || CONFIG_STM32L4_I2C3 || CONFIG_STM32L4_I2C4 */

View File

@ -388,6 +388,25 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
} }
else if (timeout > 0) else if (timeout > 0)
{ {
systime_t ticks;
/* "Implementations may place limitations on the granularity of
* timeout intervals. If the requested timeout interval requires
* a finer granularity than the implementation supports, the
* actual timeout interval will be rounded up to the next
* supported value." -- opengroup.org
*
* Round timeout up to next full tick.
*/
#if (MSEC_PER_TICK * USEC_PER_MSEC) != USEC_PER_TICK && \
defined(CONFIG_HAVE_LONG_LONG)
ticks = ((unsigned long long)timeout * USEC_PER_MSEC) + (USEC_PER_TICK - 1) /
USEC_PER_TICK;
#else
ticks = ((unsigned int)timeout + (MSEC_PER_TICK - 1)) / MSEC_PER_TICK;
#endif
/* Either wait for either a poll event(s), for a signal to occur, /* Either wait for either a poll event(s), for a signal to occur,
* or for the specified timeout to elapse with no event. * or for the specified timeout to elapse with no event.
* *
@ -396,7 +415,7 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
* immediately. * immediately.
*/ */
ret = sem_tickwait(&sem, clock_systimer(), MSEC2TICK(timeout)); ret = sem_tickwait(&sem, clock_systimer(), ticks);
if (ret < 0) if (ret < 0)
{ {
if (ret == -ETIMEDOUT) if (ret == -ETIMEDOUT)

View File

@ -45,11 +45,25 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <nuttx/fs/ioctl.h> #include <nuttx/fs/ioctl.h>
/* Include network ioctls info */ #if CONFIG_NSOCKET_DESCRIPTORS > 0
#ifdef CONFIG_NET
/* Include network IOCTL definitions */
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 # include <nuttx/net/ioctl.h>
# include <nuttx/net/ioctl.h>
#ifdef CONFIG_NETDEV_WIRELESS_IOCTL
/* Include wireless network IOCTL definitions */
# include <nuttx/wireless/wireless.h>
#endif #endif
#endif /* CONFIG_NET */
#ifdef CONFIG_DRIVERS_WIRELESS
/* Include wireless character driver IOCTL definitions */
# include <nuttx/wireless/ioctl.h>
#endif
#endif /* CONFIG_NSOCKET_DESCRIPTORS > 0 */
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions

View File

@ -50,6 +50,8 @@
#include "tcp/tcp.h" #include "tcp/tcp.h"
#include "udp/udp.h" #include "udp/udp.h"
#include "pkt/pkt.h"
#include "local/local.h"
#include "socket/socket.h" #include "socket/socket.h"
#include "usrsock/usrsock.h" #include "usrsock/usrsock.h"
@ -97,6 +99,24 @@ int net_clone(FAR struct socket *psock1, FAR struct socket *psock2)
DEBUGASSERT(psock2->s_conn); DEBUGASSERT(psock2->s_conn);
psock2->s_crefs = 1; /* One reference on the new socket itself */ psock2->s_crefs = 1; /* One reference on the new socket itself */
#ifdef CONFIG_NET_LOCAL
if (psock2->s_domain == PF_LOCAL)
{
FAR struct local_conn_s *conn = psock2->s_conn;
DEBUGASSERT(conn->lc_crefs > 0 && conn->lc_crefs < 255);
conn->lc_crefs++;
}
else
#endif
#ifdef CONFIG_NET_PKT
if (psock2->s_type == SOCK_RAW)
{
FAR struct pkt_conn_s *conn = psock2->s_conn;
DEBUGASSERT(conn->crefs > 0 && conn->crefs < 255);
conn->crefs++;
}
else
#endif
#ifdef NET_TCP_HAVE_STACK #ifdef NET_TCP_HAVE_STACK
if (psock2->s_type == SOCK_STREAM) if (psock2->s_type == SOCK_STREAM)
{ {