net/ng_pktdump: manage stack internally

This commit is contained in:
Hauke Petersen 2015-03-25 23:50:46 +01:00
parent 96efe23027
commit 4ccc3634b3
2 changed files with 47 additions and 12 deletions

View File

@ -35,19 +35,35 @@ extern "C" {
#define NG_PKTDUMP_MSG_QUEUE_SIZE (8U) #define NG_PKTDUMP_MSG_QUEUE_SIZE (8U)
#endif #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
* @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 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) {
@ -117,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;
} }