-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now we can use function user_interrupt_register() to inject an user interrupt into a task. But it can only be injected by other task. Signed-off-by: lizhe <493321524@qq.com>
- Loading branch information
Showing
8 changed files
with
110 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef _USER_INTERRUPT_H | ||
#define _USER_INTERRUPT_H | ||
|
||
#include <TCB.h> | ||
|
||
void user_interrupt_register(struct task_struct *task_ptr, user_interrupt_fun fun); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <user_interrupt.h> | ||
#include <os_cpu_stm32.h> | ||
#include <myassert.h> | ||
|
||
extern volatile struct task_struct *OSTCBCurPtr; | ||
|
||
#define current OSTCBCurPtr | ||
#define SAVED_REGISTER_NUM 15 | ||
|
||
static void restore_frame(void) | ||
{ | ||
/* we put some register in stack to build a stack frame for | ||
user interrupt function, so now we have to restore it*/ | ||
current->stack += SAVED_REGISTER_NUM; | ||
OSIntCtxSw(); | ||
} | ||
|
||
static void default_user_interrupt_handler(void *para) | ||
{ | ||
ASSERT(NULL == para, ASSERT_PARA_AFFIRM); | ||
struct task_struct *task_ptr = (struct task_struct *)current; | ||
user_interrupt_fun fun = task_ptr->fun; | ||
fun(); | ||
restore_frame(); | ||
} | ||
|
||
static inline void user_interrupt_set_task_frame(struct task_struct *task_ptr) | ||
{ | ||
set_register((void **)&task_ptr->stack, default_user_interrupt_handler, NULL, NULL); | ||
} | ||
|
||
void user_interrupt_register(struct task_struct *task_ptr, user_interrupt_fun fun) | ||
{ | ||
ASSERT(task_ptr != current, ASSERT_PARA_AFFIRM); | ||
ASSERT(fun != NULL, ASSERT_PARA_AFFIRM); | ||
task_ptr->fun = fun; | ||
user_interrupt_set_task_frame(task_ptr); | ||
return; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
SRCS = testcase20.c | ||
SRCS = testcase21.c | ||
|
||
#ifeq ($(PROJECT),stm32f103) | ||
#SRCS += bsp_led.c | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* test user interupt top */ | ||
#include <user_interrupt.h> | ||
#include <user.h> | ||
#include <osinit.h> | ||
#include <os_delay.h> | ||
#include <os_cpu.h> | ||
#include <myassert.h> | ||
|
||
extern volatile struct task_struct *OSTCBCurPtr; | ||
extern volatile struct task_struct *OSTCBHighRdyPtr; | ||
|
||
static struct task_struct *task_three = NULL; | ||
|
||
#include <printf_debug.h> | ||
|
||
void three(void *para) | ||
{ | ||
pr_shell("this is three\n"); | ||
task_three = (struct task_struct *)OSTCBCurPtr; | ||
while (1) { | ||
sleep(2 * HZ); | ||
ASSERT(OSTCBCurPtr->fun == para, ASSERT_PARA_AFFIRM); | ||
pr_shell("this is three next\n"); | ||
} | ||
} | ||
|
||
void my_fun(void) | ||
{ | ||
pr_shell("user interrupt from task four\n"); | ||
pr_shell("this is task %s\n", OSTCBCurPtr->name); | ||
} | ||
|
||
void four(void *para) | ||
{ | ||
pr_shell("this is four\n"); | ||
if (task_three == NULL) { | ||
pr_shell("user interupt test fail\n"); | ||
return; | ||
} | ||
user_interrupt_register(task_three, my_fun); | ||
pr_shell("register_complete\n"); | ||
} |