comp.lang.ada
 help / color / mirror / Atom feed
From: Warren <ve3wwg@gmail.com>
Subject: Re: Passing Ada Proc as a C Function Pointer
Date: Thu, 5 Aug 2010 07:31:35 -0700 (PDT)
Date: 2010-08-05T07:31:35-07:00	[thread overview]
Message-ID: <7002cc94-5207-4b8d-8686-f8b262bfdef0@d17g2000yqb.googlegroups.com> (raw)

On Aug 5, 3:33 am, Rolf <rolf.ebert_nosp...@gmx.net> wrote:
> On 5 Aug., 02:45, Warren <ve3...@gmail.com> wrote:
>
> > On Aug 4, 3:46 pm, Simon Wright <si...@pushface.org> wrote:
>
> > > I would be a bit worried about Thread_Proc's *Ada* environment. There's
> > > this thing called the Secondary Stack, used for - for example - string
> > > catenation; and it's not set up here.
>
> > Yikes, that could be a problem. I vaguely remember something about
> > a "secondary stack".  I'm going to need to research this.
>
> The current version of AVR-Ada does not support the secondary stack.
> It is required for returning unconstrained objects from functions.
> Using unconstrained arrays already consumes so much of the valuable
> RAM that I never felt the need to support returning these objects from
> functions.

Thanks Rolf!

If I hard code the call to the Ada proc from the start thread in the
C code, the threaded code works great now (in Ada!)  So I just got to
work out this business of the C function pointer.

The other issue I have is to sort out the declaration of the Context
object in Ada. If I declare the context in C, things go well.

Attempting to get the C_Context_Type declared correctly is proving
to be a challenge. Here is what I have:

--  typedef enum {
--      ats_normal,
--      ats_wait,
--      ats_clear = 0x40,
--      ats_tick = 0x80
--  } __attribute__((packed)) avr_thread_state;
--
--  typedef struct avr_thread_context {
--      volatile avr_thread_state state;
--      uint8_t* stack_ptr;
--      volatile struct avr_thread_context* next;
--      volatile int16_t timeout;
--      volatile void* waiting_for;
--      volatile struct avr_thread_context* next_waiting;
--      volatile struct avr_thread_context* prev_waiting;
--  } avr_thread_context;

    type C_Context_Type is
        record
            State :         Unsigned_16;
            Stack_Pointer : System.Address;
            Next :          System.Address;
            Timeout :       Unsigned_16;
            Waiting_For :   System.Address;
            Next_Waiting :  System.Address;
            Prev_Waiting :  System.Address;
        end record;

    pragma Convention(C,C_Context_Type);
    pragma Pack(C_Context_Type);
    for C_Context_Type'Size use 16;

Keep in mind I am NOT interested in using the members of
C_Context_Type, but simply trying to set aside storage
that would match the C declaration (in bytes). I've
also tried declaring arrays, but I get a similar
experience (dope vectors etc. balloon the space).

When I compile the above, I get the complaint:

avr_threads.ads:58:33: size for "C_Context_Type" too small, minimum
allowed is 112

112 bytes - yikers!  How do I get this right?

Warren




             reply	other threads:[~2010-08-05 14:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-05 14:31 Warren [this message]
2010-08-05 15:37 ` Passing Ada Proc as a C Function Pointer Warren
2010-08-05 16:51   ` Warren
  -- strict thread matches above, loose matches on Subject: below --
2010-08-04 16:40 Warren
2010-08-04 17:14 ` Dmitry A. Kazakov
2010-08-05  0:24   ` Warren
2010-08-04 18:46 ` Jeffrey Carter
2010-08-04 19:36   ` Dmitry A. Kazakov
2010-08-05  0:42   ` Warren
2010-08-05  0:55     ` Warren
2010-08-04 19:46 ` Simon Wright
2010-08-05  0:45   ` Warren
2010-08-05  7:33     ` Rolf
2010-08-05 20:50       ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox