From 9364cf663fc1dcebcc1b87cc4cec7beae5490031 Mon Sep 17 00:00:00 2001 From: Thomas Doerfler Date: Fri, 17 Jul 2009 15:16:50 +0000 Subject: adding lpc24xx BSP parts --- c/src/lib/libbsp/shared/include/stackalloc.h | 45 ++++++++++++++++++ c/src/lib/libbsp/shared/src/stackalloc.c | 71 ++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 c/src/lib/libbsp/shared/include/stackalloc.h create mode 100644 c/src/lib/libbsp/shared/src/stackalloc.c (limited to 'c/src/lib/libbsp/shared') diff --git a/c/src/lib/libbsp/shared/include/stackalloc.h b/c/src/lib/libbsp/shared/include/stackalloc.h new file mode 100644 index 0000000000..e95f43591a --- /dev/null +++ b/c/src/lib/libbsp/shared/include/stackalloc.h @@ -0,0 +1,45 @@ +/** + * @file + * + * @ingroup bsp_shared + * + * @brief Stack initialization, allocation and free functions. + */ + +/* + * Copyright (c) 2009 + * embedded brains GmbH + * Obere Lagerstr. 30 + * D-82178 Puchheim + * Germany + * rtems@embedded-brains.de + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#ifndef LIBBSP_SHARED_STACK_ALLOC_H +#define LIBBSP_SHARED_STACK_ALLOC_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +void bsp_stack_initialize(void *start, intptr_t size); + +void *bsp_stack_allocate(uint32_t size); + +void bsp_stack_free(void *stack); + +#define CONFIGURE_TASK_STACK_ALLOCATOR bsp_stack_allocate + +#define CONFIGURE_TASK_STACK_DEALLOCATOR bsp_stack_free + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* LIBBSP_SHARED_STACK_ALLOC_H */ diff --git a/c/src/lib/libbsp/shared/src/stackalloc.c b/c/src/lib/libbsp/shared/src/stackalloc.c new file mode 100644 index 0000000000..31b7c14db3 --- /dev/null +++ b/c/src/lib/libbsp/shared/src/stackalloc.c @@ -0,0 +1,71 @@ +/** + * @file + * + * @ingroup bsp_shared + * + * @brief Stack initialization, allocation and free functions. + */ + +/* + * Copyright (c) 2009 + * embedded brains GmbH + * Obere Lagerstr. 30 + * D-82178 Puchheim + * Germany + * rtems@embedded-brains.de + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#include +#include + +#include + +#define BSP_STACK_MAGIC 0xdeadbeef + +static Heap_Control bsp_stack_heap = { + .page_size = BSP_STACK_MAGIC +}; + +void bsp_stack_initialize(void *start, intptr_t size) +{ + bsp_stack_heap.begin = start; + bsp_stack_heap.end = (void *) size; +} + +void *bsp_stack_allocate(uint32_t size) +{ + void *stack = NULL; + + if (bsp_stack_heap.page_size == BSP_STACK_MAGIC) { + uint32_t rv = _Heap_Initialize( + &bsp_stack_heap, + bsp_stack_heap.begin, + (intptr_t) bsp_stack_heap.end, + CPU_STACK_ALIGNMENT + ); + if (rv == 0) { + return NULL; + } + } + + stack = _Heap_Allocate(&bsp_stack_heap, (intptr_t) size); + + if (stack == NULL) { + stack = _Workspace_Allocate(size); + } + + return stack; +} + +void bsp_stack_free(void *stack) +{ + bool ok = _Heap_Free(&bsp_stack_heap, stack); + + if (!ok) { + _Workspace_Free(stack); + } +} -- cgit v1.2.3