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 / 3593
3592  |  3594
Subject: 
Re: Direct Link (was Global Objects was Strange RCX startup issues)
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Sat, 13 Dec 2003 01:31:56 GMT
Viewed: 
3799 times
  
In lugnet.robotics.rcx.legos, Steve Hassenplug wrote:
In lugnet.robotics.rcx.legos, Mark Riley wrote:
...
When not using the program manager (i.e. linking the user program directly to
BrickOS), then some simple loops like in my example should do the trick.

All right, this brings up an interesting question.

I can use BrickOS well enough to make it do cool stuff, but I really don't know
all the cool stuff BrickOS can do...

If I read this correctly, it means I can write a single program, and build it as
part of the BrickOS kernal, so it is the only "program" that I can run, which
makes sense.

So, can someone help me figure out how to do that?

Ok, I'll take a shot at it:

1) Make a new directory in the root BrickOS directory called pgm.
2) Copy the files config.h and Makefile from the boot directory
   to the pgm directory.
3) Copy your C files to the pgm directory.
4) Edit config.h (in the pgm directory) and comment out the line
   with the CONF_PROGRAM define.
5) Edit Makefile (in the pgm directory):
   a) Add your C filenames to the KSOURCES= line.
   b) Add "*.c" to the .depend rule so it reads as follows:
       .depend: $(BRICKOS_ROOT)/kernel/*.c *.c
         $(MAKEDEPEND) $(BRICKOS_ROOT)/kernel/*.c *.c > .depend
6) Go to the pgm directory with your shell and run make.
7) You can now download your program (brickOS.srec) to the RCX.

Hopefully, I didn't omit any steps. :D

When you download your program it will immediately start running.
Unfortunately, you will find that the On/Off button no longer works (and none of
the other buttons will do anything, either).  This is because the buttons were
managed by the no longer present Program Manager.

This is something of a hack, but here's a function you can use in your program
to add On/Off functionality (I borrowed this code from the Program Manager):

  #include <unistd.h>
  #include <conio.h>
  #include <sys/tm.h>
  #include <sys/irq.h>
  void shutdown()
    {
    int clear = 50;
    cputs("OFF");
    disable_irqs();
    shutdown_tasks(T_USER | T_KERNEL);  // Kindly request all tasks shutdown
    ctid->tflags &= (~T_SHUTDOWN);      // Except for us
    enable_irqs();
    while (--clear && (nb_tasks > 2))   // Wait a bit
      msleep(100);
    if (nb_tasks > 2)                   // Wait no longer
      killall(PRIO_HIGHEST);
    ctid->tflags |= T_SHUTDOWN;         // Now we should shutdown
    }

In your main loop add a check for the On/Off key:

int main()
  {

  // initialize stuff...

  while (!shutdown_requested())
    {
    // check if on/off key pressed
    if (dkey & KEY_ONOFF)
      {
      shutdown();
      continue;
      }

    // play game...

    }

  // clean up...

  return 0;
  }

One big difference you will notice is that all your variables will persist when
turning the RCX off then on.  Uninitialized variables will be zero the first
time your program runs, however after that they will retain whatever values were
last assigned to them.  Any changes to staticly initialized values will persist
from program run to program run.

HTH,

Mark



Message has 1 Reply:
  Re: Direct Link (was Global Objects was Strange RCX startup issues)
 
(...) perfect! Step by step directions. Thanks. (...) So, now I can use the 'run' button to do other stuff, right? Or, for that matter, I could do other stuff with the On/Off button. After I turn it off (using the code listed), then, I can just turn (...) (21 years ago, 15-Dec-03, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  Direct Link (was Global Objects was Strange RCX startup issues)
 
In lugnet.robotics.rcx.legos, Mark Riley wrote: ... (...) All right, this brings up an interesting question. I can use BrickOS well enough to make it do cool stuff, but I really don't know all the cool stuff BrickOS can do... If I read this (...) (21 years ago, 11-Dec-03, to lugnet.robotics.rcx.legos)

12 Messages in This Thread:



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

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

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