source: rtems/c/src/lib/libbsp/shared/src/stackalloc.c @ ed67d93

4.115
Last change on this file since ed67d93 was ed67d93, checked in by Sebastian Huber <sebastian.huber@…>, on 04/26/12 at 08:03:38

bsps/stackalloc: Add initialization hook

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup bsp_shared
5 *
6 * @brief Stack initialization, allocation and free functions.
7 */
8
9/*
10 * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Obere Lagerstr. 30
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.com/license/LICENSE.
21 */
22
23#include <bsp/stackalloc.h>
24
25#include <rtems.h>
26#include <rtems/score/wkspace.h>
27
28#include <bsp/linker-symbols.h>
29
30static Heap_Control bsp_stack_heap;
31
32void bsp_stack_allocate_init(size_t stack_space_size)
33{
34  _Heap_Initialize(
35    &bsp_stack_heap,
36    bsp_section_stack_begin,
37    (uintptr_t) bsp_section_stack_size,
38    CPU_STACK_ALIGNMENT
39  );
40}
41
42void *bsp_stack_allocate(size_t size)
43{
44  void *stack = NULL;
45
46  if (bsp_stack_heap.area_begin != 0) {
47    stack = _Heap_Allocate(&bsp_stack_heap, size);
48  }
49
50  if (stack == NULL) {
51    stack = _Workspace_Allocate(size);
52  }
53
54  return stack;
55}
56
57void bsp_stack_free(void *stack)
58{
59  bool ok = _Heap_Free(&bsp_stack_heap, stack);
60
61  if (!ok) {
62    _Workspace_Free(stack);
63  }
64}
Note: See TracBrowser for help on using the repository browser.