source: rtems-docs/bsp_howto/miscellanous_support.rst @ d389819

4.115
Last change on this file since d389819 was d389819, checked in by Amar Takhar <amar@…>, on 01/18/16 at 05:37:40

Convert all Unicode to ASCII(128)

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