From 64115be98dda5eae8840e373c85b0c615f196dbb Mon Sep 17 00:00:00 2001 From: Drew Barbier Date: Tue, 25 Jul 2017 16:58:47 -0500 Subject: added vectored interrupt example --- software/vectored_interrupts/Makefile | 10 + software/vectored_interrupts/vectored_interrupts | Bin 0 -> 188880 bytes software/vectored_interrupts/vectored_interrupts.c | 216 +++++++++++++++++++++ 3 files changed, 226 insertions(+) create mode 100644 software/vectored_interrupts/Makefile create mode 100755 software/vectored_interrupts/vectored_interrupts create mode 100644 software/vectored_interrupts/vectored_interrupts.c (limited to 'software') diff --git a/software/vectored_interrupts/Makefile b/software/vectored_interrupts/Makefile new file mode 100644 index 0000000..4365038 --- /dev/null +++ b/software/vectored_interrupts/Makefile @@ -0,0 +1,10 @@ +TARGET = vectored_interrupts +CFLAGS += -O2 -fno-builtin-printf -DVECT_IRQ + +BSP_BASE = ../../bsp + +ASM_SRCS += $(ENV_DIR)/ventry.S +C_SRCS += vectored_interrupts.c +C_SRCS += $(BSP_BASE)/drivers/plic/plic_driver.c + +include $(BSP_BASE)/env/common.mk diff --git a/software/vectored_interrupts/vectored_interrupts b/software/vectored_interrupts/vectored_interrupts new file mode 100755 index 0000000..fd85e7e Binary files /dev/null and b/software/vectored_interrupts/vectored_interrupts differ diff --git a/software/vectored_interrupts/vectored_interrupts.c b/software/vectored_interrupts/vectored_interrupts.c new file mode 100644 index 0000000..61eee5e --- /dev/null +++ b/software/vectored_interrupts/vectored_interrupts.c @@ -0,0 +1,216 @@ +// See LICENSE for license details. + +#include +#include +#include "platform.h" +#include +#include "plic/plic_driver.h" +#include "encoding.h" +#include + +#ifndef _SIFIVE_COREPLEXIP_ARTY_H +#error 'global_interrupts' demo only supported for Coreplex IP Eval Kits +#endif + +// Global Instance data for the PLIC +// for use by the PLIC Driver. +plic_instance_t g_plic; + +// Structures for registering different interrupt handlers +// for different parts of the application. +typedef void (*interrupt_function_ptr_t) (void); +//array of function pointers which contains the PLIC +//interrupt handlers +interrupt_function_ptr_t g_ext_interrupt_handlers[PLIC_NUM_INTERRUPTS]; + +const char * instructions_msg = " \ +\n\ + SIFIVE, INC.\n\ +E31/E51 Coreplex IP Eval Kit 'vectored_interrupts' demo. \n\ +\n\ +This demo demonstrates Vectored Interrupts capabilities of\n\ +the E31/E51 Coreplex. The vector table is defined in \n\ +bsp/env/ventry.S \n\ +Button 0 is a global external interrupt routed to the PLIC.\n\ +Button 1 is a local interrupt.\n\ +\n"; + +void print_instructions() { + + write (STDOUT_FILENO, instructions_msg, strlen(instructions_msg)); + +} + +void set_timer() { + + volatile uint64_t * mtime = (uint64_t*) (CLINT_CTRL_ADDR + CLINT_MTIME); + volatile uint64_t * mtimecmp = (uint64_t*) (CLINT_CTRL_ADDR + CLINT_MTIMECMP); + uint64_t now = *mtime; + uint64_t then = now + 1*RTC_FREQ; + *mtimecmp = then; + + set_csr(mie, MIP_MTIP); +} + +/*Entry Point for Machine Timer Interrupt Handler*/ +/*called from bsp/env/ventry.s */ +void handle_m_time_interrupt(){ + static uint32_t onoff=1; + + clear_csr(mie, MIP_MTIP); + + // Set Green LED + if(onoff) { + GPIO_REG(GPIO_OUTPUT_VAL) |= (0x1 << GREEN_LED_OFFSET) ; + onoff=0; + }else { + GPIO_REG(GPIO_OUTPUT_VAL) &= ~((0x1 << GREEN_LED_OFFSET)) ; + onoff=1; + } + set_timer(); + + //re-enable button1 irq + set_csr(mie, MIP_MLIP(LOCAL_INT_BTN_1)); + +} + +/*Synchronous Trap Handler*/ +/*called from bsp/env/ventry.s */ +void handle_sync_trap(uintptr_t mcause, uintptr_t epc ) { + write(1, "vUnhandled Trap:\n", 16); + _exit(1 + mcause); +} + +/*Entry Point for PLIC Interrupt Handler*/ +/*called from bsp/env/ventry.s */ +void handle_m_external_interrupt(){ + printf("In PLIC handler\n"); + plic_source int_num = PLIC_claim_interrupt(&g_plic); + if ((int_num >=1 ) && (int_num < PLIC_NUM_INTERRUPTS)) { + g_ext_interrupt_handlers[int_num](); + } + else { + exit(1 + (uintptr_t) int_num); + } + PLIC_complete_interrupt(&g_plic, int_num); +} + +//default empty PLIC handler +void invalid_global_isr() { + printf("Unexpected global interrupt!\n"); +} + +/* b1 global interrupt isr */ +/*called from handle_m_external_interrupt */ +void button_0_handler() { + static uint32_t onoff=1; + // Set Green LED + + printf("In Button 0 handler\n"); + + if(onoff) { + GPIO_REG(GPIO_OUTPUT_VAL) |= (0x1 << BLUE_LED_OFFSET) ; + onoff=0; + }else { + GPIO_REG(GPIO_OUTPUT_VAL) &= ~((0x1 << BLUE_LED_OFFSET)) ; + onoff=1; + } + + //clear irq - interrupt pending register is write 1 to clear + GPIO_REG(GPIO_FALL_IP) |= (1< Date: Wed, 26 Jul 2017 09:05:05 -0500 Subject: fixed comments --- software/vectored_interrupts/vectored_interrupts.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'software') diff --git a/software/vectored_interrupts/vectored_interrupts.c b/software/vectored_interrupts/vectored_interrupts.c index 61eee5e..8958105 100644 --- a/software/vectored_interrupts/vectored_interrupts.c +++ b/software/vectored_interrupts/vectored_interrupts.c @@ -100,7 +100,7 @@ void invalid_global_isr() { printf("Unexpected global interrupt!\n"); } -/* b1 global interrupt isr */ +/* b0 global interrupt isr */ /*called from handle_m_external_interrupt */ void button_0_handler() { static uint32_t onoff=1; @@ -136,7 +136,7 @@ void handle_local_interrupt5() { onoff=1; } - //debounce by turing off until next timer tick + //debounce by turning off until next timer tick clear_csr(mie, MIP_MLIP(LOCAL_INT_BTN_1)); } -- cgit v1.2.3 From 1f845553419f4683312cd0f8f7a3ecc9e5f09609 Mon Sep 17 00:00:00 2001 From: Drew Barbier Date: Wed, 26 Jul 2017 09:07:19 -0500 Subject: removed bin file commited by accident --- software/vectored_interrupts/vectored_interrupts | Bin 188880 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100755 software/vectored_interrupts/vectored_interrupts (limited to 'software') diff --git a/software/vectored_interrupts/vectored_interrupts b/software/vectored_interrupts/vectored_interrupts deleted file mode 100755 index fd85e7e..0000000 Binary files a/software/vectored_interrupts/vectored_interrupts and /dev/null differ -- cgit v1.2.3 From 7ce4b61da3e41c441c3634352782abc9819adf39 Mon Sep 17 00:00:00 2001 From: Drew Barbier Date: Wed, 26 Jul 2017 15:49:18 -0500 Subject: changed synch trap entry to match other vectors --- software/vectored_interrupts/vectored_interrupts.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'software') diff --git a/software/vectored_interrupts/vectored_interrupts.c b/software/vectored_interrupts/vectored_interrupts.c index 8958105..06b9620 100644 --- a/software/vectored_interrupts/vectored_interrupts.c +++ b/software/vectored_interrupts/vectored_interrupts.c @@ -76,9 +76,9 @@ void handle_m_time_interrupt(){ /*Synchronous Trap Handler*/ /*called from bsp/env/ventry.s */ -void handle_sync_trap(uintptr_t mcause, uintptr_t epc ) { +void handle_sync_trap( ) { write(1, "vUnhandled Trap:\n", 16); - _exit(1 + mcause); + _exit(1 + read_csr(mcause)); } /*Entry Point for PLIC Interrupt Handler*/ -- cgit v1.2.3