RTEMS
wkspaceinitone.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 
11 /*
12  * Copyright (C) 2012, 2020 embedded brains GmbH (http://www.embedded-brains.de)
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef _RTEMS_SCORE_WKSPACEINITONE_H
37 #define _RTEMS_SCORE_WKSPACEINITONE_H
38 
39 #include <rtems/score/wkspace.h>
40 #include <rtems/score/assert.h>
41 #include <rtems/score/heapimpl.h>
42 #include <rtems/score/interr.h>
43 #include <rtems/score/memory.h>
44 #include <rtems/config.h>
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
56 RTEMS_INLINE_ROUTINE void _Workspace_Initialize_with_one_area( void )
57 {
58  uintptr_t page_size;
59  uintptr_t wkspace_size;
60  uintptr_t wkspace_size_with_overhead;
61  uintptr_t available_size;
62 
63  page_size = CPU_HEAP_ALIGNMENT;
65  wkspace_size_with_overhead = wkspace_size + _Heap_Area_overhead( page_size );
66 
67  if ( wkspace_size < wkspace_size_with_overhead ) {
68  const Memory_Information *mem;
69  Memory_Area *area;
70  uintptr_t free_size;
71  uintptr_t size;
72 
73  mem = _Memory_Get();
74  _Assert( _Memory_Get_count( mem ) == 1 );
75 
76  area = _Memory_Get_area( mem, 0 );
77  free_size = _Memory_Get_free_size( area );
78 
80  size = free_size;
81  } else {
82  size = wkspace_size_with_overhead;
83  }
84 
85  available_size = _Heap_Initialize(
87  _Memory_Get_free_begin( area ),
88  size,
89  page_size
90  );
91 
92  _Memory_Consume( area, size );
93  } else {
94  /* An unsigned integer overflow happened */
95  available_size = 0;
96  }
97 
98  if ( wkspace_size > available_size ) {
99  _Internal_error( INTERNAL_ERROR_TOO_LITTLE_WORKSPACE );
100  }
101 
103 }
104 
107 #ifdef __cplusplus
108 }
109 #endif
110 
111 #endif /* _RTEMS_SCORE_WKSPACEINITONE_H */
Constants and Prototypes Related to the Internal Error Handler.
static __inline__ size_t _Memory_Get_count(const Memory_Information *information)
Get the memory area count.
Definition: memory.h:115
Memory Handler API.
static __inline__ Memory_Area * _Memory_Get_area(const Memory_Information *information, size_t index)
Get a memory area by index.
Definition: memory.h:130
Heap Handler Implementation.
The memory information.
Definition: memory.h:80
static __inline__ uintptr_t _Memory_Get_free_size(const Memory_Area *area)
Get the size of the free memory area of the memory area.
Definition: memory.h:272
RTEMS_INLINE_ROUTINE void _Heap_Protection_set_delayed_free_fraction(Heap_Control *heap, uintptr_t fraction)
Sets the fraction of delayed free blocks that is actually freed during memory shortage.
Definition: heapimpl.h:431
Information for the Assert Handler.
The memory area description.
Definition: memory.h:60
Heap_Control _Workspace_Area
Executive workspace control.
Definition: wkspace.c:43
#define rtems_configuration_get_unified_work_area()
Returns true, if the RTEMS Workspace and C Program Heap are unified, otherwise returns false...
Definition: config.h:288
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:207
#define CPU_HEAP_ALIGNMENT
Definition: cpu.h:755
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Area_overhead(uintptr_t page_size)
Returns the worst case overhead to manage a memory area.
Definition: heap.h:446
static __inline__ void * _Memory_Get_free_begin(const Memory_Area *area)
Get the begin of the free area of the memory area.
Definition: memory.h:246
void _Internal_error(Internal_errors_Core_list core_error) RTEMS_NO_RETURN
Terminates the system with an INTERNAL_ERROR_CORE fatal source and the specified core error code...
Definition: interr.c:51
static __inline__ void _Memory_Consume(Memory_Area *area, uintptr_t consume)
Consume the specified size from the free memory area of the memory area.
Definition: memory.h:285
#define RTEMS_INLINE_ROUTINE
Gives a hint to the compiler in a function declaration to inline this function.
Definition: basedefs.h:683
const Memory_Information * _Memory_Get(void)
Return the memory information of this platform.
#define rtems_configuration_get_work_space_size()
Returns the RTEMS Workspace size in bytes configured for this application.
Definition: config.h:333
Information Related to the RAM Workspace.
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100