source: rtems/bsps/shared/start/stackalloc.c @ 0a09ac58

5
Last change on this file since 0a09ac58 was 0a09ac58, checked in by Sebastian Huber <sebastian.huber@…>, on 04/13/18 at 07:14:56

bsps: Move stackalloc.c to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • 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-2013 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.org/license/LICENSE.
21 */
22
23#include <bsp/stackalloc.h>
24
25#include <rtems.h>
26#include <rtems/score/heapimpl.h>
27#include <rtems/score/wkspace.h>
28
29#include <bsp/linker-symbols.h>
30
31static Heap_Control bsp_stack_heap;
32
33void bsp_stack_allocate_init(size_t stack_space_size)
34{
35  _Heap_Initialize(
36    &bsp_stack_heap,
37    bsp_section_stack_begin,
38    (uintptr_t) bsp_section_stack_size,
39    CPU_STACK_ALIGNMENT
40  );
41}
42
43void *bsp_stack_allocate(size_t size)
44{
45  void *stack = NULL;
46
47  if (bsp_stack_heap.area_begin != 0) {
48    stack = _Heap_Allocate(&bsp_stack_heap, size);
49  }
50
51  if (stack == NULL) {
52    stack = _Workspace_Allocate(size);
53  }
54
55  return stack;
56}
57
58void bsp_stack_free(void *stack)
59{
60  bool ok = _Heap_Free(&bsp_stack_heap, stack);
61
62  if (!ok) {
63    _Workspace_Free(stack);
64  }
65}
Note: See TracBrowser for help on using the repository browser.