This is my source code, very simple.
#include <rtx51.h> #include <stdio.h> #include <math.h> #include <REGX51.H> void task1 (void) _task_ 1 _priority_ 1 { P2_1 = 0; os_wait(K_TMO, 100, 0); } void task2 (void) _task_ 2 { P2_1 = 1; os_wait(K_TMO, 100, 0); } void start (void) _task_ 0 { os_set_slice(10000); os_create_task (1); os_create_task (2); os_delete_task (os_running_task_id ()); P1=0; } void main (void) { P2_3=0; os_start_system (0); }
But when i use proteus to simulator this program, I see that : P2_3 is low, that ok. But P1 is always high. I think that the program doesn't run the funtion :void start (void) _task_ 0 . But I don't know why. Can you help me. Thank you very much.
Thanks for your help. First I think os_start_system() is compel. I delete it and call os_create_task (2); in main but nothing happen.
I try applying your advice but nothing change. I need your help. Thanks very much.
and, why do you create your tasks in a task that is later terminated - is it not better to call
os_set_slice(1000); os_create_task (1); os_create_task (2);
in main?
maybe your task 0 is killed along with its side effects (spawning new tasks...)?
I mean, are you sure this call does not have unforeseen consequences? what happens if you remove it...?
what do you need
os_delete_task (0);
for ?
Thank you for your help! I fixed my code like your advice:
#include <rtx51.h> #include <stdio.h> #include <math.h> #include <REGX51.H> void task1 (void) _task_ 1 _priority_ 1 { while(1){ P2_1 = 0; os_wait(K_TMO, 100, 0); } } void task2 (void) _task_ 2 { while(1){ P2_1 = 1; os_wait(K_TMO, 100, 0); } } void start (void) _task_ 0 { P1=0; os_set_slice(1000); os_create_task (1); os_create_task (2); os_delete_task (0); } void main (void) { P2_3=0; os_start_system (0); }
But the result doesn't change. Help me, please! Thanks very much!
First off - your program does not contain any loop. The function task1() and task2() immediatelly returns. Was that intended?
Next thing - the task "start" calls os_delete_task(os_running_task_id()); Wouldn't that kill this task before it gets time to run the following line?
View all questions in Keil forum