We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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.
are you using your own scheduler? what is the RTOS you are using?
I use RTX51 Full with KeilC. I thinks this program is so simple. But.... I don't known why it doesn't run.
do you be trying the run to the simulator and you be stepping the steps?
z.i.k. try not with proteous me thinked is good.
I don't know if there is a difference between RTX51 Full and RTX51 Tiny.
The Tiny manual says: http://www.keil.com/support/man/docs/tr51/tr51_guidelines.htm
"Do not create a main C function. RTX51 Tiny has its own main function." I guess this isn't relevant, since the Tiny version doesn't document a os_start_system() call.
"Task functions must never exit or return."
You must examine your documentation if your task start() is allowed to end by falling past the end brace.
You must also examine your documentation if the main() function may return, or if os_start_system() is a function that never returns.
In the ARM version of the compiler, main() is all
This is my lastest code:
#include <rtx51.h> #include <stdio.h> #include <math.h> #include <REGX51.H> void task1 (void) _task_ 1 _priority_ 1 { while(1){ P2_2 = 0; os_wait(K_TMO, 1000, 0); } } void task2 (void) _task_ 2 { while(1){ P2_4 = 1; os_wait(K_TMO, 100, 0); } } void main (void) { P2_3=0; os_set_slice(10000); os_create_task (1); os_create_task (2); P2_3=1; }
Then, I debug it by KeilC. First, P2_3 is low. Then I see the program finish running these function : os_set_slice(10000); os_create_task (1); os_create_task (2); After that, P2_3 is high. But then I see the program repeat the main() function (P2_3 is low....) . So , I can't understand what happen.
Can you give a simple example which well operated? Thanks very much!
how about placing an infinite loop in your main as well...? I think your processor resets! is such a loop not required when using RTX?
I don't understand what you mean about "an infinite loop". My program is repeated the main() function infinite times. Maybe be my processor reseted. But why? "a loop not required when using RTX" ? Can you explain clearer? Thanks a lot!
My guess is that the function os_start_system() in RTX51 does a similar thing as the os_sys_init() function in the ARM version of RTX.
The manual says "The os_sys_init function does not return."
If you let main() return, then it is up to the startup code to decide what will happen - if main will be restarted, the processor will be reset (leading to main being called again), the program getting stuck in an infinite loop after end of main(), ...
In short - consider it undefined behaviour what happens if you leave mai(), and make sure that it doesn't happen.
void main (void) { P2_3=0; os_set_slice(10000); os_create_task (1); os_create_task (2); P2_3=1; while(1) { // hang here } ; }
If you leave out the forever loop in main then Keil will insert a LJMP to 'Main'at the end of Main. That is why your main continues forever. As was pointed out, you should not have a 'Main' when using RTX51. RTX51 always enters at Task 0. The Delete of the Task Startup code is a good practice. Normally you would have you system power up or reset initialization code in this task, then start your other tasks and then delete the Start up task. You don't want to re-run the initialization task again. I don't see where you define P2_3 as any set bit code. P2 is defined in the header but P2^3 is used to toggle the port bit. Do you have a definition that I missed? Bradford
Thanks for your help! But I see the examples in RTX51.pdf, all of them use main() function. So I don't understand how to leave main(). Could you tell me a example without main() function?
What is the result of the following:
#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 { os_set_slice(10000); os_create_task(1); os_create_task(2); P1 = 0; os_delete_task(os_running_task_id()); } void main(void) { P2_3 = 0; os_start_system(0); }
Here is a quick modified code from the RTXTiny Example file. Bradford
#include <rtx51tny.h> #include <reg51.h> sbit Toggle = P2^1; /*****************************************************/ /* Task 0 'job0': RTX-51 tiny starts execution with task 0 */ /**************************************************/ void start (void) _task_ 0 { os_create_task (1); os_create_task (2); os_delete_task (os_running_task_id ()); } /****************************************************/ /* Task 1 'job1': RTX-51 tiny starts this task with os_create_task (1) */ /***********************************************/ void task1 (void) _task_ 1 { while(1){ Toggle = 0; os_wait(K_TMO, 100, 0); } } /****************************************************/ /* Task 2 'job2': RTX-51 tiny starts this task with os_create_task (2) */ /****************************************************/ void task2 (void) _task_ 2 { while(1){ Toggle = 1; os_wait(K_TMO, 100, 0); } }
Thank you very much for your code. I compile it with RTX-51 Tiny. It run successfull. I see the change state on P2_1.
Now I need to add the priority to the tasks. It means each task has different prioritys. And the program must use RTX-51 Full. From your code , I add the priority and compile with RTX-51 full. It's ok. But when I make simulation this program, I don't see any change state o P2_1. So I sets the same priority to task 1 and 2 . But that has no effect.
This is the code:
#include <rtx51tny.h> #include <reg51.h> sbit Toggle = P2^1; /*****************************************************/ /* Task 0 'job0': RTX-51 tiny starts execution with task 0 */ /**************************************************/ void start (void) _task_ 0 { os_create_task (1); os_create_task (2); os_delete_task (os_running_task_id ()); } /****************************************************/ /* Task 1 'job1': RTX-51 tiny starts this task with os_create_task (1) */ /***********************************************/ void task1 (void) _task_ 1 _priority_ 1 { while(1){ Toggle = 0; os_wait(K_TMO, 10, 0); } } /****************************************************/ /* Task 2 'job2': RTX-51 tiny starts this task with os_create_task (2) */ /****************************************************/ void task2 (void) _task_ 2 _priority_ 1 { while(1){ Toggle = 1; os_wait(K_TMO, 10, 0); } }
Could you give me advice? Thanks a lot!
Glad you have your first RTX Tiny running. I'm sorry but I do not have RTX Full on this computer so I do not have the documentation but have you added the correct header files for RTX Full? Have you selected the correct operating system under Targets -> Operating system? This will load the correct library files. That's about all I can remember of RTX Full without the documentation available to me at this time. Bradford