source: rtems/cpukit/score/src/wkspace.c @ f2f63d1

4.115
Last change on this file since f2f63d1 was f2f63d1, checked in by Alex Ivanov <alexivanov97@…>, on 11/29/12 at 23:14:28

score misc: Score misc: Clean up Doxygen #7 (GCI 2012)

This patch is a task from GCI 2012 which improves the Doxygen
comments in the RTEMS source.

https://google-melange.appspot.com/gci/task/view/google/gci2012/7986214

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Workspace Handler Support
5 *  @ingroup ScoreWorkspace
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2009.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/system.h>
22#include <rtems/config.h>
23#include <rtems/score/wkspace.h>
24#include <rtems/score/interr.h>
25
26#include <string.h>  /* for memset */
27
28/* #define DEBUG_WORKSPACE */
29#if defined(DEBUG_WORKSPACE)
30  #include <rtems/bspIo.h>
31#endif
32
33void _Workspace_Handler_initialization(
34  Heap_Area *areas,
35  size_t area_count,
36  Heap_Initialization_or_extend_handler extend
37)
38{
39  Heap_Initialization_or_extend_handler init_or_extend = _Heap_Initialize;
40  uintptr_t remaining = rtems_configuration_get_work_space_size();
41  bool do_zero = rtems_configuration_get_do_zero_of_workspace();
42  bool unified = rtems_configuration_get_unified_work_area();
43  uintptr_t page_size = CPU_HEAP_ALIGNMENT;
44  uintptr_t overhead = _Heap_Area_overhead( page_size );
45  size_t i;
46
47  for (i = 0; i < area_count; ++i) {
48    Heap_Area *area = &areas [i];
49
50    if ( do_zero ) {
51      memset( area->begin, 0, area->size );
52    }
53
54    if ( area->size > overhead ) {
55      uintptr_t space_available;
56      uintptr_t size;
57
58      if ( unified ) {
59        size = area->size;
60      } else {
61        if ( remaining > 0 ) {
62          size = remaining < area->size - overhead ?
63            remaining + overhead : area->size;
64        } else {
65          size = 0;
66        }
67      }
68
69      space_available = (*init_or_extend)(
70        &_Workspace_Area,
71        area->begin,
72        size,
73        page_size
74      );
75
76      area->begin = (char *) area->begin + size;
77      area->size -= size;
78
79      if ( space_available < remaining ) {
80        remaining -= space_available;
81      } else {
82        remaining = 0;
83      }
84
85      init_or_extend = extend;
86    }
87  }
88
89  if ( remaining > 0 ) {
90    _Internal_error_Occurred(
91      INTERNAL_ERROR_CORE,
92      true,
93      INTERNAL_ERROR_TOO_LITTLE_WORKSPACE
94    );
95  }
96}
97
98void *_Workspace_Allocate(
99  size_t   size
100)
101{
102  void *memory;
103
104  memory = _Heap_Allocate( &_Workspace_Area, size );
105  #if defined(DEBUG_WORKSPACE)
106    printk(
107      "Workspace_Allocate(%d) from %p/%p -> %p\n",
108      size,
109      __builtin_return_address( 0 ),
110      __builtin_return_address( 1 ),
111      memory
112    );
113  #endif
114  return memory;
115}
116
117/*
118 *  _Workspace_Free
119 */
120void _Workspace_Free(
121  void *block
122)
123{
124  #if defined(DEBUG_WORKSPACE)
125    printk(
126      "Workspace_Free(%p) from %p/%p\n",
127      block,
128      __builtin_return_address( 0 ),
129      __builtin_return_address( 1 )
130    );
131  #endif
132  _Heap_Free( &_Workspace_Area, block );
133}
134
135void *_Workspace_Allocate_or_fatal_error(
136  size_t      size
137)
138{
139  void *memory;
140
141  memory = _Heap_Allocate( &_Workspace_Area, size );
142  #if defined(DEBUG_WORKSPACE)
143    printk(
144      "Workspace_Allocate_or_fatal_error(%d) from %p/%p -> %p\n",
145      size,
146      __builtin_return_address( 0 ),
147      __builtin_return_address( 1 ),
148      memory
149    );
150  #endif
151
152  if ( memory == NULL )
153    _Internal_error_Occurred(
154      INTERNAL_ERROR_CORE,
155      true,
156      INTERNAL_ERROR_WORKSPACE_ALLOCATION
157    );
158
159  return memory;
160}
Note: See TracBrowser for help on using the repository browser.