Skip to content

Commit c971b2e

Browse files
committed
sw: Test addressability and user-defined offload to PULP Cluster
1 parent 4b03d0c commit c971b2e

File tree

3 files changed

+137
-1
lines changed

3 files changed

+137
-1
lines changed

sw/tests/testClusterAddr_pulp.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2024 ETH Zurich and University of Bologna.
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Sergio Mazzola <[email protected]>
6+
7+
// Simple addressability test which writes and subsequently reads a value
8+
// in the first address mapped to the PULP Cluster 0 (i.e., the first
9+
// TCDM address)
10+
11+
#include "offload.h"
12+
#include "soc_addr_map.h"
13+
#include <regs/soc_ctrl.h>
14+
#include <stdint.h>
15+
16+
#define TESTVAL_CLUSTER 0xdeadbeef
17+
18+
int main() {
19+
uint8_t *base_addr_tcdm_cluster_0 = CLUSTER_0_BASE;
20+
21+
*((uint32_t*)base_addr_tcdm_cluster_0) = TESTVAL_CLUSTER;
22+
23+
asm volatile ("nop");
24+
asm volatile ("nop");
25+
asm volatile ("nop");
26+
asm volatile ("nop");
27+
asm volatile ("nop");
28+
29+
uint32_t result = *((uint32_t*)base_addr_tcdm_cluster_0);
30+
if (result == TESTVAL_CLUSTER) {
31+
return 0;
32+
} else {
33+
return 1;
34+
}
35+
}

sw/tests/testClusterOffload_pulp.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright 2024 ETH Zurich and University of Bologna.
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Sergio Mazzola <[email protected]>
6+
7+
// Simple offload test to PULP Cluster 0. First set the boot address of all 8
8+
// cluster cores to the desired one (the simple test function), then enables the
9+
// fetch enable for all cores at the same time. All this is done through writes
10+
// to the cluster's peripheral interconnect. Does not currently take care of the
11+
// cluster return value.
12+
13+
#include "offload.h"
14+
#include "soc_addr_map.h"
15+
#include <regs/soc_ctrl.h>
16+
#include <stdint.h>
17+
18+
#define TESTVAL_CLUSTER 0xdeadbeef
19+
20+
#define PERIPH_OFFSET 0x00200000
21+
22+
#define FETCH_EN_OFFSET (PERIPH_OFFSET + 0x008)
23+
24+
#define BOOT_ADDR_CORE_0_OFFSET (PERIPH_OFFSET + 0x040)
25+
#define BOOT_ADDR_CORE_1_OFFSET (PERIPH_OFFSET + 0x044)
26+
#define BOOT_ADDR_CORE_2_OFFSET (PERIPH_OFFSET + 0x048)
27+
#define BOOT_ADDR_CORE_3_OFFSET (PERIPH_OFFSET + 0x04C)
28+
#define BOOT_ADDR_CORE_4_OFFSET (PERIPH_OFFSET + 0x050)
29+
#define BOOT_ADDR_CORE_5_OFFSET (PERIPH_OFFSET + 0x054)
30+
#define BOOT_ADDR_CORE_6_OFFSET (PERIPH_OFFSET + 0x058)
31+
#define BOOT_ADDR_CORE_7_OFFSET (PERIPH_OFFSET + 0x05C)
32+
#define BOOT_ADDR_CORE_8_OFFSET (PERIPH_OFFSET + 0x060)
33+
#define BOOT_ADDR_CORE_9_OFFSET (PERIPH_OFFSET + 0x064)
34+
#define BOOT_ADDR_CORE_10_OFFSET (PERIPH_OFFSET + 0x068)
35+
#define BOOT_ADDR_CORE_11_OFFSET (PERIPH_OFFSET + 0x06C)
36+
#define BOOT_ADDR_CORE_12_OFFSET (PERIPH_OFFSET + 0x070)
37+
#define BOOT_ADDR_CORE_13_OFFSET (PERIPH_OFFSET + 0x074)
38+
#define BOOT_ADDR_CORE_14_OFFSET (PERIPH_OFFSET + 0x078)
39+
#define BOOT_ADDR_CORE_15_OFFSET (PERIPH_OFFSET + 0x07C)
40+
41+
int32_t test_cluster() {
42+
int32_t result;
43+
int32_t hart_id;
44+
45+
asm volatile ("csrr %0, mhartid" : "=r"(hart_id)::);
46+
47+
asm volatile (
48+
"li t0, %1\n" // Load immediate value into t0
49+
"mv a0, t0\n" // Move t0 into a0 (x10)
50+
"mv %0, a0\n" // Move a0 into the output variable
51+
: "=r"(result) // Output operand
52+
: "i"(TESTVAL_CLUSTER) // Input operand: immediate value
53+
: "t0", "a0" // Clobbered registers
54+
);
55+
56+
result = result + hart_id;
57+
58+
return result;
59+
}
60+
61+
int main() {
62+
int32_t hart_id;
63+
asm volatile ("csrr %0, mhartid" : "=r"(hart_id)::);
64+
65+
// set boot address of all cores in cluster 0
66+
uint8_t *boot_addr_core_0_cluster_0 = CLUSTER_0_BASE + BOOT_ADDR_CORE_0_OFFSET;
67+
uint8_t *boot_addr_core_1_cluster_0 = CLUSTER_0_BASE + BOOT_ADDR_CORE_1_OFFSET;
68+
uint8_t *boot_addr_core_2_cluster_0 = CLUSTER_0_BASE + BOOT_ADDR_CORE_2_OFFSET;
69+
uint8_t *boot_addr_core_3_cluster_0 = CLUSTER_0_BASE + BOOT_ADDR_CORE_3_OFFSET;
70+
uint8_t *boot_addr_core_4_cluster_0 = CLUSTER_0_BASE + BOOT_ADDR_CORE_4_OFFSET;
71+
uint8_t *boot_addr_core_5_cluster_0 = CLUSTER_0_BASE + BOOT_ADDR_CORE_5_OFFSET;
72+
uint8_t *boot_addr_core_6_cluster_0 = CLUSTER_0_BASE + BOOT_ADDR_CORE_6_OFFSET;
73+
uint8_t *boot_addr_core_7_cluster_0 = CLUSTER_0_BASE + BOOT_ADDR_CORE_7_OFFSET;
74+
75+
*((uint32_t*)boot_addr_core_0_cluster_0) = test_cluster;
76+
*((uint32_t*)boot_addr_core_1_cluster_0) = test_cluster;
77+
*((uint32_t*)boot_addr_core_2_cluster_0) = test_cluster;
78+
*((uint32_t*)boot_addr_core_3_cluster_0) = test_cluster;
79+
*((uint32_t*)boot_addr_core_4_cluster_0) = test_cluster;
80+
*((uint32_t*)boot_addr_core_5_cluster_0) = test_cluster;
81+
*((uint32_t*)boot_addr_core_6_cluster_0) = test_cluster;
82+
*((uint32_t*)boot_addr_core_7_cluster_0) = test_cluster;
83+
84+
// enable fetch for all cores in cluster 0
85+
uint8_t *fetch_en_cluster_0 = CLUSTER_0_BASE + FETCH_EN_OFFSET;
86+
87+
*((uint32_t*)fetch_en_cluster_0) = 0x00FF;
88+
89+
// only the host hart executes this
90+
volatile int count = 10000;
91+
if (hart_id == 0) {
92+
// delay loop
93+
asm volatile (
94+
"1: nop\n"
95+
"addi %0, %0, -1\n"
96+
"bnez %0, 1b\n"
97+
: "+r"(count) // Input and output operand
98+
);
99+
}
100+
return count;
101+
}

target/sim/vsim/setup.chimera_soc.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
#
55
# Moritz Scherer <[email protected]>
66

7-
set BINARY ../../../sw/tests/testCluster.memisl.elf
7+
set BINARY ../../../sw/tests/testClusterAddr_pulp.memisl.elf
88
set SELCFG 0

0 commit comments

Comments
 (0)