Subject:
|
Re: threads - bug in the firmware?
|
Newsgroups:
|
lugnet.robotics.rcx.legos
|
Date:
|
Thu, 17 Jan 2002 19:22:49 GMT
|
Viewed:
|
1704 times
|
| |
![Post a public reply to this message](/news/icon-reply.gif) | |
;-) That worked a treat, thanks Michael. (thanks for the other little
corrections in the code
too).
mike
In lugnet.robotics.rcx.legos, Michael Obenland writes:
> Hi Mike,
>
> your problem is not because of an error in legOS. But what you do is that
> you start your subroutines and then you leave main()! Leaving main means
> that all your allocated memory is freed. The following will do the job:
>
> ------------------ cut here --------------------------------------------
>
> #include <conio.h> // console
> #include <unistd.h> // UNIX std for timers and task management
> #include <dkey.h> // to allow user input, doh
>
> pid_t pid1;
> pid_t pid2;
> pid_t pid3;
>
> int bumper_task (int argc, char *argv[]);
> int left_task (int argc, char *argv[]);
> int right_task (int argc, char *argv[]);
>
> wakeup_t bumper_hit (wakeup_t data);
> wakeup_t key_hit (wakeup_t data);
>
> void key (int data1, int data2);
>
> int main(int argc, char *argv[])
> {
> pid1 = execi (&bumper_task, 0, NULL, PRIO_NORMAL+4, DEFAULT_STACK_SIZE);
> pid2 = execi (&left_task, 0, NULL, PRIO_NORMAL+2, DEFAULT_STACK_SIZE);
> pid3 = execi (&right_task, 0, NULL, PRIO_NORMAL, DEFAULT_STACK_SIZE);
> while( 1 ); // <<<<<<<<<<<<< this is crucial!
> return 0;
> }
>
> wakeup_t bumper_hit(wakeup_t data)
> {
> return dkey_pressed( KEY_PRGM );
> }
>
> int bumper_task (int argc, char *argv[])
> {
> while (1) {
> wait_event (&bumper_hit, 0);
> msleep(250);
> cputs ("ouch");
> kill(pid2);
> kill (pid3);
cputs ("dead");
> msleep (1000);
> //********** GETS THIS FAR******************
>
>
pid2 = execi( &left_task, 0, NULL, PRIO_NORMAL+2, DEFAULT_STACK_SIZE);
> pid3 = execi (&right_task, 0, NULL, PRIO_NORMAL, DEFAULT_STACK_SIZE);
> cputs( "finis" );
> }
return 0;
> } // end of bumper_task ()
>
> int left_task (int argc, char *argv[])
> {
> int k = 0;
>
> for (k = 50; k < 255; k++) {
> msleep (200);
> }
>
> return 0;
> }
>
> int right_task(int argc, char *argv[])
> {
> int k = 0;
>
> for (k = 50; k < 255; k++) {
> lcd_int (k);
> msleep (200);
> }
> return 0;
> }
>
> // ************* TEMP DEBUG CODE *************
> void key (int data1, int data2)
> {
> cputs ("key");
> wait_event (&key_hit, 0);
> lcd_int(data1);
> msleep (1000);
> cputw (data2);
> msleep (1000);
> }
>
> wakeup_t key_hit (wakeup_t data)
> {
> return dkey_pressed (KEY_VIEW);
> }
|
|
Message is in Reply To:
![](/news/x.gif) | | Re: threads - bug in the firmware?
|
| Hi Mike, your problem is not because of an error in legOS. But what you do is that you start your subroutines and then you leave main()! Leaving main means that all your allocated memory is freed. The following will do the job: ---...--- cut here (...) (22 years ago, 17-Jan-02, to lugnet.robotics.rcx.legos)
|
18 Messages in This Thread: ![threads -Mike McFarlane (14-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/46.gif) ![Re: threads -Mike McFarlane (15-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/246.gif) ![Re: threads -Albert Huang (15-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/46.gif) ![Re: threads -Mike McFarlane (16-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/46.gif) ![Re: threads -Albert Huang (16-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/46.gif) ![Re: threads -Mike McFarlane (17-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif)
![](/news/x.gif) ![](/news/x.gif) ![](/news/68.gif) ![Re: threads - bug in the firmware? -Mike McFarlane (16-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/246.gif) ![Re: threads - bug in the firmware? -Eric Swalens (16-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif)
![](/news/x.gif) ![](/news/x.gif) ![](/news/68.gif) ![Re: threads - bug in the firmware? -Michael Obenland (17-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/246.gif) ![You are here](/news/here.gif)
![](/news/x.gif) ![](/news/x.gif) ![](/news/268.gif) ![Re: threads - bug in the firmware? -Ross Crawford (17-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/46.gif) ![Re: threads - bug in the firmware? -Mike McFarlane (18-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/46.gif) ![Re: threads - bug in the firmware? -Ross Crawford (21-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif)
![](/news/x.gif) ![](/news/x.gif) ![](/news/68.gif) ![Re: threads - bug in the firmware? -Michael Ash (18-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/46.gif) ![More on threads -Michael Obenland (18-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/46.gif) ![Re: More on threads -Mike McFarlane (19-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/46.gif) ![Re: More on threads -Michael Obenland (19-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/46.gif) ![Re: More on threads -Michael Ash (19-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif)
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|