1 |
786 |
skrzyp |
//=================================================================
|
2 |
|
|
//
|
3 |
|
|
// iram.c
|
4 |
|
|
//
|
5 |
|
|
// Test support for on-chip memory
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 2008 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//=============================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): bartv
|
43 |
|
|
// Date: 2008-01-14
|
44 |
|
|
//
|
45 |
|
|
//####DESCRIPTIONEND####
|
46 |
|
|
//=============================================================================
|
47 |
|
|
|
48 |
|
|
#include <pkgconf/system.h>
|
49 |
|
|
#include CYGHWR_MEMORY_LAYOUT_H
|
50 |
|
|
#include <cyg/infra/cyg_type.h>
|
51 |
|
|
#include <cyg/infra/testcase.h>
|
52 |
|
|
#include <cyg/infra/diag.h>
|
53 |
|
|
#include <cyg/infra/cyg_ass.h>
|
54 |
|
|
|
55 |
|
|
#if !defined(CYGMEM_REGION_iram)
|
56 |
|
|
# define NA_MSG "No IRAM memory region defined"
|
57 |
|
|
#elif defined(CYGMEM_REGION_ram) && (CYGMEM_REGION_iram == CYGMEM_REGION_ram)
|
58 |
|
|
# define NA_MSG "IRAM is used as the main RAM memory bank"
|
59 |
|
|
#endif
|
60 |
|
|
|
61 |
|
|
#ifdef NA_MSG
|
62 |
|
|
|
63 |
|
|
externC void
|
64 |
|
|
cyg_start( void)
|
65 |
|
|
{
|
66 |
|
|
CYG_TEST_INIT();
|
67 |
|
|
CYG_TEST_NA(NA_MSG);
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
#else // NA_MSG
|
71 |
|
|
|
72 |
|
|
// These are provided by the linker script
|
73 |
|
|
externC cyg_uint8 _hal_iram_section_start_vma[];
|
74 |
|
|
externC cyg_uint8 _hal_iram_bss_section_start[];
|
75 |
|
|
externC cyg_uint8 _hal_iram_section_end_vma[];
|
76 |
|
|
|
77 |
|
|
// The external declarations which allow the attributes to be
|
78 |
|
|
// specified.
|
79 |
|
|
externC void onchip_fn1(void) CYGBLD_ATTRIB_SECTION(".iram_text.onchip_fn1");
|
80 |
|
|
externC int onchip_fn2(int) CYGBLD_ATTRIB_SECTION(".iram_text.onchip_fn2");
|
81 |
|
|
extern int onchip_data1[8] CYGBLD_ATTRIB_SECTION(".iram_data.onchip_data1");
|
82 |
|
|
extern char onchip_data2 CYGBLD_ATTRIB_SECTION(".iram_data.onchip_data2");
|
83 |
|
|
extern int onchip_data3[1024] CYGBLD_ATTRIB_SECTION(".iram_data.onchip_data3");
|
84 |
|
|
extern int onchip_bss1 CYGBLD_ATTRIB_SECTION(".iram_bss.onchip_bss1");
|
85 |
|
|
extern int onchip_bss2[42] CYGBLD_ATTRIB_SECTION(".iram_bss.onchip_bss2");
|
86 |
|
|
|
87 |
|
|
// Then the definitions. data3 should be garbage collected by the linker.
|
88 |
|
|
int onchip_data1[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
89 |
|
|
char onchip_data2 = 42;
|
90 |
|
|
int onchip_data3[1024] = { 1 } ;
|
91 |
|
|
int onchip_bss1;
|
92 |
|
|
int onchip_bss2[42];
|
93 |
|
|
|
94 |
|
|
void
|
95 |
|
|
onchip_fn1(void)
|
96 |
|
|
{
|
97 |
|
|
int i, data1_sum, fn2_result;
|
98 |
|
|
|
99 |
|
|
diag_printf("PASS:<onchip_fn1 running>\n");
|
100 |
|
|
|
101 |
|
|
// Check again that the data has been correctly initialized,
|
102 |
|
|
// that there are no addressing funnies, and that the data can
|
103 |
|
|
// be overwritten.
|
104 |
|
|
for (i = 0, data1_sum = 0; i < 8; i++) {
|
105 |
|
|
data1_sum += onchip_data1[i];
|
106 |
|
|
onchip_data1[i] -= i;
|
107 |
|
|
}
|
108 |
|
|
if (36 != data1_sum) {
|
109 |
|
|
diag_printf("FAIL:<onchip data1 array should add up to 36>\n");
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
for (i = 0, data1_sum = 0; i < 8; i++) {
|
113 |
|
|
data1_sum += onchip_data1[i];
|
114 |
|
|
}
|
115 |
|
|
if (8 != data1_sum) {
|
116 |
|
|
diag_printf("FAIL:<onchip data1 array should now add up to 8>\n");
|
117 |
|
|
}
|
118 |
|
|
// Call one on-chip function from another.
|
119 |
|
|
fn2_result = onchip_fn2(data1_sum);
|
120 |
|
|
if (861 != fn2_result) {
|
121 |
|
|
diag_printf("FAIL:<onchip_fn2 should return 903>\n");
|
122 |
|
|
}
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
int
|
126 |
|
|
onchip_fn2(int arg)
|
127 |
|
|
{
|
128 |
|
|
int i;
|
129 |
|
|
int result;
|
130 |
|
|
diag_printf("PASS:<onchip_fn2 running>\n");
|
131 |
|
|
|
132 |
|
|
// Make sure that the on-chip bss is correctly zero-initialized
|
133 |
|
|
// and writable.
|
134 |
|
|
for (i = 0; i < 42; i++) {
|
135 |
|
|
if (0 != onchip_bss2[i]) {
|
136 |
|
|
diag_printf("FAIL:<onchip bss2 should be initialized to 0>\n");
|
137 |
|
|
}
|
138 |
|
|
onchip_bss2[i] = i;
|
139 |
|
|
}
|
140 |
|
|
for (i = 0, result = 0; i < 42; i++) {
|
141 |
|
|
result += onchip_bss2[i];
|
142 |
|
|
}
|
143 |
|
|
return result;
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
void
|
147 |
|
|
check_addr(void* where)
|
148 |
|
|
{
|
149 |
|
|
if ((where < (void*)_hal_iram_section_start_vma) || (where >= (void*)_hal_iram_section_end_vma)) {
|
150 |
|
|
diag_printf("FAIL:<ptr %p is not in IRAM region\n", where);
|
151 |
|
|
}
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
externC void
|
155 |
|
|
cyg_start( void)
|
156 |
|
|
{
|
157 |
|
|
int i;
|
158 |
|
|
int data1_sum;
|
159 |
|
|
|
160 |
|
|
CYG_TEST_INIT();
|
161 |
|
|
// For human inspection
|
162 |
|
|
diag_printf("INFO:<IRAM usage : %p -> %p\n", _hal_iram_section_start_vma, _hal_iram_section_end_vma);
|
163 |
|
|
diag_printf("INFO:<IRAM bss @ %p\n", _hal_iram_bss_section_start);
|
164 |
|
|
diag_printf("INFO:<RAM : %p -> %p\n", (void*)CYGMEM_REGION_ram, (void*)(CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE));
|
165 |
|
|
diag_printf("INFO:<onchip_fn1 @ %p>\n", &onchip_fn1);
|
166 |
|
|
diag_printf("INFO:<onchip_fn2 @ %p>\n", &onchip_fn2);
|
167 |
|
|
diag_printf("INFO:<onchip_data1 @ %p>\n", &onchip_data1[0]);
|
168 |
|
|
|
169 |
|
|
// Make sure that IRAM is really separate from main memory.
|
170 |
|
|
if ((_hal_iram_section_start_vma >= (cyg_uint8*)CYGMEM_REGION_ram) &&
|
171 |
|
|
(_hal_iram_section_start_vma < (cyg_uint8*)(CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE))) {
|
172 |
|
|
CYG_TEST_FAIL("IRAM start overlaps SDRAM");
|
173 |
|
|
}
|
174 |
|
|
if ((_hal_iram_section_end_vma >= (cyg_uint8*)CYGMEM_REGION_ram) &&
|
175 |
|
|
(_hal_iram_section_end_vma < (cyg_uint8*)(CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE))) {
|
176 |
|
|
CYG_TEST_FAIL("IRAM end overlaps SDRAM");
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
// Make sure that various objects are correctly placed.
|
180 |
|
|
check_addr(&onchip_fn1);
|
181 |
|
|
check_addr(&onchip_fn2);
|
182 |
|
|
check_addr(&onchip_data1[0]);
|
183 |
|
|
check_addr(&onchip_data2);
|
184 |
|
|
// Not data3, we want that one to be garbage collected.
|
185 |
|
|
check_addr(&onchip_bss1);
|
186 |
|
|
check_addr(&onchip_bss2[0]);
|
187 |
|
|
|
188 |
|
|
// Check that on-chip data is correctly initialized.
|
189 |
|
|
CYG_TEST_CHECK( 42 == onchip_data2, "onchip_data2 should be the answer");
|
190 |
|
|
for (i = 0, data1_sum = 0; i < 8; i++) {
|
191 |
|
|
data1_sum += onchip_data1[i];
|
192 |
|
|
}
|
193 |
|
|
CYG_TEST_CHECK( 36 == data1_sum, "onchip data1 array should add up to 36");
|
194 |
|
|
|
195 |
|
|
// Make sure we can call code located in iram.
|
196 |
|
|
{
|
197 |
|
|
void (*onchip_fn1_ptr)(void) = &onchip_fn1;
|
198 |
|
|
(*onchip_fn1_ptr)();
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
CYG_TEST_PASS_FINISH("IRAM test");
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
#endif // NA_MSG
|