Skip to content

Commit

Permalink
[driver] add clic
Browse files Browse the repository at this point in the history
  • Loading branch information
SamulKyull authored and SamulKyull committed Jan 10, 2025
1 parent bb0e25e commit b7ef02a
Show file tree
Hide file tree
Showing 9 changed files with 488 additions and 118 deletions.
38 changes: 25 additions & 13 deletions board/avaota-f1/cdk/avaota_f1.cdkproj
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
<File Name="../../../include/drivers/reg/reg-spi.h">
<FileOption/>
</File>
<File Name="../../../include/drivers/reg/reg-clic.h"/>
</VirtualDirectory>
<VirtualDirectory Name="usb">
<VirtualDirectory Name="reg">
Expand Down Expand Up @@ -276,6 +277,9 @@
<File Name="../../../include/drivers/intc/sys-intc.h">
<FileOption/>
</File>
<File Name="../../../include/drivers/intc/sys-clic.h">
<FileOption/>
</File>
</VirtualDirectory>
</VirtualDirectory>
<VirtualDirectory Name="image">
Expand Down Expand Up @@ -507,6 +511,9 @@
<File Name="../../../src/drivers/intc/sys-gic.c" ExcludeProjConfig="BuildSet">
<FileOption/>
</File>
<File Name="../../../src/drivers/intc/sys-clic.c">
<FileOption/>
</File>
</VirtualDirectory>
</VirtualDirectory>
<VirtualDirectory Name="log">
Expand Down Expand Up @@ -534,6 +541,17 @@
<FileOption/>
</File>
</VirtualDirectory>
<DebugSessions>
<watchExpressions/>
<memoryExpressions>0x20181C8;;;</memoryExpressions>
<statistics>;;32;;MHZ;;up</statistics>
<peripheralTabs/>
<WatchDisplayFormat>1</WatchDisplayFormat>
<LocalDisplayFormat>1</LocalDisplayFormat>
<debugLayout/>
<memoryTabColSizeExpressions>100:4;100:8;100:8;100:8;</memoryTabColSizeExpressions>
<QuickWatchDisplayFormat>1</QuickWatchDisplayFormat>
</DebugSessions>
<BuildConfigs>
<BuildConfig Name="BuildSet">
<Target>
Expand Down Expand Up @@ -637,7 +655,7 @@
<Undefine/>
<Optim>None (-O0)</Optim>
<DebugLevel>Maximum (-g3)</DebugLevel>
<IncludePath>$(ProjectPath);../../../include/;../../../include/arch/riscv/;../../../include/cli/;../../../include/drivers/chips/sun300iw1/;../../../include/drivers/mmc/;../../../include/drivers/pmu/reg/;../../../include/drivers/pmu/;../../../include/drivers/reg/;../../../include/drivers/usb/;../../../include/image/;../../../include/lib/elf/;../../../include/lib/fatfs/;../../../include/lib/fdt/;../../../include/drivers/;../../../include/drivers/chips/;../../../include/drivers/mtd</IncludePath>
<IncludePath>$(ProjectPath);../../../include/;../../../include/arch/riscv/;../../../include/cli/;../../../include/drivers/chips/sun300iw1/;../../../include/drivers/mmc/;../../../include/drivers/pmu/reg/;../../../include/drivers/pmu/;../../../include/drivers/reg/;../../../include/drivers/usb/;../../../include/image/;../../../include/lib/elf/;../../../include/lib/fatfs/;../../../include/lib/fdt/;../../../include/drivers/;../../../include/drivers/chips/;../../../include/drivers/mtd/;../../../include/drivers/intc/</IncludePath>
<OtherFlags>-nostdlib -nostdinc -march=rv32imafcxthead -mabi=ilp32f -Wno-int-to-pointer-cast -Wno-int-to-pointer-cast -Wno-shift-count-overflow -Wno-builtin-declaration-mismatch -Wno-pointer-to-int-cast -Wno-implicit-function-declaration -Wno-discarded-qualifiers -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wno-parentheses</OtherFlags>
<Verbose>no</Verbose>
<Ansi>no</Ansi>
Expand All @@ -654,7 +672,7 @@
<Asm>
<Define/>
<Undefine/>
<IncludePath>$(ProjectPath);../../../include/;../../../include/arch/riscv/;../../../include/cli/;../../../include/drivers/chips/sun300iw1/;../../../include/drivers/mmc/;../../../include/drivers/pmu/reg/;../../../include/drivers/pmu/;../../../include/drivers/reg/;../../../include/drivers/usb/;../../../include/image/;../../../include/lib/elf/;../../../include/lib/fatfs/;../../../include/lib/fdt/;../../../include/drivers/;../../../include/drivers/chips/</IncludePath>
<IncludePath>$(ProjectPath);../../../include/;../../../include/arch/riscv/;../../../include/cli/;../../../include/drivers/chips/sun300iw1/;../../../include/drivers/mmc/;../../../include/drivers/pmu/reg/;../../../include/drivers/pmu/;../../../include/drivers/reg/;../../../include/drivers/usb/;../../../include/image/;../../../include/lib/elf/;../../../include/lib/fatfs/;../../../include/lib/fdt/;../../../include/drivers/;../../../include/drivers/chips/;../../../include/drivers/intc/</IncludePath>
<OtherFlags/>
<DebugLevel>none</DebugLevel>
</Asm>
Expand All @@ -668,6 +686,8 @@
<AutoLDFile>no</AutoLDFile>
<LinkType>start-group</LinkType>
<IncludeAllLibs>no</IncludeAllLibs>
<LinkSpecsType>none</LinkSpecsType>
<LinkUseNewlibNano>no</LinkUseNewlibNano>
</Linker>
<Debug>
<LoadApplicationAtStartup>yes</LoadApplicationAtStartup>
Expand Down Expand Up @@ -723,12 +743,15 @@
</ConfigSIM>
<ConfigOpenOCD>
<OpenOCDExecutablePath/>
<OpenOCDLocally>yes</OpenOCDLocally>
<OpenOCDTelnetPortEnable>no</OpenOCDTelnetPortEnable>
<OpenOCDTelnetPort>4444</OpenOCDTelnetPort>
<OpenOCDTclPortEnable>no</OpenOCDTclPortEnable>
<OpenOCDTclPort>6666</OpenOCDTclPort>
<OpenOCDConfigOptions/>
<OpenOCDTimeout>5000</OpenOCDTimeout>
<OpenOCDRemoteIP>localhost</OpenOCDRemoteIP>
<OpenOCDRemotePort>3333</OpenOCDRemotePort>
<PluginID>openocd-sifive</PluginID>
<Version>latest</Version>
</ConfigOpenOCD>
Expand All @@ -751,15 +774,4 @@
</Flash>
</BuildConfig>
</BuildConfigs>
<DebugSessions>
<watchExpressions/>
<memoryExpressions>0x20181C8;;;</memoryExpressions>
<statistics>;;32;;MHZ;;up</statistics>
<peripheralTabs/>
<WatchDisplayFormat>1</WatchDisplayFormat>
<LocalDisplayFormat>1</LocalDisplayFormat>
<debugLayout/>
<memoryTabColSizeExpressions>100:4;100:8;100:8;100:8;</memoryTabColSizeExpressions>
<QuickWatchDisplayFormat>1</QuickWatchDisplayFormat>
</DebugSessions>
</Project>
2 changes: 1 addition & 1 deletion board/avaota-f1/cdk/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// Project Info
#define PROJECT_NAME "SyterKit"
#define PROJECT_VERSION "0.3.0"
#define PROJECT_VERSION "0.4.0.2"
#define PROJECT_GIT_HASH "58dcc02e"
#define PROJECT_C_COMPILER "riscv64-unknown-elf-gcc"
#define PROJECT_C_COMPILER_VERSION "10.4.0"
Expand Down
166 changes: 83 additions & 83 deletions board/avaota-f1/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -179,87 +179,87 @@ vectors:
mret

/*
* IRQ vectors.
*/
.align 6
.globl irq_handler
* IRQ vectors.
*/
.align 6
.globl irq_handler
irq_handler:
csrw mscratch, sp
addi sp, sp, -(37 * REGSZ)
SREG x1, 1 * REGSZ(x2)
SREG x3, 3 * REGSZ(x2)
SREG x4, 4 * REGSZ(x2)
SREG x5, 5 * REGSZ(x2)
SREG x6, 6 * REGSZ(x2)
SREG x7, 7 * REGSZ(x2)
SREG x8, 8 * REGSZ(x2)
SREG x9, 9 * REGSZ(x2)
SREG x10, 10 * REGSZ(x2)
SREG x11, 11 * REGSZ(x2)
SREG x12, 12 * REGSZ(x2)
SREG x13, 13 * REGSZ(x2)
SREG x14, 14 * REGSZ(x2)
SREG x15, 15 * REGSZ(x2)
SREG x16, 16 * REGSZ(x2)
SREG x17, 17 * REGSZ(x2)
SREG x18, 18 * REGSZ(x2)
SREG x19, 19 * REGSZ(x2)
SREG x20, 20 * REGSZ(x2)
SREG x21, 21 * REGSZ(x2)
SREG x22, 22 * REGSZ(x2)
SREG x23, 23 * REGSZ(x2)
SREG x24, 24 * REGSZ(x2)
SREG x25, 25 * REGSZ(x2)
SREG x26, 26 * REGSZ(x2)
SREG x27, 27 * REGSZ(x2)
SREG x28, 28 * REGSZ(x2)
SREG x29, 29 * REGSZ(x2)
SREG x30, 30 * REGSZ(x2)
SREG x31, 31 * REGSZ(x2)
csrrw t0, mscratch, x0
csrr s0, mstatus
csrr t1, mepc
csrr t2, mbadaddr
csrr t3, mcause
SREG t0, 2 * REGSZ(x2)
SREG s0, 32 * REGSZ(x2)
SREG t1, 33 * REGSZ(x2)
SREG t2, 34 * REGSZ(x2)
SREG t3, 35 * REGSZ(x2)
li x5, -1
SREG x5, 36 * REGSZ(x2)
move a0, sp
jal riscv_handle_exception
csrr a0, mscratch
LREG x1, 1 * REGSZ(a0)
LREG x2, 2 * REGSZ(a0)
LREG x3, 3 * REGSZ(a0)
LREG x4, 4 * REGSZ(a0)
LREG x5, 5 * REGSZ(a0)
LREG x6, 6 * REGSZ(a0)
LREG x7, 7 * REGSZ(a0)
LREG x8, 8 * REGSZ(a0)
LREG x9, 9 * REGSZ(a0)
LREG x11, 11 * REGSZ(a0)
LREG x12, 12 * REGSZ(a0)
LREG x13, 13 * REGSZ(a0)
LREG x14, 14 * REGSZ(a0)
LREG x15, 15 * REGSZ(a0)
LREG x16, 16 * REGSZ(a0)
LREG x17, 17 * REGSZ(a0)
LREG x18, 18 * REGSZ(a0)
LREG x19, 19 * REGSZ(a0)
LREG x20, 20 * REGSZ(a0)
LREG x21, 21 * REGSZ(a0)
LREG x22, 22 * REGSZ(a0)
LREG x23, 23 * REGSZ(a0)
LREG x24, 24 * REGSZ(a0)
LREG x25, 25 * REGSZ(a0)
LREG x26, 26 * REGSZ(a0)
LREG x27, 27 * REGSZ(a0)
LREG x28, 28 * REGSZ(a0)
LREG x29, 29 * REGSZ(a0)
LREG x30, 30 * REGSZ(a0)
LREG x31, 31 * REGSZ(a0)
LREG x10, 10 * REGSZ(a0)
mret
csrw mscratch, sp
addi sp, sp, -(37 * REGSZ)
SREG x1, 1 * REGSZ(x2)
SREG x3, 3 * REGSZ(x2)
SREG x4, 4 * REGSZ(x2)
SREG x5, 5 * REGSZ(x2)
SREG x6, 6 * REGSZ(x2)
SREG x7, 7 * REGSZ(x2)
SREG x8, 8 * REGSZ(x2)
SREG x9, 9 * REGSZ(x2)
SREG x10, 10 * REGSZ(x2)
SREG x11, 11 * REGSZ(x2)
SREG x12, 12 * REGSZ(x2)
SREG x13, 13 * REGSZ(x2)
SREG x14, 14 * REGSZ(x2)
SREG x15, 15 * REGSZ(x2)
SREG x16, 16 * REGSZ(x2)
SREG x17, 17 * REGSZ(x2)
SREG x18, 18 * REGSZ(x2)
SREG x19, 19 * REGSZ(x2)
SREG x20, 20 * REGSZ(x2)
SREG x21, 21 * REGSZ(x2)
SREG x22, 22 * REGSZ(x2)
SREG x23, 23 * REGSZ(x2)
SREG x24, 24 * REGSZ(x2)
SREG x25, 25 * REGSZ(x2)
SREG x26, 26 * REGSZ(x2)
SREG x27, 27 * REGSZ(x2)
SREG x28, 28 * REGSZ(x2)
SREG x29, 29 * REGSZ(x2)
SREG x30, 30 * REGSZ(x2)
SREG x31, 31 * REGSZ(x2)
csrrw t0, mscratch, x0
csrr s0, mstatus
csrr t1, mepc
csrr t2, mbadaddr
csrr t3, mcause
SREG t0, 2 * REGSZ(x2)
SREG s0, 32 * REGSZ(x2)
SREG t1, 33 * REGSZ(x2)
SREG t2, 34 * REGSZ(x2)
SREG t3, 35 * REGSZ(x2)
li x5, -1
SREG x5, 36 * REGSZ(x2)
move a0, sp
jal riscv_handle_exception
csrr a0, mscratch
LREG x1, 1 * REGSZ(a0)
LREG x2, 2 * REGSZ(a0)
LREG x3, 3 * REGSZ(a0)
LREG x4, 4 * REGSZ(a0)
LREG x5, 5 * REGSZ(a0)
LREG x6, 6 * REGSZ(a0)
LREG x7, 7 * REGSZ(a0)
LREG x8, 8 * REGSZ(a0)
LREG x9, 9 * REGSZ(a0)
LREG x11, 11 * REGSZ(a0)
LREG x12, 12 * REGSZ(a0)
LREG x13, 13 * REGSZ(a0)
LREG x14, 14 * REGSZ(a0)
LREG x15, 15 * REGSZ(a0)
LREG x16, 16 * REGSZ(a0)
LREG x17, 17 * REGSZ(a0)
LREG x18, 18 * REGSZ(a0)
LREG x19, 19 * REGSZ(a0)
LREG x20, 20 * REGSZ(a0)
LREG x21, 21 * REGSZ(a0)
LREG x22, 22 * REGSZ(a0)
LREG x23, 23 * REGSZ(a0)
LREG x24, 24 * REGSZ(a0)
LREG x25, 25 * REGSZ(a0)
LREG x26, 26 * REGSZ(a0)
LREG x27, 27 * REGSZ(a0)
LREG x28, 28 * REGSZ(a0)
LREG x29, 29 * REGSZ(a0)
LREG x30, 30 * REGSZ(a0)
LREG x31, 31 * REGSZ(a0)
LREG x10, 10 * REGSZ(a0)
mret
6 changes: 6 additions & 0 deletions include/arch/riscv/csr.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ extern "C" {
#define MIE_SEIE (1 << 9) /**< Supervisor External Interrupt Enable */
#define MIE_MEIE (1 << 11) /**< Machine External Interrupt Enable */

/* RISC-V Privilege */
#define PRV_U (0)
#define PRV_S (1)
#define PRV_H (2)
#define PRV_M (3)

/**
* @brief Swap the value of a CSR with a new value.
*
Expand Down
64 changes: 64 additions & 0 deletions include/drivers/intc/sys-clic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* SPDX-License-Identifier: GPL-2.0+ */

#ifndef _SYS_CLIC_H_
#define _SYS_CLIC_H_

#include <io.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <types.h>

#include <common.h>
#include <log.h>

#include <reg-clic.h>
#include <reg-ncat.h>

#ifdef __cplusplus
extern "C" {
#endif// __cplusplus

#define CLIC_IRQ_NUM (186)

typedef enum irq_trigger_type {
IRQ_TRIGGER_TYPE_LEVEL,
IRQ_TRIGGER_TYPE_EDGE_RISING,
IRQ_TRIGGER_TYPE_EDGE_FALLING,
IRQ_TRIGGER_TYPE_EDGE_BOTH
} irq_trigger_type_t;

typedef struct irq_controller {
uint16_t id;
uint16_t irq_cnt;
uint16_t parent_id;
uint16_t irq_id;
uint64_t reg_base_addr;
} irq_controller_t;

/**
* @brief Handles the IRQ
*
*/
void do_irq();

/**
* @brief Initializes the interrupt mechanism
*
* @return 0 on success, or an error code
*/
int arch_interrupt_init(void);

/**
* @brief Exits the interrupt mechanism
*
* @return 0 on success, or an error code
*/
int arch_interrupt_exit(void);

#ifdef __cplusplus
}
#endif// __cplusplus

#endif// _SYS_CLIC_H_
Loading

0 comments on commit b7ef02a

Please sign in to comment.