📄 wlan_thread.h
字号:
/*
* File: wlan_thread.h
*/
#ifndef _KTHREAD_H_
#define _KTHREAD_H_
#include "list.h"
#include "tx_api.h"
#include "MfpSystem.h"
#define KTHREAD_TIMESLICE 20
#define KTHREAD_PRIORITY THR_PRI_WIRELESS
#define KTHREAD_STACKSIZE 4096 // REVISIT: tune this value
#define KTHREAD_WAIT_FLAG 0x00000001
#define WLAN_THREAD_STOPPED 0
#define WLAN_THREAD_RUNNING 1
/* A structure to store all information we needfor our thread. */
typedef struct
{
/* private data */
TX_THREAD txThread;
TX_SEMAPHORE startstop_sem;
TX_EVENT_FLAGS_GROUP waitQ;
u32 state;
u32 priv;
u8 threadStack[KTHREAD_STACKSIZE] ALIGN4;
} wlan_thread ALIGN4;
/* Create a new kernel thread. Called by the creator. */
static inline void wlan_create_thread(void (*func)(u32), wlan_thread *thread,
char* name)
{
// create binary semaphore with inital count of 1
tx_semaphore_create(&thread->startstop_sem, name, 1);
// immediately decrement the semaphore; when the thread starts it
// will increment the semaphore after it initializes itself.
// This is done to allow the new thread to run before the
// creating thread continues
tx_semaphore_get(&thread->startstop_sem, TX_WAIT_FOREVER);
// initialize the thread's event flags
tx_event_flags_create(&thread->waitQ, name);
// create and start the thread
tx_thread_create(&thread->txThread, name, func, (u32)thread,
thread->threadStack, KTHREAD_STACKSIZE,
KTHREAD_PRIORITY, KTHREAD_PRIORITY,
KTHREAD_TIMESLICE, TX_AUTO_START);
// wait for it to start and init
tx_semaphore_get(&thread->startstop_sem, TX_WAIT_FOREVER);
}
/* Stop a kernel thread. Called by the removing instance. */
static inline void wlan_terminate_thread(wlan_thread *thread)
{
thread->state = WLAN_THREAD_STOPPED;
// wake the thread in case it's sleeping
tx_event_flags_set(&thread->waitQ, KTHREAD_WAIT_FLAG, TX_OR);
// wait for thread to die; semaphore will be 0 if thread has not
// exited because mrvl_create_thread routines leaves it at 0.
tx_semaphore_get(&thread->startstop_sem, TX_WAIT_FOREVER);
tx_thread_delete(&thread->txThread);
tx_event_flags_delete(&thread->waitQ);
tx_semaphore_delete(&thread->startstop_sem);
}
/* Initialize new created thread. Called by the new thread. */
static inline void wlan_activate_thread(wlan_thread *thread) //init_kthread
{
thread->state = WLAN_THREAD_RUNNING;
tx_semaphore_put(&thread->startstop_sem);
}
/* Cleanup of thread. Called by the exiting thread. */
static inline void wlan_deactivate_thread(wlan_thread *thread) //exit_kthread
{
tx_semaphore_put(&thread->startstop_sem);
}
static inline wlan_thread* get_current_kthread()
{
}
#endif /* _KTHREAD_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -