net/can: replace the common connect prologue
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
parent
8366c87c5b
commit
43ca28da36
@ -33,6 +33,7 @@
|
|||||||
#include <netpacket/can.h>
|
#include <netpacket/can.h>
|
||||||
#include <nuttx/semaphore.h>
|
#include <nuttx/semaphore.h>
|
||||||
#include <nuttx/can.h>
|
#include <nuttx/can.h>
|
||||||
|
#include <nuttx/net/net.h>
|
||||||
#include <nuttx/net/netdev.h>
|
#include <nuttx/net/netdev.h>
|
||||||
|
|
||||||
#include "devif/devif.h"
|
#include "devif/devif.h"
|
||||||
@ -51,9 +52,9 @@
|
|||||||
/* Allocate a new packet socket data callback */
|
/* Allocate a new packet socket data callback */
|
||||||
|
|
||||||
#define can_callback_alloc(dev,conn) \
|
#define can_callback_alloc(dev,conn) \
|
||||||
devif_callback_alloc(dev, &conn->list, &conn->list_tail)
|
devif_callback_alloc(dev, &conn->sconn.list, &conn->sconn.list_tail)
|
||||||
#define can_callback_free(dev,conn,cb) \
|
#define can_callback_free(dev,conn,cb) \
|
||||||
devif_conn_callback_free(dev, cb, &conn->list, &conn->list_tail)
|
devif_conn_callback_free(dev, cb, &conn->sconn.list, &conn->sconn.list_tail)
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Type Definitions
|
* Public Type Definitions
|
||||||
@ -75,15 +76,7 @@ struct can_conn_s
|
|||||||
{
|
{
|
||||||
/* Common prologue of all connection structures. */
|
/* Common prologue of all connection structures. */
|
||||||
|
|
||||||
dq_entry_t node; /* Supports a doubly linked list */
|
struct socket_conn_s sconn;
|
||||||
|
|
||||||
/* This is a list of NetLink connection callbacks. Each callback
|
|
||||||
* represents a thread that is stalled, waiting for a device-specific
|
|
||||||
* event.
|
|
||||||
*/
|
|
||||||
|
|
||||||
FAR struct devif_callback_s *list; /* NetLink callbacks */
|
|
||||||
FAR struct devif_callback_s *list_tail; /* NetLink callbacks */
|
|
||||||
|
|
||||||
FAR struct net_driver_s *dev; /* Reference to CAN device */
|
FAR struct net_driver_s *dev; /* Reference to CAN device */
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ uint16_t can_callback(FAR struct net_driver_s *dev,
|
|||||||
|
|
||||||
if (net_trylock() == OK)
|
if (net_trylock() == OK)
|
||||||
{
|
{
|
||||||
flags = devif_conn_event(dev, conn, flags, conn->list);
|
flags = devif_conn_event(dev, conn, flags, conn->sconn.list);
|
||||||
net_unlock();
|
net_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ void can_initialize(void)
|
|||||||
{
|
{
|
||||||
/* Mark the connection closed and move it to the free list */
|
/* Mark the connection closed and move it to the free list */
|
||||||
|
|
||||||
dq_addlast(&g_can_connections[i].node, &g_free_can_connections);
|
dq_addlast(&g_can_connections[i].sconn.node, &g_free_can_connections);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ FAR struct can_conn_s *can_alloc(void)
|
|||||||
{
|
{
|
||||||
for (i = 0; i < CONFIG_CAN_CONNS; i++)
|
for (i = 0; i < CONFIG_CAN_CONNS; i++)
|
||||||
{
|
{
|
||||||
dq_addlast(&conn[i].node, &g_free_can_connections);
|
dq_addlast(&conn[i].sconn.node, &g_free_can_connections);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -175,7 +175,7 @@ FAR struct can_conn_s *can_alloc(void)
|
|||||||
|
|
||||||
/* Enqueue the connection into the active list */
|
/* Enqueue the connection into the active list */
|
||||||
|
|
||||||
dq_addlast(&conn->node, &g_active_can_connections);
|
dq_addlast(&conn->sconn.node, &g_active_can_connections);
|
||||||
}
|
}
|
||||||
|
|
||||||
_can_semgive(&g_free_sem);
|
_can_semgive(&g_free_sem);
|
||||||
@ -201,7 +201,7 @@ void can_free(FAR struct can_conn_s *conn)
|
|||||||
|
|
||||||
/* Remove the connection from the active list */
|
/* Remove the connection from the active list */
|
||||||
|
|
||||||
dq_rem(&conn->node, &g_active_can_connections);
|
dq_rem(&conn->sconn.node, &g_active_can_connections);
|
||||||
|
|
||||||
/* Reset structure */
|
/* Reset structure */
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ void can_free(FAR struct can_conn_s *conn)
|
|||||||
|
|
||||||
/* Free the connection */
|
/* Free the connection */
|
||||||
|
|
||||||
dq_addlast(&conn->node, &g_free_can_connections);
|
dq_addlast(&conn->sconn.node, &g_free_can_connections);
|
||||||
_can_semgive(&g_free_sem);
|
_can_semgive(&g_free_sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ FAR struct can_conn_s *can_nextconn(FAR struct can_conn_s *conn)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return (FAR struct can_conn_s *)conn->node.flink;
|
return (FAR struct can_conn_s *)conn->sconn.node.flink;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user