generated from riscv/docs-spec-template
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Interrupt and timer support #2
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d86cf0a
First draft support for interrupt handling
WiseCrohn 313f438
Add timer support, and improve documentation.
WiseCrohn c7ea825
Get rid of user mode context and switch to use of a handle.
WiseCrohn 2378740
Add csi_read_mtime
WiseCrohn 7930bfd
Change SSoT for csi_csrs.h
WiseCrohn f5c6785
- add new API functions csi_set_interrupt_level, csi_get_interrupt_le…
WiseCrohn eb355e1
Improvements to formatting of documentation
WiseCrohn 94d9ba4
- Add csi_set_preemption
WiseCrohn c0d0a6a
Add csi_route_interrupt
WiseCrohn 8b692fc
Improve doc generation to include more cross-referencing links.
WiseCrohn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Top-level definition file for RVM-CSI API. Note: application writers do not include | ||
* this file: user rvm_csi.h instead. | ||
*/ | ||
|
||
#ifndef CSI_H | ||
#define CSI_H | ||
|
||
#include "csi_interrupts.h" | ||
|
||
#endif /* CSI_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* PLACEHOLDER: replaced by content from BSP */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* PLACEHOLDER: replaced by content from BSP */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* PLACEHOLDER: replaced by content from BSP */ | ||
|
||
#ifndef CSI_BSP_INTERRUPTS_H | ||
#define CSI_BSP_INTERRUPTS_H | ||
|
||
// Context structure for a timeout | ||
typedef struct { | ||
int placeholder; | ||
} csi_timeout_t; | ||
|
||
#endif // CSI_BSP_INTERRUPTS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* PLACEHOLDER: replaced by content from BSP */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* PLACEHOLDER: to be replaced by content auto-generated by Sail model */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* General-Purpose Definitions for use in CSI code | ||
* | ||
* This file is included from rvm_csi.h prior to all other headers and contains | ||
* general-purpose definitions which may be used by subsequent headers. | ||
* | ||
* Copyright (c) RISC-V International 2022. Creative Commons License. Auto- | ||
* generated file: DO NOT EDIT | ||
*/ | ||
|
||
#ifndef CSI_DEFS_H | ||
#define CSI_DEFS_H | ||
|
||
/* | ||
* Return type for functions indicating status | ||
*/ | ||
typedef enum { | ||
CSI_SUCCESS = 0, /* Operation completed successfully */ | ||
CSI_NOT_IMPLEMENTED = -1, /* Functionality not implemented */ | ||
CSI_ERROR = -2, /* Generic error code */ | ||
CSI_NOT_INITIALIZED = -3, /* Sub-system not correctly initialised, operation failed. */ | ||
CSI_OUT_OF_MEM = -4, /* Out-of-memory error */ | ||
} csi_status_t; | ||
|
||
/* | ||
* Enumerates all sources in the system that can give rise to a trap event. This | ||
* enumeration should be treated as an integer which can have additional values | ||
* beyond those enumerated here. A standard set of interrupt and exception sources | ||
* are enumerated here, which exclude external sources. All external interrupt | ||
* sources should be enumerated by the BSP within csi_bsp_interrupts.h; and their | ||
* ennumerated values should follow on from CSI_NUM_STANDARD_TRAP_SOURCES. | ||
* csi_bsp_interrupts.h must also define CSI_TOTAL_BSP_TRAP_SOURCES to indicate the | ||
* total number of sources defined. User applications may then use values above | ||
* this to enumerate user-defined software signals. Note that the actual | ||
* enumerated values have no meaning beyond serving to uniquely identify the source | ||
* of a trap event. They are not intended to map onto values in the mcause | ||
* register. | ||
*/ | ||
typedef enum { | ||
CSI_ENUM_NMI = 0, /* Non-maskable exception (hardware error) */ | ||
CSI_ENUM_MACHINE_SW_INTERRUPT, /* Machine mode software interrupt */ | ||
CSI_ENUM_MACHINE_TIMER_INTERRUPT, /* Machine mode timer interrupt */ | ||
CSI_ENUM_INSTRUCTION_ADDR_MISALIGNED_EXCEPTION, /* Instruction misaligned exception */ | ||
CSI_ENUM_INSTRUCTION_ACCESS_FAULT_EXCEPTION, /* Instruction access fault exception */ | ||
CSI_ENUM_ILLEGAL_INSTRUCTION_EXCEPTION, /* Illegal instruction exception */ | ||
CSI_ENUM_BREAKPOINT_EXCEPTION, /* Breakpoint exception */ | ||
CSI_ENUM_LOAD_ADDR_MISALIGNED_EXCEPTION, /* Load address misaligned exception */ | ||
CSI_ENUM_LOAD_ACCESS_FAULT_EXCEPTION, /* Load access fault exception */ | ||
CSI_ENUM_STORE_ADDR_MISALIGNED_EXCEPTION, /* Store address misaligned exception */ | ||
CSI_ENUM_STORE_ACCESS_FAULT_EXCEPTION, /* Store access fault exception */ | ||
CSI_ENUM_ECALL_FROM_UMODE, /* ECALL from User mode */ | ||
CSI_ENUM_ECALL_FROM_MMODE, /* ECALL from Machine mode */ | ||
CSI_ENUM_INST_PAGE_FAULT, /* Instruction page-fault */ | ||
CSI_ENUM_LOAD_PAGE_FAULT, /* Load page-fault */ | ||
CSI_ENUM_STORE_PAGE_FAULT, /* Store page-fault */ | ||
CSI_NUM_STANDARD_TRAP_SOURCES, /* Must come last in this list */ | ||
} csi_trap_source_t; | ||
|
||
/* | ||
* Interrupt enable bits in the mie CSR | ||
*/ | ||
typedef enum { | ||
CSI_SW_INTERRUPTS_ENABLE = 8, /* Software interrupts enable bit index */ | ||
CSI_TIMER_INTERRUPTS_ENABLE = 128, /* Timer interrupts enable bit index */ | ||
CSI_EXT_INTERRUPTS_ENABLE = 2048, /* External interrupts enable bit index */ | ||
} csi_interrupt_enables_t; | ||
|
||
|
||
#endif /* CSI_DEFS_H */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should trap source classified to interrupt and exception to match mcause.
This is how we define in NMSIS Core https://github.com/Nuclei-Software/NMSIS/blob/master/Device/_Template_Vendor/Vendor/Device/Include/Device.h#L64-L114
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
csi_trap_source_t is different from mcause, because it is much more detailed. For example, mcause only has a single entry for "machine external interrrupt", whereas csi_trap_source_t has to enumerate all the external interrupts in the system (the BSP extends it for this purpose). Also, it is useful to have all values of csi_trap_source_t contiguous (without gaps), so that the BSP can maintain a table which is indexed by this enumeration (without wasting memory).
I think there are no efficiency problems here because a decode from mcause (+ PLIC/AIA configuration) to csi_trap_source_t does not need to happen at the time an interrupt is taken (it can happen at the time a handler is registered). csi_trap_source_t just gives a convenient way of indexing sources for the purpose of the HAL API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the contiguous values, I think exception and interrupt should be enumerated in two enum, since exception id and interrupt id could be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I think we have a misunderstanding. The way I conceived it, the actual enumerated values are not important, they don't relate to anything in the hardware. We have a single function (csi_register_m_isr) to register a (machine-mode) user handler for either interrupts or exceptions, so need a single enum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so all the handing of the
csi_trap_source_t
will leave to the implementation of csi_register_m_isr to process this enum.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And did you take a look at the riscv fast interrupt for mcu, it support vector interrupt and non-vector interrupt, it might be more necessary than plic/aia.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I would suggest a couple of enhancements arising from this. Firstly, the CLIC introduces interrupt levels as well as priorities (levels determine what interrupts can preempt others at the same privilege level, whereas priorities determine the order in which simultaneous interrupts are taken). So I propose to add APIs for setting interrupt levels and level threshold.
Also, I propose to say that the BSP should use vectored interrupts where possible, and we can introduce an additional API to allow users to register a "raw" handler that will be plugged directly into the vector table for a particular mcause (bypassing the base trap handler supplied by the BSP). This allows users to create their own fast, customized handler for a particular mcause (but the disadvantage is that the user's handler in that case would need to do all context save-and restore for itself - whereas a handler registered with csi_register_m_isr or csi_register_u_isr doesn't need to deal with that because the base handler does it).