summaryrefslogtreecommitdiffstats
path: root/c-user/board_support_packages.rst
blob: 9e5863288b6f103618c0ae0ca445dee265843a0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
.. comment SPDX-License-Identifier: CC-BY-SA-4.0

.. COMMENT: COPYRIGHT (c) 1988-2008.
.. COMMENT: On-Line Applications Research Corporation (OAR).
.. COMMENT: All rights reserved.

Board Support Packages
**********************

.. index:: Board Support Packages
.. index:: BSPs

Introduction
============
.. index:: BSP, definition

A board support package (BSP) is a collection of user-provided facilities which
interface RTEMS and an application with a specific hardware platform.  These
facilities may include hardware initialization, device drivers, user
extensions, and a Multiprocessor Communications Interface (MPCI).  However, a
minimal BSP need only support processor reset and initialization and, if
needed, a clock tick.

Reset and Initialization
========================

An RTEMS based application is initiated or re-initiated when the processor is
reset.  This initialization code is responsible for preparing the target
platform for the RTEMS application.  Although the exact actions performed by
the initialization code are highly processor and target dependent, the logical
functionality of these actions are similar across a variety of processors and
target platforms.

Normally, the BSP and some of the application initialization is intertwined in
the RTEMS initialization sequence controlled by the shared function
``boot_card()``.

The reset application initialization code is executed first when the processor
is reset.  All of the hardware must be initialized to a quiescent state by this
software before initializing RTEMS.  When in quiescent state, devices do not
generate any interrupts or require any servicing by the application.  Some of
the hardware components may be initialized in this code as well as any
application initialization that does not involve calls to RTEMS directives.

The processor's Interrupt Vector Table which will be used by the application
may need to be set to the required value by the reset application
initialization code.  Because interrupts are enabled automatically by RTEMS as
part of the context switch to the first task, the Interrupt Vector Table MUST
be set before this directive is invoked to ensure correct interrupt vectoring.
The processor's Interrupt Vector Table must be accessible by RTEMS as it will
be modified by the when installing user Interrupt Service Routines (ISRs) On
some CPUs, RTEMS installs it's own Interrupt Vector Table as part of
initialization and thus these requirements are met automatically.  The reset
code which is executed before the call to any RTEMS initialization routines has
the following requirements:

- Must not make any blocking RTEMS directive calls.

- If the processor supports multiple privilege levels, must leave the processor
  in the most privileged, or supervisory, state.

- Must allocate a stack of sufficient size to execute the initialization and
  shutdown of the system.  This stack area will NOT be used by any task once
  the system is initialized.  This stack is often reserved via the linker
  script or in the assembly language start up file.

- Must initialize the stack pointer for the initialization process to that
  allocated.

- Must initialize the processor's Interrupt Vector Table.

- Must disable all maskable interrupts.

- If the processor supports a separate interrupt stack, must allocate the
  interrupt stack and initialize the interrupt stack pointer.

At the end of the initialization sequence, RTEMS does not return to the BSP
initialization code, but instead context switches to the highest priority task
to begin application execution.  This task is typically a User Initialization
Task which is responsible for performing both local and global application
initialization which is dependent on RTEMS facilities.  It is also responsible
for initializing any higher level RTEMS services the application uses such as
networking and blocking device drivers.

Interrupt Stack Requirements
----------------------------

The worst-case stack usage by interrupt service routines must be taken into
account when designing an application.  If the processor supports interrupt
nesting, the stack usage must include the deepest nest level.  The worst-case
stack usage must account for the following requirements:

- Processor's interrupt stack frame

- Processor's subroutine call stack frame

- RTEMS system calls

- Registers saved on stack

- Application subroutine calls

The size of the interrupt stack must be greater than or equal to the confugured
minimum stack size.

Processors with a Separate Interrupt Stack
------------------------------------------

Some processors support a separate stack for interrupts.  When an interrupt is
vectored and the interrupt is not nested, the processor will automatically
switch from the current stack to the interrupt stack.  The size of this stack
is based solely on the worst-case stack usage by interrupt service routines.

The dedicated interrupt stack for the entire application on some architectures
is supplied and initialized by the reset and initialization code of the user's
Board Support Package.  Whether allocated and initialized by the BSP or RTEMS,
since all ISRs use this stack, the stack size must take into account the worst
case stack usage by any combination of nested ISRs.

Processors Without a Separate Interrupt Stack
---------------------------------------------

Some processors do not support a separate stack for interrupts.  In this case,
without special assistance every task's stack must include enough space to
handle the task's worst-case stack usage as well as the worst-case interrupt
stack usage.  This is necessary because the worst-case interrupt nesting could
occur while any task is executing.

On many processors without dedicated hardware managed interrupt stacks, RTEMS
manages a dedicated interrupt stack in software.  If this capability is
supported on a CPU, then it is logically equivalent to the processor supporting
a separate interrupt stack in hardware.

Device Drivers
==============

Device drivers consist of control software for special peripheral devices and
provide a logical interface for the application developer.  The RTEMS I/O
manager provides directives which allow applications to access these device
drivers in a consistent fashion.  A Board Support Package may include device
drivers to access the hardware on the target platform.  These devices typically
include serial and parallel ports, counter/timer peripherals, real-time clocks,
disk interfaces, and network controllers.

For more information on device drivers, refer to the
I/O Manager chapter.

Clock Tick Device Driver
------------------------

Most RTEMS applications will include a clock tick device driver which invokes
a clock tick directive at regular intervals.  The clock tick is
necessary if the application is to utilize timeslicing, the clock manager, the
timer manager, the rate monotonic manager, or the timeout option on blocking
directives.

The clock tick is usually provided as an interrupt from a counter/timer or a
real-time clock device.  When a counter/timer is used to provide the clock
tick, the device is typically programmed to operate in continuous mode.  This
mode selection causes the device to automatically reload the initial count and
continue the countdown without programmer intervention.  This reduces the
overhead required to manipulate the counter/timer in the clock tick ISR and
increases the accuracy of tick occurrences.  The initial count can be based on
the microseconds_per_tick field in the RTEMS Configuration Table.  An alternate
approach is to set the initial count for a fixed time period (such as one
millisecond) and have the ISR invoke a clock tick directive on the configured
``microseconds_per_tick`` boundaries.  Obviously, this can induce some error if
the configured ``microseconds_per_tick`` is not evenly divisible by the chosen
clock interrupt quantum.

It is important to note that the interval between clock ticks directly impacts
the granularity of RTEMS timing operations.  In addition, the frequency of
clock ticks is an important factor in the overall level of system overhead.  A
high clock tick frequency results in less processor time being available for
task execution due to the increased number of clock tick ISRs.

User Extensions
===============

RTEMS allows the application developer to augment selected features by invoking
user-supplied extension routines when the following system events occur:

- Task creation

- Task initiation

- Task reinitiation

- Task deletion

- Task context switch

- Post task context switch

- Task begin

- Task exits

- Fatal error detection

User extensions can be used to implement a wide variety of functions including
execution profiling, non-standard coprocessor support, debug support, and error
detection and recovery.  For example, the context of a non-standard numeric
coprocessor may be maintained via the user extensions.  In this example, the
task creation and deletion extensions are responsible for allocating and
deallocating the context area, the task initiation and reinitiation extensions
would be responsible for priming the context area, and the task context switch
extension would save and restore the context of the device.

For more information on user extensions, refer to :ref:`User Extensions Manager`.

Multiprocessor Communications Interface (MPCI)
==============================================

RTEMS requires that an MPCI layer be provided when a multiple node application
is developed.  This MPCI layer must provide an efficient and reliable
communications mechanism between the multiple nodes.  Tasks on different nodes
communicate and synchronize with one another via the MPCI.  Each MPCI layer
must be tailored to support the architecture of the target platform.

For more information on the MPCI, refer to the Multiprocessing Manager chapter.

Tightly-Coupled Systems
-----------------------

A tightly-coupled system is a multiprocessor configuration in which the
processors communicate solely via shared global memory.  The MPCI can simply
place the RTEMS packets in the shared memory space.  The two primary
considerations when designing an MPCI for a tightly-coupled system are data
consistency and informing another node of a packet.

The data consistency problem may be solved using atomic "test and set"
operations to provide a "lock" in the shared memory.  It is important to
minimize the length of time any particular processor locks a shared data
structure.

The problem of informing another node of a packet can be addressed using one of
two techniques.  The first technique is to use an interprocessor interrupt
capability to cause an interrupt on the receiving node.  This technique
requires that special support hardware be provided by either the processor
itself or the target platform.  The second technique is to have a node poll for
arrival of packets.  The drawback to this technique is the overhead associated
with polling.

Loosely-Coupled Systems
-----------------------

A loosely-coupled system is a multiprocessor configuration in which the
processors communicate via some type of communications link which is not shared
global memory.  The MPCI sends the RTEMS packets across the communications link
to the destination node.  The characteristics of the communications link vary
widely and have a significant impact on the MPCI layer.  For example, the
bandwidth of the communications link has an obvious impact on the maximum MPCI
throughput.

The characteristics of a shared network, such as Ethernet, lend themselves to
supporting an MPCI layer.  These networks provide both the point-to-point and
broadcast capabilities which are expected by RTEMS.

Systems with Mixed Coupling
---------------------------

A mixed-coupling system is a multiprocessor configuration in which the
processors communicate via both shared memory and communications links.  A
unique characteristic of mixed-coupling systems is that a node may not have
access to all communication methods.  There may be multiple shared memory areas
and communication links.  Therefore, one of the primary functions of the MPCI
layer is to efficiently route RTEMS packets between nodes.  This routing may be
based on numerous algorithms. In addition, the router may provide alternate
communications paths in the event of an overload or a partial failure.

Heterogeneous Systems
---------------------

Designing an MPCI layer for a heterogeneous system requires special
considerations by the developer.  RTEMS is designed to eliminate many of the
problems associated with sharing data in a heterogeneous environment.  The MPCI
layer need only address the representation of thirty-two (32) bit unsigned
quantities.

For more information on supporting a heterogeneous system, refer the Supporting
Heterogeneous Environments in the Multiprocessing Manager chapter.