Menu Close

RISC-V PLIC Project Design(1)

1. PLIC software design

 

Related reference articles:

RISC-V teaching plan

 

The corresponding PLIC design in the software mainly includes the following modules.

 

1.1. fii_types.h

#define RV_TYPE RV32                         //Define RISC-V CPU as 32-bit



//The following definitions are for the convenience of transplanting the system and clarifying the length and sign of the defined data type. In short, it is an alias for the commonly used data type.
//Example: unsigned int is not necessarily 32 bits under different systems, but here, u32_t can be an unsigned integer, or it can be another 32-bit long, unsigned data type depending on the situation
//In general, compared with unsigned int, u32_t not only simplifies the writing method, but also includes more information

typedef unsigned int uintptr_t;

typedef unsigned long long u64_t;
typedef unsigned int u32_t;
typedef unsigned short u16_t;
typedef unsigned char u8_t;

typedef long long s64_t;
typedef int s32_t;
typedef short s16_t;
typedef char s8_t;

 

1.2. plic.h

This header file mainly declares some macros related to external platform-level interrupts

#ifndef PLIC_H
#define PLIC_H

#include "const.h"

//These definitions can be found in the address map (detailed address map, click here)
// Define the priority offset and parameters for external platform-level interrupts

#define PLIC_PRIORITY_OFFSET _AC(0x0000,UL)        //UL is an unsigned long, which is suitable for transplantation of different systems and can prevent overflow in calculation
#define PLIC_PRIORITY_SHIFT_PER_SOURCE 2


// Define the suspension offset and parameters for external platform-level interrupts

#define PLIC_PENDING_OFFSET _AC(0x1000,UL)
#define PLIC_PENDING_SHIFT_PER_SOURCE 0


// Define the enable offset and parameters for external platform-level interrupts

#define PLIC_ENABLE_OFFSET _AC(0x2000,UL)                               
#define PLIC_ENABLE_SHIFT_PER_TARGET 7    

                               

// Define threshold offsets and parameters for external platform-level interrupts

#define PLIC_THRESHOLD_OFFSET _AC(0x200000,UL)   
#define PLIC_THRESHOLD_SHIFT_PER_TARGET 12



// Define the offset and parameters of the external platform-level interrupt declaration    

#define PLIC_CLAIM_OFFSET _AC(0x200004,UL)
#define PLIC_CLAIM_SHIFT_PER_TARGET 12

//The official definition is that up to 1023 interrupt sources can be used
#define PLIC_MAX_SOURCE 1023
#define PLIC_SOURCE_MASK 0x3FF

#endif /* PLIC_H */

 

1.3. plic_driver.h

#ifndef PLIC_DRIVER_H
#define PLIC_DRIVER_H

#include "plic.h"
#include "platform.h"

typedef struct __plic_instance_t //struct in C language
{
uintptr_t base_addr;

u32_t num_sources;
u32_t num_priorities;

} plic_instance_t;

//Define the data type of variables related to PLIC

typedef u32_t plic_source;
typedef u32_t plic_priority;
typedef u32_t plic_threshold;

//Initialize PLIC
void PLIC_init(plic_instance_t * this_plic, uintptr_t base_addr,
u32_t num_sources, u32_t num_priorities);

//Set the priority threshold
void PLIC_set_threshold(plic_instance_t * this_plic, plic_threshold threshold);

//set interrupt enable
void PLIC_enable_interrupt(plic_instance_t * this_plic, plic_source source);

// disable interrupts
void PLIC_disable_interrupt(plic_instance_t * this_plic, plic_source source);

//set priority
void PLIC_set_priority(plic_instance_t * this_plic, plic_source source,
plic_priority priority);

// break statement
plic_source PLIC_claim_interrupt(plic_instance_t * this_plic);

// interrupt complete
void PLIC_complete_interrupt(plic_instance_t * this_plic, plic_source source);


#endif

 

 

Project file download:

 

 

Posted in FPGA, RISC-V, RISC-V Textbook, Textbook and Training Project

Related Articles

Leave a Reply

Your email address will not be published.

Leave the field below empty!