-
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
Conversation
- this also required some enhancements to schema and parser, to support function type declarations and to ensure correct content in docs and headers.
Add u-mode functions for raising signals and setting timeouts Split timer config into 2 functions
Note on thread-safety Get parser unit test working again
Hi @WiseCrohn, could you put more details in the PR description about the interrupt API design assumption, and what should be put in CSI core part, what should be put in BSP part from your design. |
Hi @fanghuaqi I added something, is this what you need? |
Yes, that is what I want to know, thanks. |
CSI_ENUM_LOAD_PAGE_FAULT, | ||
CSI_ENUM_STORE_PAGE_FAULT, | ||
CSI_NUM_STANDARD_TRAP_SOURCES, /* Must come last in this list */ | ||
} csi_trap_source_t; |
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.
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)
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).
I also propose a further enhancement which is to add arguments to the initialization function allowing to specify stack space for interrupt handling (separate stacks for M-mode and U-mode). The use of a separate stack for interrupts may be preferred instead of using the stack of the interrupted thread (easier system design and may save memory) |
…vel, csi_set_interrupt_level_thresh, csi_get_interrupt_level_thresh, csi_register_raw_interrupt_handler, csi_register_raw_exception_handler. - Add parameters to init function for U-mode and M-mode stack spaces. - Further explanatory text and corrections.
(no change of functionality in this commit)
- Add priority argument to csi_set_m_timeout and csi_set_u_timeout - Improve explanatory text
Add U-mode version of raw interrupt handling
Hi @WiseCrohn , I opened a issue in riscv/riscv-profiles#98 questioning about mcu profile, so we can set a more suitable interrupt api for specified mcu profile, which might be good to make the design for interrupt api narrowed for specified case. Thanks |
Also revise some of the introductory text. No change to functionality.
Closing this PR and raising another as there has been a re-think to header file structure etc. following gap analysis. |
Key aims in the design of this API:
Wider assumptions about the "embedded" systems we support:
To see the output specification in PDF form, get the latest from github actions here: https://github.com/riscv-non-isa/riscv-rvm-csi/actions/workflows/build-pdf.yml