summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew Barbier <dbarbi1@gmail.com>2018-07-04 18:48:19 -0500
committerDrew Barbier <dbarbi1@gmail.com>2018-07-04 18:48:19 -0500
commit962b23a3797ba659577056ed3fc57c2d0a77df62 (patch)
tree4346d81c75ac2458bef05ee450d4edfbcc2d0ed1
parent9d58b2120c5a9b9dbc95c0ea90b16280e36dc9ca (diff)
clic driver level and priority functions
-rw-r--r--bsp/drivers/clic/clic_driver.c75
-rw-r--r--bsp/drivers/clic/clic_driver.h8
-rw-r--r--bsp/env/coreip-e2-arty/platform.h2
-rw-r--r--software/clic_vectored/clic_vectored.c23
4 files changed, 97 insertions, 11 deletions
diff --git a/bsp/drivers/clic/clic_driver.c b/bsp/drivers/clic/clic_driver.c
index a4c4694..66b24d6 100644
--- a/bsp/drivers/clic/clic_driver.c
+++ b/bsp/drivers/clic/clic_driver.c
@@ -83,6 +83,81 @@ uint8_t clic_get_cliccfg (clic_instance_t * this_clic){
return *(volatile uint8_t*)(this_clic->hart_addr+CLIC_CFG);
}
+//sets an interrupt level based encoding of nmbits, nlbits
+uint8_t clic_set_int_level( clic_instance_t * this_clic, uint32_t source, uint8_t level) {
+ //extract nlbits
+ uint8_t nlbits = clic_get_cliccfg(this_clic);
+ nlbits = (nlbits >>1) & 0x7;
+
+ //shift level right to mask off unused bits
+ level = level>>((this_clic->num_config_bits)-nlbits); //plus this_clic->nmbits which is always 0 for now.
+ //shift level into correct bit position
+ level = level << (8-((this_clic->num_config_bits)-nlbits));
+
+ //write to clicintcfg
+ uint8_t current_intcfg = clic_get_intcfg(this_clic, source);
+ clic_set_intcfg(this_clic, source, (current_intcfg | level));
+
+ return level;
+}
+
+//gets an interrupt level based encoding of nmbits, nlbits
+uint8_t clic_get_int_level( clic_instance_t * this_clic, uint32_t source) {
+ uint8_t level;
+ level = clic_get_intcfg(this_clic, source);
+
+ //extract nlbits
+ uint8_t nlbits = clic_get_cliccfg(this_clic);
+ nlbits = (nlbits >>1) & 0x7;
+
+ //shift level
+ level = level >> (8-(this_clic->num_config_bits));
+ //shift level right to mask off priority bits
+ level = level>>((this_clic->num_config_bits)-nlbits); //this_clic->nmbits which is always 0 for now.
+
+ return level;
+}
+
+//sets an interrupt priority based encoding of nmbits, nlbits
+uint8_t clic_set_int_priority( clic_instance_t * this_clic, uint32_t source, uint8_t priority) {
+ //priority bits = num_config_bits - nlbits
+ //extract nlbits
+ uint8_t nlbits = clic_get_cliccfg(this_clic);
+ nlbits = (nlbits >>1) & 0x7;
+
+ uint8_t priority_bits = this_clic->num_config_bits-nlbits;
+ if(priority_bits = 0) {
+ //no bits to set
+ return 0;
+ }
+ //mask off unused bits
+ priority = priority >> (8-priority_bits);
+ //shift into the correct bit position
+ priority = priority << (8-(this_clic->num_config_bits));
+
+ //write to clicintcfg
+ uint8_t current_intcfg = clic_get_intcfg(this_clic, source);
+ clic_set_intcfg(this_clic, source, (current_intcfg | priority));
+ return current_intcfg;
+}
+
+//gets an interrupt priority based encoding of nmbits, nlbits
+uint8_t clic_get_int_priority( clic_instance_t * this_clic, uint32_t source) {
+ uint8_t priority;
+ priority = clic_get_intcfg(this_clic, source);
+
+ //extract nlbits
+ uint8_t nlbits = clic_get_cliccfg(this_clic);
+ nlbits = (nlbits >>1) & 0x7;
+
+ //shift left to mask off level bits
+ priority = priority << nlbits;
+
+ //shift priority
+ priority = priority >> (8-((this_clic->num_config_bits)+nlbits));
+
+ return priority;
+}
diff --git a/bsp/drivers/clic/clic_driver.h b/bsp/drivers/clic/clic_driver.h
index 1fd9bb6..27c34c2 100644
--- a/bsp/drivers/clic/clic_driver.h
+++ b/bsp/drivers/clic/clic_driver.h
@@ -30,6 +30,14 @@ void clic_set_intcfg (clic_instance_t * this_clic, uint32_t source, uint32_t int
uint8_t clic_get_intcfg (clic_instance_t * this_clic, uint32_t source);
void clic_set_cliccfg (clic_instance_t * this_clic, uint32_t cfg);
uint8_t clic_get_cliccfg (clic_instance_t * this_clic);
+//sets an interrupt level based encoding of nmbits, nlbits
+uint8_t clic_set_int_level( clic_instance_t * this_clic, uint32_t source, uint8_t level);
+//get an interrupt level based encoding of nmbits, nlbits
+uint8_t clic_get_int_level( clic_instance_t * this_clic, uint32_t source);
+//sets an interrupt priority based encoding of nmbits, nlbits
+uint8_t clic_set_int_priority( clic_instance_t * this_clic, uint32_t source, uint8_t priority);
+//sets an interrupt priority based encoding of nmbits, nlbits
+uint8_t clic_get_int_priority( clic_instance_t * this_clic, uint32_t source);
__END_DECLS
diff --git a/bsp/env/coreip-e2-arty/platform.h b/bsp/env/coreip-e2-arty/platform.h
index 305726d..ba06160 100644
--- a/bsp/env/coreip-e2-arty/platform.h
+++ b/bsp/env/coreip-e2-arty/platform.h
@@ -79,7 +79,7 @@
#define NUM_GPIO 16
#define CLIC_NUM_INTERRUPTS 28 + 16
-#define CLIC_CONFIG_BITS 0x1E //2 for E20
+#define CLIC_CONFIG_BITS 4
#define HAS_BOARD_BUTTONS
diff --git a/software/clic_vectored/clic_vectored.c b/software/clic_vectored/clic_vectored.c
index cbc104e..872aba3 100644
--- a/software/clic_vectored/clic_vectored.c
+++ b/software/clic_vectored/clic_vectored.c
@@ -53,7 +53,8 @@ void wait_ms(uint64_t ms) {
void button_0_isr(void) __attribute__((interrupt));
void button_0_isr(void) {
// Toggle Red LED
- printf("Button 0 was pressed. Toggle Red.\n");
+ uint8_t level = clic_get_int_level(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_0));
+ printf("Button 0 was pressed, interrupt level %d. Toggle Red.\n", level);
GPIO_REG(GPIO_OUTPUT_VAL) = GPIO_REG(GPIO_OUTPUT_VAL) ^ (0x1 << RED_LED_OFFSET);
wait_ms(500);
clic_enable_interrupt(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_0));
@@ -62,14 +63,15 @@ void button_0_isr(void) {
void button_0_setup(void) {
clic_install_handler(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_0), button_0_isr);
- clic_set_intcfg(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_0), 1<<4);
+ clic_set_int_level(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_0), 1);
clic_enable_interrupt(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_0));
}
void button_1_isr(void) __attribute__((interrupt));
void button_1_isr(void) {
// Toggle Red LED
- printf("Button 1 was pressed. Toggle Blue.\n");
+ uint8_t level = clic_get_int_level(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_1));
+ printf("Button 1 was pressed, interrupt level %d. Toggle Blue.\n", level);
GPIO_REG(GPIO_OUTPUT_VAL) = GPIO_REG(GPIO_OUTPUT_VAL) ^ (0x1 << BLUE_LED_OFFSET);
wait_ms(500);
clic_enable_interrupt(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_1));
@@ -78,14 +80,15 @@ void button_1_isr(void) {
void button_1_setup(void) {
clic_install_handler(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_1), button_1_isr);
- clic_set_intcfg(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_1), 2<<4);
+ clic_set_int_level(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_1), 2);
clic_enable_interrupt(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_1));
}
void button_2_isr(void) __attribute__((interrupt));
void button_2_isr(void) {
// Toggle Red LED
- printf("Button 2 was pressed. Toggle Green.\n");
+ uint8_t level = clic_get_int_level(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_2));
+ printf("Button 2 was pressed, interrupt level %d. Toggle Green.\n", level);
GPIO_REG(GPIO_OUTPUT_VAL) = GPIO_REG(GPIO_OUTPUT_VAL) ^ (0x1 << GREEN_LED_OFFSET);
wait_ms(500);
clic_enable_interrupt(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_2));
@@ -94,7 +97,7 @@ void button_2_isr(void) {
void button_2_setup(void) {
clic_install_handler(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_2), button_2_isr);
- clic_set_intcfg(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_2), 3<<4);
+ clic_set_int_level(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_2), 3);
clic_enable_interrupt(&clic, (LOCALINTIDBASE + LOCAL_INT_BTN_2));
}
@@ -104,12 +107,12 @@ void msi_isr()__attribute((interrupt));
void msi_isr() {
//clear the SW interrupt
CLINT_REG(CLINT_MSIP) = 0;
- COUNT++;
+ COUNT++;
}
void msi_setup(void) {
clic_install_handler(&clic, MSIPID, msi_isr);
- clic_set_intcfg(&clic, MSIPID, 1<<4);
+ clic_set_int_level(&clic, MSIPID, 1);
clic_enable_interrupt(&clic, MSIPID);
}
@@ -133,8 +136,8 @@ int main(int argc, char **argv)
CLIC_NUM_INTERRUPTS,
CLIC_CONFIG_BITS);
- //use all 4 config bits for levels
- clic_set_cliccfg(&clic, CLIC_CONFIG_BITS);
+ //use all 4 config bits for levels, no shv
+ clic_set_cliccfg(&clic, ((CLIC_CONFIG_BITS<<1)|0));
//initialize gpio and buttons.
//each button registers an interrupt handler