comp.lang.ada
 help / color / mirror / Atom feed
* Return unconstrained types in ZFP
@ 2012-12-02  2:38 Rego, P.
  2012-12-02  3:29 ` Shark8
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Rego, P. @ 2012-12-02  2:38 UTC (permalink / raw)


Dear fellows, 

I am trying to implement, for an ATmega2560 (Arduino Mega) micro-controller using ZFP in GNAT-AVR, an USART unconstrained Get string like
      function Get (Port : USART_Port_Type; Size : Unsigned_8) return String_U8;

assuming that USART_Port_Type is an enumeration, and
      type String_U8 is array (Unsigned_8 range <>) of Character;

So I tried
      function Get (Port : USART_Port_Type; Size : Unsigned_8) return String_U8 is
         Curr_String : String_U8 (1 .. Size);
         Null_String : constant String_U8 (1 .. Size) := (others => ' ');
      begin
         for Index in 1 .. Curr_String'Length loop
            Curr_String (Unsigned_8 (Index)) := Get (Port); -- BTW, function Get (Port : USART_Port_Type) return Character; works ok!
         end loop;
         return Curr_String;
      exception
         when others => return Null_String;
      end Get;

and the compiler complained that I am not defining the Last_Chance_Handler. Now I found in GNAT documentation, that I should define it using
      procedure Last_Chance_Handler
        (Source_Location : System.Address; Line : Integer);
      pragma Export (C, Last_Chance_Handler, "__gnat_last_chance_handler");

and at least (for now) a null procedure would be enough
      procedure Last_Chance_Handler
        (Source_Location : System.Address; Line : Integer) is
      begin
         null;
      end Last_Chance_Handler; 

But now the compiler complains that I also did not define the Get_Secondary_Stack, and found no reference to memcpy. I found in GNAT documentation the Secondary Stack definition, but with no syntax information, and nothing else. And regarding to memcpy, found nothing.
   --    The Secondary Stack
   --      The secondary stack is a special storage pool that is used for
   --      this purpose. The called function places the result on the
   --      secondary stack, and the caller uses or copies the value from
   --      the secondary stack, and pops the secondary stack after the
   --      value is consumed. The secondary stack is outside the system
   --      ABI, and the important point is that although generally it is
   --      handled in a stack like manner corresponding to the subprogram
   --      call structure, a return from a function does NOT pop the stack.

Actually the compiler returned me
   In function `avr__atmega2560__usart__get__7':
   avr-atmega2560-usart.adb:(.text+0x164c): undefined reference to `memcpy'
   avr-atmega2560-usart.adb:(.text+0x1694): undefined reference to `memcpy'
   C:/GNAT/2012/lib/gcc/avr/4.5.4/rts-zfp\adalib\libgnat.a(s-secsta.o): In function `system__secondary_stack__ss_allocate':
   s-secsta.adb:(.text+0x8): undefined reference to `__gnat_get_secondary_stack'
   C:/GNAT/2012/lib/gcc/avr/4.5.4/rts-zfp\adalib\libgnat.a(s-secsta.o): In function `system__secondary_stack__ss_mark':
   s-secsta.adb:(.text+0x54): undefined reference to `__gnat_get_secondary_stack'
   C:/GNAT/2012/lib/gcc/avr/4.5.4/rts-zfp\adalib\libgnat.a(s-secsta.o): In function `system__secondary_stack__ss_release':
   s-secsta.adb:(.text+0x66): undefined reference to `__gnat_get_secondary_stack'
   collect2: ld returned 1 exit status
   avr-gnatlink: error when calling C:\GNAT\2012\bin\avr-gcc.exe
   avr-gnatmake: *** link failed.

I also tried to define null bodies like the Last_Chance_Handler, and at this point the code linked with success. But I am afraid that doing this I could make a big mess, so I did not burn the chip using this .hex (specially due to Memcpy null body). Thus, could someone give me a light on this? How can I implement correctly the Secondary_Stack procedure and Memcpy? Or maybe a better documentation or a tutorial would be very helpful.

Thanks.



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2012-12-05 13:48 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-02  2:38 Return unconstrained types in ZFP Rego, P.
2012-12-02  3:29 ` Shark8
2012-12-04  1:08   ` Rego, P.
2012-12-02 18:13 ` Luke A. Guest
2012-12-04  0:59   ` Rego, P.
2012-12-02 18:27 ` rrr.eee.27
2012-12-04  0:54   ` Rego, P.
2012-12-03 12:25 ` Stephen Leake
2012-12-04  1:15   ` Rego, P.
2012-12-04  8:40   ` Stephen Leake
2012-12-04 13:21     ` Britt
2012-12-05  3:34       ` Stephen Leake
2012-12-05 13:48         ` Britt

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