To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 2219
2218  |  2220
Subject: 
Re: threads - bug in the firmware?
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Thu, 17 Jan 2002 19:22:49 GMT
Viewed: 
1704 times
  
;-) 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:
  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:





Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR