Merge pull request #736 from geniusgogo/IDLE_hook

[kernel] Idle hook
This commit is contained in:
Bernard Xiong 2017-05-23 11:08:26 +08:00 committed by GitHub
commit 1730dcb83f
2 changed files with 16 additions and 4 deletions

View File

@ -164,7 +164,7 @@ void rt_thread_inited_sethook (void (*hook)(rt_thread_t thread));
* idle thread interface * idle thread interface
*/ */
void rt_thread_idle_init(void); void rt_thread_idle_init(void);
#ifdef RT_USING_HOOK #if defined(RT_USING_HOOK) || defined(RT_USING_IDLE_HOOK)
void rt_thread_idle_sethook(void (*hook)(void)); void rt_thread_idle_sethook(void (*hook)(void));
#endif #endif
void rt_thread_idle_excute(void); void rt_thread_idle_excute(void);

View File

@ -30,8 +30,14 @@
#include <rthw.h> #include <rthw.h>
#include <rtthread.h> #include <rtthread.h>
#if defined (RT_USING_HOOK)
#ifndef RT_USING_IDLE_HOOK
#define RT_USING_IDLE_HOOK 1
#endif
#endif
#ifndef IDLE_THREAD_STACK_SIZE #ifndef IDLE_THREAD_STACK_SIZE
#if defined (RT_USING_HOOK) || defined(RT_USING_HEAP) #if defined (RT_USING_IDLE_HOOK) || defined(RT_USING_HEAP)
#define IDLE_THREAD_STACK_SIZE 256 #define IDLE_THREAD_STACK_SIZE 256
#else #else
#define IDLE_THREAD_STACK_SIZE 128 #define IDLE_THREAD_STACK_SIZE 128
@ -44,7 +50,7 @@ static rt_uint8_t rt_thread_stack[IDLE_THREAD_STACK_SIZE];
extern rt_list_t rt_thread_defunct; extern rt_list_t rt_thread_defunct;
#ifdef RT_USING_HOOK #ifdef RT_USING_IDLE_HOOK
static void (*rt_thread_idle_hook)(); static void (*rt_thread_idle_hook)();
/** /**
@ -179,7 +185,13 @@ static void rt_thread_idle_entry(void *parameter)
{ {
while (1) while (1)
{ {
RT_OBJECT_HOOK_CALL(rt_thread_idle_hook,()); #ifdef RT_USING_IDLE_HOOK
if (rt_thread_idle_hook != RT_NULL)
{
rt_thread_idle_hook();
}
#endif
rt_thread_idle_excute(); rt_thread_idle_excute();
} }
} }