Skip to content

Commit e02cc9e

Browse files
authored
sw: Adjust *_decls headers for usability in downstream projects (#132)
1 parent 13d1e6b commit e02cc9e

25 files changed

+93
-5
lines changed

sw/snRuntime/api/alloc_decls.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
7+
#include <stddef.h>
8+
#include <stdint.h>
9+
510
typedef struct {
611
// Base address from where allocation starts
712
uint32_t base;

sw/snRuntime/api/cls_decls.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
7+
#include <stdint.h>
8+
9+
#include "alloc_decls.h"
10+
511
typedef struct {
612
uint32_t hw_barrier;
713
snrt_allocator_t l1_allocator;

sw/snRuntime/api/cluster_interrupt_decls.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
7+
#include <stdint.h>
8+
59
inline void snrt_int_cluster_set(uint32_t mask);
610

711
inline void snrt_int_cluster_clr(uint32_t mask);

sw/snRuntime/api/global_interrupt_decls.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
7+
#include <stdint.h>
8+
59
inline void snrt_int_sw_clear(uint32_t hartid);
610

711
inline void snrt_int_sw_set(uint32_t hartid);

sw/snRuntime/api/memory_decls.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
7+
#include <stdint.h>
8+
59
inline uint32_t __attribute__((const)) snrt_l1_start_addr();
610

711
inline uint32_t __attribute__((const)) snrt_l1_end_addr();

sw/snRuntime/api/omp/eu_decls.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
7+
#include <stdint.h>
8+
59
typedef struct {
610
uint32_t workers_in_loop;
711
uint32_t exit_flag;

sw/snRuntime/api/riscv_decls.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5-
#include "../../deps/riscv-opcodes/encoding.h"
5+
#pragma once
6+
7+
#include <stdint.h>
68

79
static inline void snrt_wfi();
810

sw/snRuntime/api/start_decls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
57
static inline void snrt_exit(int exit_code);

sw/snRuntime/api/sync_decls.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
7+
#include <stdint.h>
8+
59
typedef struct {
610
uint32_t volatile cnt;
711
uint32_t volatile iteration;

sw/snRuntime/api/team_decls.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
7+
#include <stdint.h>
8+
59
inline uint32_t __attribute__((const)) snrt_hartid();
610
inline uint32_t __attribute__((const)) snrt_cluster_num();
711
inline uint32_t __attribute__((const)) snrt_cluster_core_num();
@@ -13,4 +17,4 @@ inline uint32_t __attribute__((const)) snrt_cluster_core_idx();
1317
inline uint32_t __attribute__((const)) snrt_cluster_dm_core_num();
1418
inline uint32_t __attribute__((const)) snrt_cluster_compute_core_num();
1519
inline int __attribute__((const)) snrt_is_compute_core();
16-
inline int __attribute__((const)) snrt_is_dm_core();
20+
inline int __attribute__((const)) snrt_is_dm_core();

sw/snRuntime/src/alloc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
57
#define ALIGN_UP(addr, size) (((addr) + (size)-1) & ~((size)-1))
68
#define ALIGN_DOWN(addr, size) ((addr) & ~((size)-1))
79

sw/snRuntime/src/cls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
57
extern __thread cls_t* _cls_ptr;
68

79
inline cls_t* cls() { return _cls_ptr; }

sw/snRuntime/src/cluster_interrupts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
57
#include "../../deps/riscv-opcodes/encoding.h"
68

79
/**

sw/snRuntime/src/dma.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
57
/// A DMA transfer identifier.
68
typedef uint32_t snrt_dma_txid_t;
79

sw/snRuntime/src/dump.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// will print the given value via the 8th register. Alternatively, the
1818
// `write_csr(reg, val)` macro can be used directly.
1919

20+
#pragma once
21+
2022
#define NAMED_DUMP(type, name, reg) \
2123
static __attribute__((always_inline)) inline void dump_##name(type val) { \
2224
asm volatile("csrw " #reg ", %0" ::"rK"(val)); \

sw/snRuntime/src/global_interrupts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
57
/**
68
* @brief Clear SW interrupt in CLINT
79
* @details

sw/snRuntime/src/perf_cnt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
57
/// Different perf counters
68
// Must match with `snitch_cluster_peripheral`
79
enum snrt_perf_cnt {

sw/snRuntime/src/printf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
57
// Use snrt_putchar for printf
68
#define _putchar snrt_putchar
79

sw/snRuntime/src/riscv.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2023 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+
#include "riscv_decls.h"
6+
7+
#include "riscv.h"
8+
9+
extern void snrt_wfi();
10+
11+
extern void snrt_nop();
12+
13+
extern uint32_t snrt_mcycle();
14+
15+
extern void snrt_interrupt_enable(uint32_t irq);
16+
17+
extern void snrt_interrupt_disable(uint32_t irq);
18+
19+
extern void snrt_interrupt_global_enable(void);
20+
21+
extern void snrt_interrupt_global_disable(void);

sw/snRuntime/src/riscv.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44

55
#include "riscv_decls.h"
66

7+
#pragma once
8+
9+
#include "../../deps/riscv-opcodes/encoding.h"
10+
711
/**
812
* @brief Put the hart into wait for interrupt state
913
*
1014
*/
11-
static inline void snrt_wfi() { asm volatile("wfi"); }
15+
inline void snrt_wfi() { asm volatile("wfi"); }
1216

13-
static inline void snrt_nop() { asm volatile("nop" : : :); }
17+
inline void snrt_nop() { asm volatile("nop" : : :); }
1418

15-
static inline uint32_t snrt_mcycle() {
19+
inline uint32_t snrt_mcycle() {
1620
uint32_t register r;
1721
asm volatile("csrr %0, mcycle" : "=r"(r) : : "memory");
1822
return r;

sw/snRuntime/src/ssr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
57
/// Synchronize the integer and float pipelines.
68
inline void snrt_fpu_fence() {
79
unsigned tmp;

sw/snRuntime/src/sync.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Luca Colagrande <colluca@iis.ee.ethz.ch>
66
// Viviane Potocnik <vivianep@iis.ee.ethz.ch>
77

8+
#pragma once
9+
810
#include <math.h>
911

1012
//================================================================================

sw/snRuntime/src/team.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#pragma once
6+
57
inline uint32_t __attribute__((const)) snrt_hartid() {
68
uint32_t hartid;
79
asm("csrr %0, mhartid" : "=r"(hartid));

target/snitch_cluster/sw/runtime/banshee/src/snrt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "omp.c"
1515
#include "printf.c"
1616
#include "putchar.c"
17+
#include "riscv.c"
1718
#include "snitch_cluster_start.c"
1819
#include "sync.c"
1920
#include "team.c"

target/snitch_cluster/sw/runtime/rtl/src/snrt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "omp.c"
1515
#include "printf.c"
1616
#include "putchar.c"
17+
#include "riscv.c"
1718
#include "snitch_cluster_start.c"
1819
#include "sync.c"
1920
#include "team.c"

0 commit comments

Comments
 (0)