From 83259590224c5c174e6ad4502c65c086c1b24964 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 23 Jul 2008 18:08:05 +0000 Subject: 2008-07-23 Joel Sherrill * Makefile, ada_from_c.adb, app.c, config.h, example.adb, example.ads: New files. New test to demonstrate C calling Ada. --- ada_from_c_task/Makefile | 35 +++++++++++++++++++++++++++++++++++ ada_from_c_task/ada_from_c.adb | 24 ++++++++++++++++++++++++ ada_from_c_task/app.c | 41 +++++++++++++++++++++++++++++++++++++++++ ada_from_c_task/config.h | 5 +++++ ada_from_c_task/example.adb | 18 ++++++++++++++++++ ada_from_c_task/example.ads | 14 ++++++++++++++ 6 files changed, 137 insertions(+) create mode 100644 ada_from_c_task/Makefile create mode 100644 ada_from_c_task/ada_from_c.adb create mode 100644 ada_from_c_task/app.c create mode 100644 ada_from_c_task/config.h create mode 100644 ada_from_c_task/example.adb create mode 100644 ada_from_c_task/example.ads diff --git a/ada_from_c_task/Makefile b/ada_from_c_task/Makefile new file mode 100644 index 0000000..c6fb340 --- /dev/null +++ b/ada_from_c_task/Makefile @@ -0,0 +1,35 @@ +# +# Makefile for Ada Dump URL example +# +# See README.Makefiles in the main ada-examples directory. +# + +PROGRAM=ada_from_c + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(PROJECT_ROOT)/make/leaf.cfg + +# stack size for the first Ada thread +CFLAGS +=-DGNAT_MAIN_STACKSPACE=100 + +# initialize the network stack -- assumes existence of networkconfig.h +# CFLAGS +=-DMAIN_USE_NETWORKING=1 + +# Should we prompt for command line arguments? +# DEFINES +=-DMAIN_USE_REQUIRES_COMMAND_LINE + +# Do we have a C initialization helper? +DEFINES +=-DMAIN_CALL_C_INITIALIZE_APPLICATION + +# Do we have extra configuration +DEFINES +=-DHAS_EXTRA_CONFIGURATION + +# If you want to hard-code the command line, define this to a string +# DEFINES += -DMAIN_COMMAND_LINE="ARGS" + +EXTRA_OBJS=app.o + +include ../Makefile.shared + +app.o: app.c diff --git a/ada_from_c_task/ada_from_c.adb b/ada_from_c_task/ada_from_c.adb new file mode 100644 index 0000000..268968f --- /dev/null +++ b/ada_from_c_task/ada_from_c.adb @@ -0,0 +1,24 @@ +-- +-- Ada From C Example -- Ada "Application" +-- + +with Text_IO; use Text_IO; +with Example; + +procedure Ada_From_C is + + task Ada_From_C_Task; + + task body Ada_From_C_Task is + begin + Put_Line ("GNAT/RTEMS C Calling Ada Test"); + + loop + Put_Line ("Ada task loop iteration"); + delay 1.0; + end loop; + end Ada_From_C_Task; + +begin + NULL; +end Ada_From_C; diff --git a/ada_from_c_task/app.c b/ada_from_c_task/app.c new file mode 100644 index 0000000..2ab91dc --- /dev/null +++ b/ada_from_c_task/app.c @@ -0,0 +1,41 @@ +#include + +#include + +rtems_task c_task( + rtems_task_argument ignored +) +{ + rtems_interval ticks_per_second; + int iterations; + + ticks_per_second = rtems_clock_get_ticks_per_second(); + + for (iterations=0 ; ; iterations++ ) { + (void) rtems_task_wake_after( 1 * ticks_per_second ); + printf( "C task loop iteration\n" ); + example_ToBeCalled( iterations ); + } +} + +void initialize_application(void) +{ + rtems_status_code status; + rtems_id id; + + status = rtems_task_create( + rtems_build_name( 'C', 'T', 'S', 'K' ), + 133, + RTEMS_MINIMUM_STACK_SIZE * 2, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, + &id + ); + if ( status ) + printf( "c_task create failed %d\n", status ); + + status = rtems_task_start( id, c_task, 0 ); + if ( status ) + printf( "c_task start failed %d\n", status ); + +} diff --git a/ada_from_c_task/config.h b/ada_from_c_task/config.h new file mode 100644 index 0000000..ce4349b --- /dev/null +++ b/ada_from_c_task/config.h @@ -0,0 +1,5 @@ +/* + * $Id$ + */ + +#define CONFIGURE_MAXIMUM_FAKE_ADA_TASKS 1 diff --git a/ada_from_c_task/example.adb b/ada_from_c_task/example.adb new file mode 100644 index 0000000..e73b18a --- /dev/null +++ b/ada_from_c_task/example.adb @@ -0,0 +1,18 @@ +-- +-- The license and distribution terms for this file may be +-- found in the file LICENSE in this distribution or at +-- http://www.rtems.com/license/LICENSE. +-- +-- $Id$ +-- + +with Text_IO; use Text_IO; + +package body Example is + procedure ToBeCalled ( + iterations : in Integer + ) is + begin + Put_Line ( "Ada method called " & Integer'Image (iterations) & " times" ); + end ToBeCalled; +end Example; diff --git a/ada_from_c_task/example.ads b/ada_from_c_task/example.ads new file mode 100644 index 0000000..7a5a256 --- /dev/null +++ b/ada_from_c_task/example.ads @@ -0,0 +1,14 @@ +-- +-- The license and distribution terms for this file may be +-- found in the file LICENSE in this distribution or at +-- http://www.rtems.com/license/LICENSE. +-- +-- $Id$ +-- + +package Example is + procedure ToBeCalled( + iterations : in Integer + ); + pragma export(C, ToBeCalled, "example_ToBeCalled"); +end Example; -- cgit v1.2.3