net/ng_pktdump: manage stack internally
This commit is contained in:
parent
96efe23027
commit
4ccc3634b3
@ -35,19 +35,35 @@ extern "C" {
|
||||
#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) {
|
||||
@ -117,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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user