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 / 3568
3567  |  3569
Subject: 
Global Objects was Strange RCX startup issues
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Tue, 9 Dec 2003 22:31:35 GMT
Viewed: 
3873 times
  
Mark,

This is an interesting issue.  Initially, after reading your post, I was
thinking that it would be easy to add this support to BrickOS.  Of
course, this is only partially correct.

For NON Task Manager builds (therefore no Program manager), it is easy
to plug your code into the kernel.

For Task Manager builds *without* the Program Manager, it is possible,
but not as easy (have to wrap main as you did here)

For Task Manager builds with the Program Manager, this is the tricky
part.  The issue is WHEN to call the ctors and dtors.

Also, I have a question (because of my limited knowledge of how the
__ctors and __dtors are managed):  Would the two *for* loops in your
sample code call the ctors and dtors for all global objects, regardless
of which program they belong (assuming Task Management and Program
Management is built)?  Would it be correct to validate that the function
pointer is pointing to a function within the current program code before
calling it?

// Joe


Mark Riley wrote:

[snip]

#include <config.h>
#include <c++/Motor.H>
#include <conio.h>
#include <unistd.h>

// Call the constructors & destructors of global objects

typedef void (*Ftor)();
extern "C" Ftor __ctors[], __ctors_end[];
extern "C" Ftor __dtors[], __dtors_end[];
int main2();

int main()
  {
  Ftor* f;
  int r;

  // call constructors
  for (f = __ctors; f != __ctors_end; f++)
    (*f)();

  r = main2();

  // call destructors
  for (f = __dtors; f != __dtors_end; f++)
    (*f)();

  return r;
  }

// Test motor object

Motor m(Motor::A);

int main2()
  {
  while (!shutdown_requested())
    {
    m.forward();
    m.speed(m.max);
    cputs("F");
    sleep(1);

    m.reverse();
    m.speed((m.max + m.min) / 2);
    cputs("r");
    sleep(1);
    }

  return 0;
  }



Message has 1 Reply:
  Re: Global Objects was Strange RCX startup issues
 
Doh! I think I just answered the question (of course it was After hitting send) Joseph Woolley wrote: [snip] > Also, I have a question (because of my limited knowledge of how the > __ctors and __dtors are managed): Would the two *for* loops in your (...) (21 years ago, 9-Dec-03, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  Re: Strange RCX startup issues
 
(...) This was only a problem when using certain firmware downloaders. If you use firmdl3, then you should be fine. (...) As far as I can tell, I don't think there is any provision in BrickOS to call the constructors and destructors of globals & (...) (21 years ago, 9-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