source: rtems-docs/c-user/ada_support.rst @ e52906b

5
Last change on this file since e52906b was e52906b, checked in by Sebastian Huber <sebastian.huber@…>, on 01/09/19 at 15:14:06

Simplify SPDX-License-Identifier comment

  • Property mode set to 100644
File size: 4.3 KB
Line 
1.. SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. Copyright (C) 1989, 2017 On-Line Applications Research Corporation (OAR)
4
5.. index:: Ada
6.. _ada_support:
7
8Ada Support
9************
10
11Introduction
12============
13RTEMS has long had support for the Ada programming language
14by supporting the GNU Ada Compiler (GNAT). There are two primary
15components to this support:
16
17- Ada Programming Language Support
18
19- Classic API Ada Bindings
20
21Ada Programming Language Support
22================================
23
24The Ada programming natively supports multi-threaded programming
25with its own tasking and concurrency model. Native Ada multi-threaded
26applications should work using GNAT/RTEMS with no changes.
27
28The application developer will have to account for the specific
29requirements of the GNAT Run-Time when configuring RTEMS. There
30are example Ada programs with RTEMS configuration and startup sequences.
31
32Classic API Ada Bindings
33========================
34
35An Ada language binding exists for a subset of the RTEMS Classic
36API. In the early 1990's, there were C and Ada implementations of
37RTEMS which were functionally equivalent. The source structure was as
38similar as possible. In fact, the top level ``c/`` directory at one point
39had a sibling ``ada/``. The current Ada language bindings and test code was
40derived from that Ada implementation.
41
42The Ada binding specifically excludes some methods which are either not
43safe or not intended for use from Ada programs. However, methods are
44generally only added to this binding when a user makes a requests. Thus
45some methods that could be supported are not. If in doubt, ask about a
46methods and contribute bindings.
47
48The bindings are located in the ``c/src/ada`` directory of the RTEMS source
49tree. The tests are in ``c/src/ada-tests``.  The bindings following a simple
50pattern to map the C Classic API calls into Ada subprograms. The following
51rules are used:
52
53- All RTEMS interfaces are in the RTEMS Ada package.  The rtems\_ and
54  RTEMS\_ prefixes in the C version of the Classic API thus correspond to
55  "RTEMS." in Ada symbol nomenclature. For example, ``rtems_task_create()``
56  in C is ``RTEMS.Task_Create()`` in Ada.
57
58- Classic API directives tend to return an ``rtems_status_code``. Some
59  directives also have an output parameter such as an object id on a create
60  operation. Ada subprograms are either pure functions with only a single
61  return value or subprograms. For consistency, the returned status code
62  is always the last parameter of the Ada calling sequence.
63
64Caution should be exercised when writing programs which mix Ada tasks,
65Classic API tasks, and POSIX API threads. Ada tasks use a priority
66numbering scheme defined by the Ada programming language. Each Ada task
67is implemented in GNAT/RTEMS as a single POSIX thread. Thus Ada task
68priorities must be mapped onto POSIX thread priorities. Complicating
69matters, Classic API tasks and POSIX API threads use different numbering
70schemes for priority. Low numbers are high priority in the Classic
71API while indicating low priority in the POSIX threads API. Experience
72writing mixed threading model programs teaches that creating a table
73of the priorities used in the application with the value in all tasking
74models used is helpful.
75
76The GNAT run-time uses a priority ceiling mutex to protect its data
77structures. The priority ceiling value is one priority more important
78than the most important Ada task priority (in POSIX API terms). Do not
79invoke any services implemented in Ada from a thread or task which is
80of greater priority. This will result in a priority ceiling violation
81error and lead to a failure in the Ada run-time.
82
83Exercise extreme caution when considering writing code in Ada which
84will execute in the context of an interrupt handler. Hardware interrupts are
85processed outside the context of any thread in RTEMS and this can lead
86to violating assumptions in the GNAT run-time. Specifically a priority
87ceiling mutex should never be used from an ISR and it is difficult to
88predict when the Ada compiler or run-time will use a mutex.
89
90RTEMS has two capabilities which can assist in avoiding this problem. The
91Classic API Timer Manager allows the creation of Timer Service Routines
92which execute in the context of a task rather than the clock tick
93Interrupt Service Routine. Similarly, there is support for Interrupt Tasks
94which is a mechanism to defer the processing of the event from the
95hardware interrupt level to a thread.
Note: See TracBrowser for help on using the repository browser.