Skip to content

Commit d37a0e8

Browse files
Anirudha SarangiSiva Addepalli
authored andcommitted
sw_apps: dhrystone: Add support for Microblaze
Microblaze CPU support is being added into the dhrystone application through this patch. For Microblaze Dhrystone to work, it is mandatory that the design has an Axi Timer. Signed-off-by: Anirudha Sarangi <anirudha.sarangi@xilinx.com> Acked-by: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
1 parent 2672b76 commit d37a0e8

File tree

5 files changed

+142
-40
lines changed

5 files changed

+142
-40
lines changed

lib/sw_apps/dhrystone/data/dhrystone.tcl

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ proc swapp_get_name {} {
88
}
99

1010
proc swapp_get_description {} {
11-
return "Dhrystone synthetic benchmark program for baremetal environment. Not supported for Microblaze in 2021.1.";
11+
return "Dhrystone synthetic benchmark program for baremetal environment.";
1212
}
1313

1414
proc check_standalone_os {} {
@@ -64,23 +64,40 @@ proc check_stdout_hw {} {
6464
set hw_processor [common::get_property HW_INSTANCE $proc_instance]
6565
set proc_type [common::get_property IP_NAME [hsi::get_cells -hier $hw_processor]];
6666

67-
if {($proc_type == "psu_microblaze")} {
68-
error "This application is not supported for PMU Microblaze processor (psu_microblaze).";
69-
}
70-
71-
if {($proc_type == "microblaze")} {
72-
error "This application is not supported for Microblaze processor as of now.";
67+
if {$proc_type == "psu_pmu" || $proc_type == "psu_pmc" || $proc_type == "psu_psm" || $proc_type == "psv_pmc" || $proc_type == "psv_psm" } {
68+
#error "This application is not supported for non-standard and hardened Microblaze configurations.";
7369
}
7470

7571
set slaves [common::get_property SLAVES [hsi::get_cells -hier [hsi::get_sw_processor]]]
7672
foreach slave $slaves {
7773
set slave_type [common::get_property IP_NAME [hsi::get_cells -hier $slave]];
78-
if { $slave_type == "ps7_uart" || $slave_type == "psu_uart" || $slave_type == "psv_sbsauart" } {
74+
if { $slave_type == "ps7_uart" || $slave_type == "psu_uart" || $slave_type == "psv_sbsauart" || $slave_type == "axi_uartlite" ||
75+
$slave_type == "axi_uart16550" || $slave_type == "iomodule" ||
76+
$slave_type == "mdm" } {
7977
return;
8078
}
8179
}
8280

83-
error "This application requires a Uart IP in the hardware."
81+
error "This application requires a Uart IP in the hardware."
82+
}
83+
84+
proc check_axi_timer_hw {} {
85+
set proc_instance [hsi::get_sw_processor];
86+
set hw_processor [common::get_property HW_INSTANCE $proc_instance]
87+
set proc_type [common::get_property IP_NAME [hsi::get_cells -hier $hw_processor]];
88+
89+
if {($proc_type == "microblaze")} {
90+
set slaves [common::get_property SLAVES [hsi::get_cells -hier [hsi::get_sw_processor]]]
91+
foreach slave $slaves {
92+
set slave_type [common::get_property IP_NAME [hsi::get_cells -hier $slave]];
93+
if { $slave_type == "axi_timer" } {
94+
return;
95+
}
96+
}
97+
} else {
98+
return;
99+
}
100+
error "This application requires a Axi Timer IP in the hardware."
84101
}
85102

86103
proc check_stdout_sw {} {
@@ -124,6 +141,9 @@ proc swapp_is_supported_hw {} {
124141
# check for uart peripheral
125142
check_stdout_hw;
126143

144+
# check for axi timer
145+
check_axi_timer_hw;
146+
127147
# we require atleast 30k memory
128148
require_memory "30000";
129149
}
@@ -137,7 +157,29 @@ proc swapp_is_supported_sw {} {
137157
}
138158

139159
proc swapp_generate {} {
140-
# To be filled up once Microblaze support is added
160+
# cleanup this file for writing
161+
set fid [open "platform_config.h" "w+"];
162+
puts $fid "/******************************************************************************";
163+
puts $fid "* Copyright (c) 2010 - 2021 Xilinx, Inc. All rights reserved.";
164+
puts $fid "* SPDX-License-Identifier: MIT";
165+
puts $fid "******************************************************************************/";
166+
puts $fid "#ifndef __PLATFORM_CONFIG_H_";
167+
puts $fid "#define __PLATFORM_CONFIG_H_\n";
168+
169+
puts $fid "/* declare strcpy */";
170+
puts $fid "#include <string.h>";
171+
172+
puts $fid "\n";
173+
174+
puts $fid "/* declare functions in platform.c */";
175+
puts $fid "void init_platform();";
176+
puts $fid "void cleanup_platform();";
177+
178+
# if we have a uart16550 as stdout, then generate some config for that
179+
generate_stdout_config $fid;
180+
181+
puts $fid "#endif";
182+
close $fid;
141183
}
142184

143185
proc swapp_get_linker_constraints {} {
@@ -146,7 +188,7 @@ proc swapp_get_linker_constraints {} {
146188
}
147189

148190
proc swapp_get_supported_processors {} {
149-
return "psu_cortexa53 ps7_cortexa9 psv_cortexa72 psu_cortexr5 psv_cortexr5";
191+
return "microblaze psu_cortexa53 ps7_cortexa9 psv_cortexa72 psu_cortexr5 psv_cortexr5";
150192
}
151193

152194
proc swapp_get_supported_os {} {

lib/sw_apps/dhrystone/src/dhry.h

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@
343343
* data.
344344
*
345345
* On Xilinx baremetal environment, the dhrystone app is well tested for
346-
* Cortex-A9, Cortex-A53, Cortex-R5 processors.
346+
* Cortex-A9, Cortex-A53, Cortex-R5, and Microblaze processors.
347347
*
348348
* Typical numbers to expect (when the Dhrystone App is compiled with -O2 optimization
349349
* with the available 2021.1 toolchains are as following:
@@ -384,14 +384,26 @@
384384
* DMIPS/Sec: 673.280151
385385
* DMIPS/MHz: 1.795432
386386
*
387+
*
388+
* For Microblaze (CPU Freq: 100000000 Hz), with D-Cache and
389+
* I_Cache configured for 16KB:
390+
*
391+
* Microseconds for one run through Dhrystone: 173.160339
392+
* Dhrystones per Second: 5774.994141
393+
* DMIPS/Sec: 3.286849
394+
* DMIPS/MHz: 0.032868
395+
* Please note that Microblaze CPU being configurable, the Dhrystone
396+
* numbers may vary significantly based on various configurations (e.g.
397+
* D-cache and I_cache sizes).
398+
* Also, the Microblaze application expects an Axi Timer in the design.
399+
*
387400
***************************************************************************
388401
*/
389402

390403
#ifndef __DRHY_H_
391404
#define __DRHY_H_
392405

393406
#if defined (__GNUC__) && !defined (__clang__) && !defined (__ICCARM__)
394-
#if !defined (__MICROBLAZE__)
395407

396408
/* Compiler and system dependent definitions: */
397409
#include <xil_printf.h>
@@ -400,25 +412,35 @@
400412
#include <stdio.h>
401413
#include <string.h>
402414
#include "xil_io.h"
403-
#include "xpseudo_asm.h"
404415
#include "xparameters.h"
405416
#include "platform_config.h"
417+
#if !defined (__MICROBLAZE__)
406418
#include "xtime_l.h"
407-
419+
#include "xpseudo_asm.h"
420+
#endif
408421

409422
typedef enum {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5}
410423
Enumeration;
411424

412425
/* General definitions: */
426+
#if !defined (__MICROBLAZE__)
413427
#define ITERATIONS 16000000
414-
#define Mic_secs_Per_Second 1000000.0
428+
#else
429+
#define ITERATIONS 16000
430+
#endif
431+
#define Mic_secs_Per_Second 1000000.0
415432
#define Null 0
416433
/* Value of a Null pointer */
417434
#define true 1
418435
#define false 0
419436

437+
#if defined (__MICROBLAZE__)
438+
typedef u64 XTime;
439+
#endif
440+
420441
#define structassign(d, s) d = s
421442

443+
#if !defined (__MICROBLAZE__)
422444
#if defined (__aarch64__) && !defined (ARMR5)
423445
#if !defined (versal)
424446
#define CLOCKS_PER_SEC XPAR_CPU_CORTEXA53_0_CPU_CLK_FREQ_HZ
@@ -438,10 +460,24 @@ typedef enum {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5}
438460
#ifdef ARMA9
439461
#define CLOCKS_PER_SEC XPAR_CPU_CORTEXA9_CORE_CLOCK_FREQ_HZ
440462
#endif
463+
#else
464+
#define CLOCKS_PER_SEC XPAR_MICROBLAZE_CORE_CLOCK_FREQ_HZ
465+
#define COUNTS_PER_SECOND XPAR_TMRCTR_0_CLOCK_FREQ_HZ
466+
#endif
441467

442468
#define Too_Small_Time COUNTS_PER_SECOND
443469
#define GETTIME(_t) (*_t=barebones_clock())
444470

471+
/* Axi Timer specific macros used for Microblaze CPU */
472+
#if defined (__MICROBLAZE__)
473+
#define MB_AXITIMER_BASEADDR XPAR_TMRCTR_0_BASEADDR
474+
#define MB_AXITIMER_TCSR0_OFFSET 0U
475+
#define MB_AXITIMER_TLR_OFFSET 4U
476+
#define MB_AXITIMER_TCR_OFFSET 8U
477+
#define MB_AXITIMER_CSR_ENABLE_TMR_MASK 0x00000080U
478+
#define MB_AXITIMER_CSR_AUTO_RELOAD_MASK 0x00000010U
479+
#endif
480+
445481
typedef int One_Thirty;
446482
typedef int One_Fifty;
447483
typedef char Capital_Letter;
@@ -471,5 +507,4 @@ typedef struct record {
471507
} Rec_Type, *Rec_Pointer;
472508

473509
#endif /* defined (__GNUC__) && !defined (__clang__) && !defined (__ICCARM__) */
474-
#endif /*!defined (__MICROBLAZE__)*/
475510
#endif /* __DRHY_H_ */

lib/sw_apps/dhrystone/src/dhry_1.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,39 @@
1717

1818
#include "dhry.h"
1919

20+
#if defined (__MICROBLAZE__)
21+
static void MB_StartAxiTimer(void)
22+
{
23+
u32 ControlStatusReg;
24+
25+
/* Checking if the timer is enabled */
26+
if(Xil_In32(MB_AXITIMER_BASEADDR + MB_AXITIMER_TCSR0_OFFSET) &&
27+
MB_AXITIMER_CSR_ENABLE_TMR_MASK)
28+
{
29+
return;
30+
}
31+
/*
32+
* Read the current register contents such that only the necessary bits
33+
* of the register are modified in the following operations
34+
*/
35+
ControlStatusReg = Xil_In32(MB_AXITIMER_BASEADDR +
36+
MB_AXITIMER_TCSR0_OFFSET);
37+
/*
38+
* Remove the reset condition such that the timer counter starts running
39+
* with the value loaded from the compare register
40+
*/
41+
Xil_Out32((MB_AXITIMER_BASEADDR + MB_AXITIMER_TCSR0_OFFSET),
42+
(ControlStatusReg | MB_AXITIMER_CSR_ENABLE_TMR_MASK |
43+
MB_AXITIMER_CSR_AUTO_RELOAD_MASK));
44+
}
45+
46+
void XTime_GetTime(XTime *time_val)
47+
{
48+
*time_val = Xil_In32((MB_AXITIMER_BASEADDR) +
49+
(MB_AXITIMER_TCR_OFFSET));
50+
}
51+
#endif
52+
2053
/* Porting : Timing functions
2154
* How to capture time and convert to seconds must be ported to whatever
2255
* is supported by the platform.
@@ -223,6 +256,9 @@ int main ()
223256
/***************/
224257
/* Start timer */
225258
/***************/
259+
#if defined (__MICROBLAZE__)
260+
MB_StartAxiTimer();
261+
#endif
226262
start_time();
227263

228264
for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index){

lib/sw_apps/dhrystone/src/platform.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#/******************************************************************************
2-
#* Copyright (c) 2010 - 2021 Xilinx, Inc. All rights reserved.
3-
#* SPDX-License-Identifier: MIT
4-
#******************************************************************************/
1+
/******************************************************************************
2+
* Copyright (c) 2010 - 2021 Xilinx, Inc. All rights reserved.
3+
* SPDX-License-Identifier: MIT
4+
******************************************************************************/
55

66
#include "xparameters.h"
77
#include "xil_cache.h"
@@ -12,8 +12,14 @@
1212

1313
void enable_caches()
1414
{
15-
/* Empty function for ARM platforms */
16-
/* Once support for MB is added, this function will be populated */
15+
#if defined (__MICROBLAZE__)
16+
#ifdef XPAR_MICROBLAZE_USE_ICACHE
17+
Xil_ICacheEnable();
18+
#endif
19+
#ifdef XPAR_MICROBLAZE_USE_DCACHE
20+
Xil_DCacheEnable();
21+
#endif
22+
#endif
1723
}
1824

1925
void disable_caches()

lib/sw_apps/dhrystone/src/platform_config.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)