From: Warren on
On Aug 5, 10:31 am, Warren <ve3...(a)gmail.com> wrote:
> On Aug 5, 3:33 am, Rolf <rolf.ebert_nosp...(a)gmx.net> wrote:
...
> 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

Arg!!!! Arg!!!!

I keep thinking in terms of bytes - not BITS!! No wonder!

Warren
From: Warren on
On Aug 5, 11:37 am, Warren <ve3...(a)gmail.com> wrote:
> Arg!!!!  Arg!!!!
>
> I keep thinking in terms of bytes - not BITS!!  No wonder!
>
> Warren

At long last-- it works!!!!

I ended up creating a C routine for the launch:

void
avr_thread_start_ada(
avr_thread_context* context,
uint8_t* stack,
uint16_t stack_size) {
extern void thread_thunk(void); /* Ada in C convention */

avr_thread_start(context,thread_thunk,stack,stack_size);
}

which is called by Start_Thread in Ada. This then invokes the usual
avr_thread_start(), which then launches the Ada (in C convention)
routine Thread_Thunk:

procedure Thread_Thunk;
pragma export(C,Thread_Thunk,"thread_thunk");

procedure Thread_Thunk is
Context : Thread_Context_Ptr := Get_Context;
begin
Context.Ada_Proc.all; -- Start Ada code in new thread
end Thread_Thunk;

There was an undocumented AVR_Threads routine in the include file
that allowed me to pick up the active context, which is used by
Ada routine binding Get_Context.

The context object turned out to be tricky because the C context
object needed to be "struct aligned", which appears to be 64-bit.
So a little work on that fixed it. I also rolled the stack into
the object as a variant record, for user convenience:

type Thread_Context(Stack_Size : Unsigned_16) is
record
C_Context : aliased C_Context_Type;
Ada_Proc : Thread_Proc;
Stack : aliased Stack_Type(1..Stack_Size);
end record;

for Thread_Context use
record
C_Context at 0 range 0 .. 16 * 8 -1; -- Must be
first to be 64-bit aligned
Stack_Size at 16 range 0 .. 15; -- Moved
here - non critical
Ada_Proc at 18 range 0 .. 15; -- Non
critical placement
-- Stack at 20 range 0 .. Stack_Size * 8 - 1;
end record;

Thanks to everyone for their comments and ideas.

Warren
From: Simon Wright on
Rolf <rolf.ebert_nospam_(a)gmx.net> writes:

>> > There may be a pragma to prevent secondary stack usage?
>>
>> I'm all ears! ;-)
>
> pragma Restrictions (No_Secondary_Stack);
>
> It is already active if you use AVR-Ada. See the file gnat.adc

One fewer thing to worry about, then!