]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_FreedomStudio/freedom-metal/src/cpu.c
Update RISCC-V-RV32-SiFive_HiFive1_FreedomStudio project to latest tools and metal...
[freertos] / FreeRTOS / Demo / RISC-V_RV32_SiFive_HiFive1_FreedomStudio / 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(unsigned 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);