source: rtems-docs/bsp_howto/miscellanous_support.rst @ 9aafb39

4.115
Last change on this file since 9aafb39 was f29b7c1c, checked in by Joel Sherrill <joel@…>, on 10/28/16 at 01:01:18

bsp_howto: Fix code-block markup

  • Property mode set to 100644
File size: 15.7 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3
4.. COMMENT: COPYRIGHT (c) 1988-2002.
5.. COMMENT: On-Line Applications Research Corporation (OAR).
6.. COMMENT: All rights reserved.
7
8Miscellaneous Support Files
9###########################
10
11GCC Compiler Specifications File
12================================
13
14The file ``bsp_specs`` defines the start files and libraries that are always
15used with this BSP.  The format of this file is admittedly cryptic and this
16document will make no attempt to explain it completely.  Below is the
17``bsp_specs`` file from the PowerPC psim BSP:
18
19.. code-block:: c
20
21    %rename endfile old_endfile
22    %rename startfile old_startfile
23    %rename link old_link
24    *startfile:
25    %{!qrtems: %(old_startfile)} \
26    %{!nostdlib: %{qrtems: ecrti%O%s rtems_crti%O%s crtbegin.o%s start.o%s}}
27    *link:
28    %{!qrtems: %(old_link)} %{qrtems: -Qy -dp -Bstatic -e _start -u __vectors}
29    *endfile:
30    %{!qrtems: %(old_endfile)} %{qrtems: crtend.o%s ecrtn.o%s}
31
32The first section of this file renames the built-in definition of some
33specification variables so they can be augmented without embedded their
34original definition.  The subsequent sections specify what behavior is expected
35when the ``-qrtems`` option is specified.
36
37The ``*startfile`` section specifies that the BSP specific file ``start.o``
38will be used instead of ``crt0.o``.  In addition, various EABI support files
39(``ecrti.o`` etc.) will be linked in with the executable.
40
41The ``*link`` section adds some arguments to the linker when it is invoked by
42GCC to link an application for this BSP.
43
44The format of this file is specific to the GNU Compiler Suite.  The argument
45used to override and extend the compiler built-in specifications is available
46in all recent GCC versions.  The ``-specs`` option is present in all ``egcs``
47distributions and ``gcc`` distributions starting with version 2.8.0.
48
49README Files
50============
51
52Most BSPs provide one or more ``README`` files.  Generally, there is a
53``README`` file at the top of the BSP source.  This file describes the board
54and its hardware configuration, provides vendor information, local
55configuration information, information on downloading code to the board,
56debugging, etc..  The intent of this file is to help someone begin to use the
57BSP faster.
58
59A ``README`` file in a BSP subdirectory typically explains something about the
60contents of that subdirectory in greater detail.  For example, it may list the
61documentation available for a particular peripheral controller and how to
62obtain that documentation.  It may also explain some particularly cryptic part
63of the software in that directory or provide rationale on the implementation.
64
65times
66=====
67
68This file contains the results of the RTEMS Timing Test Suite.  It is in a
69standard format so that results from one BSP can be easily compared with those
70of another target board.
71
72If a BSP supports multiple variants, then there may be multiple ``times``
73files.  Usually these are named ``times.VARIANTn``.
74
75Tools Subdirectory
76==================
77
78Some BSPs provide additional tools that aid in using the target board.  These
79tools run on the development host and are built as part of building the BSP.
80Most common is a script to automate running the RTEMS Test Suites on the BSP.
81Examples of this include:
82
83- ``powerpc/psim`` includes scripts to ease use of the simulator
84
85- ``m68k/mvme162`` includes a utility to download across the VMEbus into target
86  memory if the host is a VMEbus board in the same chasis.
87
88bsp.h Include File
89==================
90
91The file ``include/bsp.h`` contains prototypes and definitions specific to this
92board.  Every BSP is required to provide a ``bsp.h``.  The best approach to
93writing a ``bsp.h`` is copying an existing one as a starting point.
94
95Many ``bsp.h`` files provide prototypes of variables defined in the linker
96script (``linkcmds``).
97
98tm27.h Include File
99===================
100
101The ``tm27`` test from the RTEMS Timing Test Suite is designed to measure the
102length of time required to vector to and return from an interrupt handler. This
103test requires some help from the BSP to know how to cause and manipulate the
104interrupt source used for this measurement.  The following is a list of these:
105
106- ``MUST_WAIT_FOR_INTERRUPT`` - modifies behavior of ``tm27``.
107
108- ``Install_tm27_vector`` - installs the interrupt service routine for the
109  Interrupt Benchmark Test (``tm27``).
110
111- ``Cause_tm27_intr`` - generates the interrupt source used in the Interrupt
112  Benchmark Test (``tm27``).
113
114- ``Clear_tm27_intr`` - clears the interrupt source used in the Interrupt
115  Benchmark Test (``tm27``).
116
117- ``Lower_tm27_intr`` - lowers the interrupt mask so the interrupt source used
118  in the Interrupt Benchmark Test (``tm27``) can generate a nested interrupt.
119
120All members of the Timing Test Suite are designed to run *WITHOUT* the Clock
121Device Driver installed.  This increases the predictability of the tests'
122execution as well as avoids occassionally including the overhead of a clock
123tick interrupt in the time reported.  Because of this it is sometimes possible
124to use the clock tick interrupt source as the source of this test interrupt.
125On other architectures, it is possible to directly force an interrupt to occur.
126
127Calling Overhead File
128=====================
129
130The file ``include/coverhd.h`` contains the overhead associated with invoking
131each directive.  This overhead consists of the execution time required to
132package the parameters as well as to execute the "jump to subroutine" and
133"return from subroutine" sequence.  The intent of this file is to help separate
134the calling overhead from the actual execution time of a directive.  This file
135is only used by the tests in the RTEMS Timing Test Suite.
136
137The numbers in this file are obtained by running the "Timer
138Overhead"``tmoverhd`` test.  The numbers in this file may be 0 and no overhead
139is subtracted from the directive execution times reported by the Timing Suite.
140
141There is a shared implementation of ``coverhd.h`` which sets all of the
142overhead constants to 0.  On faster processors, this is usually the best
143alternative for the BSP as the calling overhead is extremely small.  This file
144is located at:
145
146.. code-block:: c
147
148    c/src/lib/libbsp/shared/include/coverhd.h
149
150sbrk() Implementation
151=====================
152
153Although nearly all BSPs give all possible memory to the C Program Heap at
154initialization, it is possible for a BSP to configure the initial size of the
155heap small and let it grow on demand.  If the BSP wants to dynamically extend
156the heap used by the C Library memory allocation routines (i.e. ``malloc``
157family), then the``sbrk`` routine must be functional.  The following is the
158prototype for this routine:
159
160.. code-block:: c
161
162    void * sbrk(size_t increment)
163
164The ``increment`` amount is based upon the ``sbrk_amount`` parameter passed to
165the ``bsp_libc_init`` during system initialization.
166
167.. index:: CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
168
169If your BSP does not want to support dynamic heap extension, then you do not
170have to do anything special.  However, if you want to support ``sbrk``, you
171must provide an implementation of this method and define
172``CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK`` in ``bsp.h``.  This informs
173``rtems/confdefs.h`` to configure the Malloc Family Extensions which support
174``sbrk``.
175
176bsp_fatal_extension() - Cleanup the Hardware
177============================================
178
179The ``bsp_fatal_extension()`` is an optional BSP specific initial extension
180invoked once a fatal system state is reached.  Most of the BSPs use the same
181shared version of ``bsp_fatal_extension()`` that does nothing or performs a
182system reset.  This implementation is located in the following file:
183
184.. code-block:: c
185
186    c/src/lib/libbsp/shared/bspclean.c
187
188The ``bsp_fatal_extension()`` routine can be used to return to a ROM monitor,
189insure that interrupt sources are disabled, etc..  This routine is the last
190place to ensure a clean shutdown of the hardware.  The fatal source, internal
191error indicator, and the fatal code arguments are available to evaluate the
192fatal condition.  All of the non-fatal shutdown sequences ultimately pass their
193exit status to ``rtems_shutdown_executive`` and this is what is passed to this
194routine in case the fatal source is ``RTEMS_FATAL_SOURCE_EXIT``.
195
196On some BSPs, it prints a message indicating that the application completed
197execution and waits for the user to press a key before resetting the board.
198The PowerPC/gen83xx and PowerPC/gen5200 BSPs do this when they are built to
199support the FreeScale evaluation boards.  This is convenient when using the
200boards in a development environment and may be disabled for production use.
201
202Configuration Macros
203====================
204
205Each BSP can define macros in bsp.h which alter some of the the default
206configuration parameters in ``rtems/confdefs.h``.  This section describes those
207macros:
208
209.. index:: CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
210
211- ``CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK`` must be defined if the BSP has proper
212  support for ``sbrk``.  This is discussed in more detail in the previous
213  section.
214
215.. index:: BSP_IDLE_TASK_BODY
216
217- ``BSP_IDLE_TASK_BODY`` may be defined to the entry point of a BSP specific
218  IDLE thread implementation.  This may be overridden if the application
219  provides its own IDLE task implementation.
220
221.. index:: BSP_IDLE_TASK_STACK_SIZE
222
223- ``BSP_IDLE_TASK_STACK_SIZE`` may be defined to the desired default stack size
224  for the IDLE task as recommended when using this BSP.
225
226.. index:: BSP_INTERRUPT_STACK_SIZE
227
228- ``BSP_INTERRUPT_STACK_SIZE`` may be defined to the desired default interrupt
229  stack size as recommended when using this BSP.  This is sometimes required
230  when the BSP developer has knowledge of stack intensive interrupt handlers.
231
232.. index:: BSP_ZERO_WORKSPACE_AUTOMATICALLY
233
234- ``BSP_ZERO_WORKSPACE_AUTOMATICALLY`` is defined when the BSP requires that
235  RTEMS zero out the RTEMS C Program Heap at initialization.  If the memory is
236  already zeroed out by a test sequence or boot ROM, then the boot time can be
237  reduced by not zeroing memory twice.
238
239.. index:: BSP_DEFAULT_UNIFIED_WORK_AREAS
240
241- ``BSP_DEFAULT_UNIFIED_WORK_AREAS`` is defined when the BSP recommends that
242  the unified work areas configuration should always be used.  This is
243  desirable when the BSP is known to always have very little RAM and thus
244  saving memory by any means is desirable.
245
246set_vector() - Install an Interrupt Vector
247==========================================
248
249On targets with Simple Vectored Interrupts, the BSP must provide an
250implementation of the ``set_vector`` routine.  This routine is responsible for
251installing an interrupt vector.  It invokes the support routines necessary to
252install an interrupt handler as either a "raw" or an RTEMS interrupt handler.
253Raw handlers bypass the RTEMS interrupt structure and are responsible for
254saving and restoring all their own registers.  Raw handlers are useful for
255handling traps, debug vectors, etc.
256
257The ``set_vector`` routine is a central place to perform interrupt controller
258manipulation and encapsulate that information.  It is usually implemented as
259follows:
260
261.. code-block:: c
262
263    rtems_isr_entry set_vector(                 /* returns old vector */
264      rtems_isr_entry handler,                  /* isr routine        */
265      rtems_vector_number vector,               /* vector number      */
266      int                 type                  /* RTEMS or RAW intr  */
267    )
268    {
269      if the type is RAW
270        install the raw vector
271      else
272        use rtems_interrupt_catch to install the vector
273      perform any interrupt controller necessary to unmask the interrupt source
274      return the previous handler
275    }
276
277.. note::
278
279    The i386, PowerPC and ARM ports use a Programmable Interrupt Controller
280    model which does not require the BSP to implement ``set_vector``.  BSPs for
281    these architectures must provide a different set of support routines.
282
283Interrupt Delay Profiling
284=========================
285
286The RTEMS profiling needs support by the BSP for the interrupt delay times.  In
287case profiling is enabled via the RTEMS build configuration option
288``--enable-profiling`` (in this case the pre-processor symbol
289``RTEMS_PROFILING`` is defined) a BSP may provide data for the interrupt delay
290times.  The BSP can feed interrupt delay times with the
291``_Profiling_Update_max_interrupt_delay()`` function (``#include
292<rtems/score/profiling.h>``).  For an example please have a look at
293``c/src/lib/libbsp/sparc/leon3/clock/ckinit.c``.
294
295Programmable Interrupt Controller API
296=====================================
297
298A BSP can use the PIC API to install Interrupt Service Routines through a set
299of generic methods. In order to do so, the header files
300libbsp/shared/include/irq-generic.h and ``libbsp/shared/include/irq-info.h``
301must be included by the bsp specific irq.h file present in the include/
302directory. The irq.h acts as a BSP interrupt support configuration file which
303is used to define some important MACROS. It contains the declarations for any
304required global functions like bsp_interrupt_dispatch(). Thus later on, every
305call to the PIC interface requires including ``<bsp/irq.h>``
306
307The generic interrupt handler table is intitalized by invoking the
308``bsp_interrupt_initialize()`` method from bsp_start() in the bspstart.c file
309which sets up this table to store the ISR addresses, whose size is based on the
310definition of macros, ``BSP_INTERRUPT_VECTOR_MIN`` and
311``BSP_INTERRUPT_VECTOR_MAX`` in include/bsp.h
312
313For the generic handler table to properly function, some bsp specific code is
314required, that should be present in ``irq/irq.c``. The bsp-specific functions
315required to be writen by the BSP developer are :
316
317.. index:: bsp_interrupt_facility_initialize()
318
319- ``bsp_interrupt_facility_initialize()`` contains bsp specific interrupt
320  initialization code(Clear Pending interrupts by modifying registers, etc.).
321  This method is called from ``bsp_interrupt_initialize()`` internally while
322  setting up the table.
323
324.. index:: bsp_interrupt_handler_default()
325
326- ``bsp_interrupt_handler_default()`` acts as a fallback handler when no ISR
327  address has been provided corresponding to a vector in the table.
328
329.. index:: bsp_interrupt_dispatch()
330
331- ``bsp_interrupt_dispatch()`` service the ISR by handling any bsp specific
332  code & calling the generic method ``bsp_interrupt_handler_dispatch()`` which
333  in turn services the interrupt by running the ISR after looking it up in the
334  table. It acts as an entry to the interrupt switchboard, since the bsp
335  branches to this function at the time of occurrence of an interrupt.
336
337.. index:: bsp_interrupt_vector_enable()
338
339- ``bsp_interrupt_vector_enable()`` enables interrupts and is called in
340  irq-generic.c while setting up the table.
341
342.. index:: bsp_interrupt_vector_disable()
343
344- ``bsp_interrupt_vector_disable()`` disables interrupts and is called in
345  irq-generic.c while setting up the table & during other important parts.
346
347An interrupt handler is installed or removed with the help of the following functions :
348
349.. code-block:: c
350
351    rtems_status_code rtems_interrupt_handler_install(   /* returns status code */
352      rtems_vector_number     vector,                    /* interrupt vector */
353      const char             *info,                      /* custom identification text */
354      rtems_option            options,                   /* Type of Interrupt */
355      rtems_interrupt_handler handler,                   /* interrupt handler */
356      void                   *arg                        /* parameter to be passed
357                                                            to handler at the time of
358                                                            invocation */
359    )
360    rtems_status_code rtems_interrupt_handler_remove(   /* returns status code */
361      rtems_vector_number     vector,                   /* interrupt vector */
362      rtems_interrupt_handler handler,                  /* interrupt handler */
363      void                   *arg                       /* parameter to be passed to handler */
364    )
Note: See TracBrowser for help on using the repository browser.