netdev_upperhalf: add polling mode support for tx/rx
support more work modes to support more scenarios Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
parent
bf78bf1db4
commit
ccf60a7bab
@ -38,6 +38,14 @@ config NETDEV_WORK_THREAD
|
||||
|
||||
endchoice # Netdev poll worker
|
||||
|
||||
config NETDEV_WORK_THREAD_POLLING_PERIOD
|
||||
int "Polling period, the units are microseconds"
|
||||
default 0
|
||||
depends on NETDEV_WORK_THREAD
|
||||
---help---
|
||||
Disable the txdone and rxready interrupt and use polling
|
||||
period to receive packets when the value is not 0.
|
||||
|
||||
config NETDEV_WORK_THREAD_PRIORITY
|
||||
int "Priority of work poll thread"
|
||||
default 100
|
||||
|
@ -712,6 +712,27 @@ static void netdev_upper_work(FAR void *arg)
|
||||
net_unlock();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netdev_upper_wait
|
||||
*
|
||||
* Description:
|
||||
* Wait for timeout or signal.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NETDEV_WORK_THREAD
|
||||
static int netdev_upper_wait(FAR sem_t *sem)
|
||||
{
|
||||
#if CONFIG_NETDEV_WORK_THREAD_POLLING_PERIOD > 0
|
||||
int ret =
|
||||
nxsem_tickwait(sem, USEC2TICK(CONFIG_NETDEV_WORK_THREAD_POLLING_PERIOD));
|
||||
|
||||
return ret == -ETIMEDOUT ? OK : ret;
|
||||
#else
|
||||
return nxsem_wait(sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netdev_upper_loop
|
||||
*
|
||||
@ -720,13 +741,13 @@ static void netdev_upper_work(FAR void *arg)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NETDEV_WORK_THREAD
|
||||
static int netdev_upper_loop(int argc, FAR char *argv[])
|
||||
{
|
||||
FAR struct netdev_upperhalf_s *upper =
|
||||
(FAR struct netdev_upperhalf_s *)((uintptr_t)strtoul(argv[1], NULL, 16));
|
||||
|
||||
while (nxsem_wait(&upper->sem) == OK && upper->tid != INVALID_PROCESS_ID)
|
||||
while (netdev_upper_wait(&upper->sem) == OK &&
|
||||
upper->tid != INVALID_PROCESS_ID)
|
||||
{
|
||||
netdev_upper_work(upper);
|
||||
}
|
||||
@ -1315,7 +1336,9 @@ void netdev_lower_carrier_off(FAR struct netdev_lowerhalf_s *dev)
|
||||
|
||||
void netdev_lower_rxready(FAR struct netdev_lowerhalf_s *dev)
|
||||
{
|
||||
#if CONFIG_NETDEV_WORK_THREAD_POLLING_PERIOD == 0
|
||||
netdev_upper_queue_work(&dev->netdev);
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -1332,7 +1355,9 @@ void netdev_lower_rxready(FAR struct netdev_lowerhalf_s *dev)
|
||||
void netdev_lower_txdone(FAR struct netdev_lowerhalf_s *dev)
|
||||
{
|
||||
NETDEV_TXDONE(&dev->netdev);
|
||||
#if CONFIG_NETDEV_WORK_THREAD_POLLING_PERIOD == 0
|
||||
netdev_upper_queue_work(&dev->netdev);
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -47,6 +47,10 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NETDEV_WORK_THREAD_POLLING_PERIOD
|
||||
# define CONFIG_NETDEV_WORK_THREAD_POLLING_PERIOD 0
|
||||
#endif
|
||||
|
||||
/* Layout for net packet:
|
||||
*
|
||||
* | <-------------- NETPKT_BUFLEN ---------------> |
|
||||
|
Loading…
Reference in New Issue
Block a user