1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Heap handling for uncached RAM |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * Copyright (c) 2013 embedded brains GmbH. All rights reserved. |
---|
9 | * |
---|
10 | * embedded brains GmbH |
---|
11 | * Dornierstr. 4 |
---|
12 | * 82178 Puchheim |
---|
13 | * Germany |
---|
14 | * <rtems@embedded-brains.de> |
---|
15 | * |
---|
16 | * The license and distribution terms for this file may be |
---|
17 | * found in the file LICENSE in this distribution or at |
---|
18 | * http://www.rtems.org/license/LICENSE. |
---|
19 | */ |
---|
20 | |
---|
21 | #include <assert.h> |
---|
22 | #include <bsp/linker-symbols.h> |
---|
23 | #include <bsp/nocache-heap.h> |
---|
24 | #include <rtems/score/heapimpl.h> |
---|
25 | #include <rtems/score/apimutex.h> |
---|
26 | |
---|
27 | /** @brief Uncached RAM pool |
---|
28 | * |
---|
29 | * Allocate the whole bsp_nocache for the nocache heap */ |
---|
30 | static char nocache_pool[1024 |
---|
31 | * 1024] __attribute__( ( section( ".bsp_nocache" ) ) ); |
---|
32 | |
---|
33 | /** @brief Nocache heap |
---|
34 | * |
---|
35 | * Heap control for the uncached RAM heap */ |
---|
36 | static Heap_Control nocache_heap; |
---|
37 | |
---|
38 | /** @brief Init nocache heap |
---|
39 | * |
---|
40 | * Constructor for the uncached RAM heap |
---|
41 | * @returns 0 on succuss, error code from errno.h on failure |
---|
42 | */ |
---|
43 | void altera_cyclone_v_nocache_init_heap( void ) |
---|
44 | { |
---|
45 | uintptr_t heap_status = 0; |
---|
46 | |
---|
47 | heap_status = _Heap_Initialize( |
---|
48 | &nocache_heap, |
---|
49 | &nocache_pool[0], |
---|
50 | sizeof( nocache_pool ), |
---|
51 | 0 |
---|
52 | ); |
---|
53 | assert( heap_status != 0 ); |
---|
54 | } |
---|
55 | |
---|
56 | /** @brief Allocate uncached RAM |
---|
57 | * |
---|
58 | * Allocates RAM from the uncached heap |
---|
59 | * @param size Number of bytes to be allocated |
---|
60 | * @returns Pointer to the allocated RAM |
---|
61 | */ |
---|
62 | void *altera_cyclone_v_nocache_malloc( const size_t size ) |
---|
63 | { |
---|
64 | void* ret = NULL; |
---|
65 | |
---|
66 | _RTEMS_Lock_allocator(); |
---|
67 | ret = _Heap_Allocate( &nocache_heap, size ); |
---|
68 | _RTEMS_Unlock_allocator(); |
---|
69 | |
---|
70 | return ret; |
---|
71 | } |
---|
72 | |
---|
73 | /** @brief Free uncached RAM |
---|
74 | * |
---|
75 | * Releases RAM from the uncached heap |
---|
76 | * @param ptr Address of the RAM to be released |
---|
77 | */ |
---|
78 | void altera_cyclone_v_nocache_free( void *ptr ) |
---|
79 | { |
---|
80 | if ( ptr != NULL ) { |
---|
81 | bool ok; |
---|
82 | |
---|
83 | _RTEMS_Lock_allocator(); |
---|
84 | ok = _Heap_Free( &nocache_heap, ptr ); |
---|
85 | _RTEMS_Unlock_allocator(); |
---|
86 | |
---|
87 | assert( ok ); |
---|
88 | } |
---|
89 | } |
---|