1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +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:
Martine Lenders 2015-03-30 02:43:43 +02:00
commit 476dd297bd
4 changed files with 67 additions and 19 deletions

View File

@ -86,6 +86,10 @@
#include "l2_ping.h" #include "l2_ping.h"
#endif #endif
#ifdef MODULE_NG_PKTDUMP
#include "net/ng_pktdump.h"
#endif
#define ENABLE_DEBUG (0) #define ENABLE_DEBUG (0)
#include "debug.h" #include "debug.h"
@ -272,4 +276,8 @@ void auto_init(void)
DEBUG("Auto init transport layer module: [tcp].\n"); DEBUG("Auto init transport layer module: [tcp].\n");
tcp_init_transport_layer(); tcp_init_transport_layer();
#endif #endif
#ifdef MODULE_NG_PKTDUMP
DEBUG("Auto init ng_pktdump module.\n");
ng_pktdump_init();
#endif
} }

View File

@ -28,19 +28,42 @@
extern "C" { extern "C" {
#endif #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 * @brief Start the packet dump thread and listening for incoming packets
* *
* @param[in] stack stack for the packet dump thread * @return PID of the pktdump thread
* @param[in] stacksize size of @p stack * @return negative value on error
* @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
*/ */
kernel_pid_t ng_pktdump_init(char *stack, int stacksize, kernel_pid_t ng_pktdump_init(void);
char priority, char *name);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -22,9 +22,20 @@
#include "thread.h" #include "thread.h"
#include "msg.h" #include "msg.h"
#include "kernel.h"
#include "net/ng_pktdump.h" #include "net/ng_pktdump.h"
#include "net/ng_netbase.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) void _dump_type(ng_nettype_t type)
{ {
switch (type) { switch (type) {
@ -90,6 +101,10 @@ void *_eventloop(void *arg)
{ {
(void)arg; (void)arg;
msg_t msg; 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) { while (1) {
msg_receive(&msg); msg_receive(&msg);
@ -113,8 +128,16 @@ void *_eventloop(void *arg)
return NULL; return NULL;
} }
kernel_pid_t ng_pktdump_init(char *stack, int stacksize, kernel_pid_t ng_pktdump_getpid(void)
char priority, char *name)
{ {
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;
} }

View File

@ -55,11 +55,6 @@ static xbee_t dev;
*/ */
static char nomac_stack[KERNEL_CONF_STACKSIZE_DEFAULT]; 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 * @brief Read chars from STDIO
*/ */
@ -93,8 +88,7 @@ int main(void)
ng_netif_init(); ng_netif_init();
/* initialize and register pktdump */ /* initialize and register pktdump */
dump.pid = ng_pktdump_init(dump_stack, sizeof(dump_stack), PRIORITY_MAIN - 2, dump.pid = ng_pktdump_getpid();
"dump");
if (dump.pid <= KERNEL_PID_UNDEF) { if (dump.pid <= KERNEL_PID_UNDEF) {
puts("Error starting pktdump thread"); puts("Error starting pktdump thread");
return -1; return -1;