From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,86f62fb0f98ad93e X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!d17g2000yqb.googlegroups.com!not-for-mail From: Warren Newsgroups: comp.lang.ada Subject: Re: Passing Ada Proc as a C Function Pointer Date: Thu, 5 Aug 2010 07:31:35 -0700 (PDT) Organization: http://groups.google.com Message-ID: <7002cc94-5207-4b8d-8686-f8b262bfdef0@d17g2000yqb.googlegroups.com> References: 60b8a494-fed1-4e0f-ba27-a2b7070d5818@k19g2000yqc.googlegroups.com NNTP-Posting-Host: 216.121.235.102 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1281018695 8946 127.0.0.1 (5 Aug 2010 14:31:35 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 5 Aug 2010 14:31:35 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d17g2000yqb.googlegroups.com; posting-host=216.121.235.102; posting-account=ENgozAkAAACH-stq5yXctoDQeZQP2E6J User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 ( .NET CLR 3.5.30729),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:12879 Date: 2010-08-05T07:31:35-07:00 List-Id: On Aug 5, 3:33=A0am, Rolf wrote: > On 5 Aug., 02:45, Warren wrote: > > > On Aug 4, 3:46=A0pm, Simon Wright 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 - strin= g > > > catenation; and it's not set up here. > > > Yikes, that could be a problem. I vaguely remember something about > > a "secondary stack". =A0I'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 =3D 0x40, -- ats_tick =3D 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