summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/idle.c18
-rw-r--r--src/irq.c30
-rw-r--r--src/thread.c33
3 files changed, 76 insertions, 5 deletions
diff --git a/src/idle.c b/src/idle.c
index 867af87612..aab09cb913 100644
--- a/src/idle.c
+++ b/src/idle.c
@@ -24,6 +24,7 @@
* 2012-12-29 Bernard fix compiling warning.
* 2013-12-21 Grissiom let rt_thread_idle_excute loop until there is no
* dead thread.
+ * 2016-08-09 ArdaFu add method to get the handler of the idle thread.
*/
#include <rthw.h>
@@ -178,11 +179,7 @@ static void rt_thread_idle_entry(void *parameter)
{
while (1)
{
- #ifdef RT_USING_HOOK
- if (rt_thread_idle_hook != RT_NULL)
- rt_thread_idle_hook();
- #endif
-
+ RT_OBJECT_HOOK_CALL(rt_thread_idle_hook,());
rt_thread_idle_excute();
}
}
@@ -209,3 +206,14 @@ void rt_thread_idle_init(void)
/* startup */
rt_thread_startup(&idle);
}
+
+/**
+ * @ingroup Thread
+ *
+ * This function will get the handler of the idle thread.
+ *
+ */
+rt_thread_t rt_thread_idle_gethandler(void)
+{
+ return (rt_thread_t)(&idle);
+}
diff --git a/src/irq.c b/src/irq.c
index 70b18e018c..ca221cf10d 100644
--- a/src/irq.c
+++ b/src/irq.c
@@ -21,11 +21,39 @@
* Date Author Notes
* 2006-02-24 Bernard first version
* 2006-05-03 Bernard add IRQ_DEBUG
+ * 2016-08-09 ArdaFu add interrupt enter and leave hook.
*/
#include <rthw.h>
#include <rtthread.h>
+#ifdef RT_USING_HOOK
+
+static void (*rt_interrupt_enter_hook)(void);
+static void (*rt_interrupt_leave_hook)(void);
+
+/**
+ * @ingroup Hook
+ * This function set a hook function when the system enter a interrupt
+ *
+ * @note the hook function must be simple and never be blocked or suspend.
+ */
+void rt_interrupt_enter_sethook(void (*hook)(void))
+{
+ rt_interrupt_enter_hook = hook;
+}
+/**
+ * @ingroup Hook
+ * This function set a hook function when the system exit a interrupt.
+ *
+ * @note the hook function must be simple and never be blocked or suspend.
+ */
+void rt_interrupt_leave_sethook(void (*hook)(void))
+{
+ rt_interrupt_leave_hook = hook;
+}
+#endif
+
/* #define IRQ_DEBUG */
/**
@@ -52,6 +80,7 @@ void rt_interrupt_enter(void)
level = rt_hw_interrupt_disable();
rt_interrupt_nest ++;
+ RT_OBJECT_HOOK_CALL(rt_interrupt_enter_hook,());
rt_hw_interrupt_enable(level);
}
RTM_EXPORT(rt_interrupt_enter);
@@ -72,6 +101,7 @@ void rt_interrupt_leave(void)
level = rt_hw_interrupt_disable();
rt_interrupt_nest --;
+ RT_OBJECT_HOOK_CALL(rt_interrupt_leave_hook,());
rt_hw_interrupt_enable(level);
}
RTM_EXPORT(rt_interrupt_leave);
diff --git a/src/thread.c b/src/thread.c
index 487c005b65..b8b582d5be 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -35,6 +35,7 @@
* thread preempted, which reported by Jiaxing Lee.
* 2011-09-08 Bernard fixed the scheduling issue in rt_thread_startup.
* 2012-12-29 Bernard fixed compiling warning.
+ * 2016-08-09 ArdaFu add thread suspend and resume hook.
*/
#include <rtthread.h>
@@ -44,6 +45,36 @@ extern rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX];
extern struct rt_thread *rt_current_thread;
extern rt_list_t rt_thread_defunct;
+#ifdef RT_USING_HOOK
+
+static void (*rt_thread_suspend_hook)(rt_thread_t thread);
+static void (*rt_thread_resume_hook)(rt_thread_t thread);
+/**
+ * @ingroup Hook
+ * This function sets a hook function when the system suspend a thread.
+ *
+ * @param hook the specified hook function
+ *
+ * @note the hook function must be simple and never be blocked or suspend.
+ */
+void rt_thread_suspend_sethook(void (*hook)(rt_thread_t thread))
+{
+ rt_thread_suspend_hook = hook;
+}
+/**
+ * @ingroup Hook
+ * This function sets a hook function when the system resume a thread.
+ *
+ * @param hook the specified hook function
+ *
+ * @note the hook function must be simple and never be blocked or suspend.
+ */
+void rt_thread_resume_sethook(void (*hook)(rt_thread_t thread))
+{
+ rt_thread_resume_hook = hook;
+}
+#endif
+
void rt_thread_exit(void)
{
struct rt_thread *thread;
@@ -581,6 +612,7 @@ rt_err_t rt_thread_suspend(rt_thread_t thread)
/* enable interrupt */
rt_hw_interrupt_enable(temp);
+ RT_OBJECT_HOOK_CALL(rt_thread_suspend_hook,(thread));
return RT_EOK;
}
RTM_EXPORT(rt_thread_suspend);
@@ -623,6 +655,7 @@ rt_err_t rt_thread_resume(rt_thread_t thread)
/* insert to schedule ready list */
rt_schedule_insert_thread(thread);
+ RT_OBJECT_HOOK_CALL(rt_thread_resume_hook,(thread));
return RT_EOK;
}
RTM_EXPORT(rt_thread_resume);