]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_GCC/freedom-metal/src/cpu.c
Base project to replace existing Freedom Studio project using latest Freedom Studio...
[freertos] / FreeRTOS / Demo / RISC-V_RV32_SiFive_HiFive1_GCC / freedom-metal / src / cpu.c
1 /* Copyright 2018 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
3
4 #include <metal/cpu.h>
5 #include <metal/machine.h>
6
7 struct metal_cpu* metal_cpu_get(int hartid)
8 {
9     if (hartid < __METAL_DT_MAX_HARTS) {
10         return (struct metal_cpu *)__metal_cpu_table[hartid];
11     }   
12     return NULL;
13 }
14
15 int metal_cpu_get_current_hartid()
16 {
17 #ifdef __riscv
18     int mhartid;
19     asm volatile("csrr %0, mhartid" : "=r" (mhartid));
20     return mhartid;
21 #endif
22 }
23
24 int metal_cpu_get_num_harts()
25 {
26     return __METAL_DT_MAX_HARTS;
27 }
28
29 extern inline unsigned long long metal_cpu_get_timer(struct metal_cpu *cpu);
30
31 extern inline unsigned long long metal_cpu_get_timebase(struct metal_cpu *cpu);
32
33 extern inline unsigned long long metal_cpu_get_mtime(struct metal_cpu *cpu);
34
35 extern inline int metal_cpu_set_mtimecmp(struct metal_cpu *cpu, unsigned long long time);
36
37 extern inline struct metal_interrupt* metal_cpu_timer_interrupt_controller(struct metal_cpu *cpu);
38
39 extern inline int metal_cpu_timer_get_interrupt_id(struct metal_cpu *cpu);
40
41 extern inline struct metal_interrupt* metal_cpu_software_interrupt_controller(struct metal_cpu *cpu);
42
43 extern inline int metal_cpu_software_get_interrupt_id(struct metal_cpu *cpu);
44
45 extern inline int metal_cpu_software_set_ipi(struct metal_cpu *cpu, int hartid);
46
47 extern inline int metal_cpu_software_clear_ipi(struct metal_cpu *cpu, int hartid);
48
49 extern inline int metal_cpu_get_msip(struct metal_cpu *cpu, int hartid);
50
51 extern inline struct metal_interrupt* metal_cpu_interrupt_controller(struct metal_cpu *cpu);
52
53 extern inline int metal_cpu_exception_register(struct metal_cpu *cpu, int ecode, metal_exception_handler_t handler);
54
55 extern inline int metal_cpu_get_instruction_length(struct metal_cpu *cpu, uintptr_t epc);
56
57 extern inline uintptr_t metal_cpu_get_exception_pc(struct metal_cpu *cpu);
58
59 extern inline int metal_cpu_set_exception_pc(struct metal_cpu *cpu, uintptr_t epc);