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

4.115
Last change on this file since 3c6d7ae was 3c6d7ae, checked in by Sebastian Huber <sebastian.huber@…>, on 04/24/12 at 12:00:54

bsps/stackalloc: Use stack section symbols

  • Property mode set to 100644
File size: 1.3 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
30#define BSP_STACK_MAGIC 0xdeadbeef
31
32static Heap_Control bsp_stack_heap = {
33  .page_size = BSP_STACK_MAGIC
34};
35
36void *bsp_stack_allocate(size_t size)
37{
38  void *stack = NULL;
39
40  if (bsp_stack_heap.page_size == BSP_STACK_MAGIC) {
41    uintptr_t rv = _Heap_Initialize(
42      &bsp_stack_heap,
43      bsp_section_stack_begin,
44      (uintptr_t) bsp_section_stack_size,
45      CPU_STACK_ALIGNMENT
46    );
47    if (rv == 0) {
48      return NULL;
49    }
50  }
51
52  stack = _Heap_Allocate(&bsp_stack_heap, size);
53
54  if (stack == NULL) {
55    stack = _Workspace_Allocate(size);
56  }
57
58  return stack;
59}
60
61void bsp_stack_free(void *stack)
62{
63  bool ok = _Heap_Free(&bsp_stack_heap, stack);
64
65  if (!ok) {
66    _Workspace_Free(stack);
67  }
68}
Note: See TracBrowser for help on using the repository browser.