mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #2719 from haukepetersen/ng_opt_pktdump
net/ng_pktdump: manage stack internal and use msg queue
This commit is contained in:
commit
476dd297bd
@ -86,6 +86,10 @@
|
||||
#include "l2_ping.h"
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_NG_PKTDUMP
|
||||
#include "net/ng_pktdump.h"
|
||||
#endif
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
@ -272,4 +276,8 @@ void auto_init(void)
|
||||
DEBUG("Auto init transport layer module: [tcp].\n");
|
||||
tcp_init_transport_layer();
|
||||
#endif
|
||||
#ifdef MODULE_NG_PKTDUMP
|
||||
DEBUG("Auto init ng_pktdump module.\n");
|
||||
ng_pktdump_init();
|
||||
#endif
|
||||
}
|
||||
|
@ -28,19 +28,42 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Message queue size for the pktdump thread
|
||||
*/
|
||||
#ifndef NG_PKTDUMP_MSG_QUEUE_SIZE
|
||||
#define NG_PKTDUMP_MSG_QUEUE_SIZE (8U)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Priority of the pktdump thread
|
||||
*/
|
||||
#ifndef NG_PKTDUMP_PRIO
|
||||
#define NG_PKTDUMP_PRIO (PRIORITY_MIN - 1)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Stack size used for the pktdump thread
|
||||
*/
|
||||
#ifndef NG_PKTDUMP_STACKSIZE
|
||||
#define NG_PKTDUMP_STACKSIZE (KERNEL_CONF_STACKSIZE_MAIN)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Get the PID of the pktdump thread
|
||||
*
|
||||
* @return PID of the pktdump thread
|
||||
* @return @ref KERNEL_PID_UNDEF if not initialized
|
||||
*/
|
||||
kernel_pid_t ng_pktdump_getpid(void);
|
||||
|
||||
/**
|
||||
* @brief Start the packet dump thread and listening for incoming packets
|
||||
*
|
||||
* @param[in] stack stack for the packet dump thread
|
||||
* @param[in] stacksize size of @p stack
|
||||
* @param[in] priority priority of the packet dump thread
|
||||
* @param[in] name name for the packet dump thread
|
||||
*
|
||||
* @return PID of newly created task on success
|
||||
* @return negative value on error
|
||||
* @return PID of the pktdump thread
|
||||
* @return negative value on error
|
||||
*/
|
||||
kernel_pid_t ng_pktdump_init(char *stack, int stacksize,
|
||||
char priority, char *name);
|
||||
kernel_pid_t ng_pktdump_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -22,9 +22,20 @@
|
||||
|
||||
#include "thread.h"
|
||||
#include "msg.h"
|
||||
#include "kernel.h"
|
||||
#include "net/ng_pktdump.h"
|
||||
#include "net/ng_netbase.h"
|
||||
|
||||
/**
|
||||
* @brief PID of the pktdump thread
|
||||
*/
|
||||
static kernel_pid_t _pid = KERNEL_PID_UNDEF;
|
||||
|
||||
/**
|
||||
* @brief Stack for the pktdump thread
|
||||
*/
|
||||
static char _stack[NG_PKTDUMP_STACKSIZE];
|
||||
|
||||
void _dump_type(ng_nettype_t type)
|
||||
{
|
||||
switch (type) {
|
||||
@ -90,6 +101,10 @@ void *_eventloop(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
msg_t msg;
|
||||
msg_t msg_queue[NG_PKTDUMP_MSG_QUEUE_SIZE];
|
||||
|
||||
/* setup the message queue */
|
||||
msg_init_queue(msg_queue, NG_PKTDUMP_MSG_QUEUE_SIZE);
|
||||
|
||||
while (1) {
|
||||
msg_receive(&msg);
|
||||
@ -113,8 +128,16 @@ void *_eventloop(void *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
kernel_pid_t ng_pktdump_init(char *stack, int stacksize,
|
||||
char priority, char *name)
|
||||
kernel_pid_t ng_pktdump_getpid(void)
|
||||
{
|
||||
return thread_create(stack, stacksize, priority, 0, _eventloop, NULL, name);
|
||||
return _pid;
|
||||
}
|
||||
|
||||
kernel_pid_t ng_pktdump_init(void)
|
||||
{
|
||||
if (_pid == KERNEL_PID_UNDEF) {
|
||||
_pid = thread_create(_stack, sizeof(_stack), NG_PKTDUMP_PRIO,
|
||||
0, _eventloop, NULL, "pktdump");
|
||||
}
|
||||
return _pid;
|
||||
}
|
||||
|
@ -55,11 +55,6 @@ static xbee_t dev;
|
||||
*/
|
||||
static char nomac_stack[KERNEL_CONF_STACKSIZE_DEFAULT];
|
||||
|
||||
/**
|
||||
* @brief Stack for the pktdump thread
|
||||
*/
|
||||
static char dump_stack[KERNEL_CONF_STACKSIZE_MAIN];
|
||||
|
||||
/**
|
||||
* @brief Read chars from STDIO
|
||||
*/
|
||||
@ -93,8 +88,7 @@ int main(void)
|
||||
ng_netif_init();
|
||||
|
||||
/* initialize and register pktdump */
|
||||
dump.pid = ng_pktdump_init(dump_stack, sizeof(dump_stack), PRIORITY_MAIN - 2,
|
||||
"dump");
|
||||
dump.pid = ng_pktdump_getpid();
|
||||
if (dump.pid <= KERNEL_PID_UNDEF) {
|
||||
puts("Error starting pktdump thread");
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user