RTEMS 6.1-rc1
wkspaceinitmulti.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * Copyright (C) 2012, 2020 embedded brains GmbH & Co. KG
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _RTEMS_SCORE_WKSPACEINITMULTI_H
38#define _RTEMS_SCORE_WKSPACEINITMULTI_H
39
40#include <rtems/score/wkspace.h>
42#include <rtems/score/interr.h>
43#include <rtems/score/memory.h>
44#include <rtems/config.h>
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
60static inline void _Workspace_Initialize_for_multiple_areas( void )
61{
62 const Memory_Information *mem;
64 uintptr_t remaining;
65 bool unified;
66 uintptr_t page_size;
67 uintptr_t overhead;
68 size_t i;
69
70 mem = _Memory_Get();
71 page_size = CPU_HEAP_ALIGNMENT;
73 init_or_extend = _Heap_Initialize;
75 overhead = _Heap_Area_overhead( page_size );
76
77 for ( i = 0; i < _Memory_Get_count( mem ); ++i ) {
78 Memory_Area *area;
79 uintptr_t free_size;
80
81 area = _Memory_Get_area( mem, i );
82 free_size = _Memory_Get_free_size( area );
83
84 if ( free_size > overhead ) {
85 uintptr_t space_available;
86 uintptr_t size;
87
88 if ( unified ) {
89 size = free_size;
90 } else {
91 if ( remaining > 0 ) {
92 size = remaining < free_size - overhead ?
93 remaining + overhead : free_size;
94 } else {
95 size = 0;
96 }
97 }
98
99 space_available = ( *init_or_extend )(
101 _Memory_Get_free_begin( area ),
102 size,
103 page_size
104 );
105
106 _Memory_Consume( area, size );
107
108 if ( space_available < remaining ) {
109 remaining -= space_available;
110 } else {
111 remaining = 0;
112 }
113
114 init_or_extend = _Heap_Extend;
115 }
116 }
117
118 if ( remaining > 0 ) {
119 _Internal_error( INTERNAL_ERROR_TOO_LITTLE_WORKSPACE );
120 }
121
122 _Heap_Protection_set_delayed_free_fraction( &_Workspace_Area, 1 );
123}
124
125#ifdef __cplusplus
126}
127#endif
128
129#endif /* _RTEMS_SCORE_WKSPACEINITMULTI_H */
This header file provides the interfaces of the Memory Handler.
#define rtems_configuration_get_unified_work_area()
Indicates if the RTEMS Workspace and C Program Heap are configured to be unified for this application...
Definition: config.h:768
#define rtems_configuration_get_work_space_size()
Gets the RTEMS Workspace size in bytes configured for this application.
Definition: config.h:838
uintptr_t _Heap_Extend(Heap_Control *heap, void *area_begin, uintptr_t area_size, uintptr_t unused)
Extends the memory available for the heap.
Definition: heapextend.c:139
uintptr_t(* Heap_Initialization_or_extend_handler)(Heap_Control *heap, void *area_begin, uintptr_t area_size, uintptr_t page_size_or_unused)
Heap initialization and extend handler type.
Definition: heap.h:373
uintptr_t _Heap_Initialize(Heap_Control *heap, void *area_begin, uintptr_t area_size, uintptr_t page_size)
Initializes the heap control block.
Definition: heap.c:225
RTEMS_NO_RETURN void _Internal_error(Internal_errors_Core_list core_error)
Terminates the system with an INTERNAL_ERROR_CORE fatal source and the specified core error code.
Definition: interr.c:61
const Memory_Information * _Memory_Get(void)
Return the memory information of this platform.
Definition: bspgetworkarea.c:227
Heap_Control _Workspace_Area
Executive workspace control.
Definition: wkspace.c:44
This header file provides interfaces of the Barrier Handler which are only used by the implementation...
This header file provides the interfaces of the Internal Error Handler.
This header file provides interfaces of the Workspace Handler which are only used by the implementati...
The memory area description.
Definition: memory.h:63
The memory information.
Definition: memory.h:83
unsigned size
Definition: tte.h:1