summaryrefslogtreecommitdiff
path: root/software
diff options
context:
space:
mode:
authorMegan Wachs <megan@sifive.com>2017-02-02 11:40:13 -0800
committerGitHub <noreply@github.com>2017-02-02 11:40:13 -0800
commitb7c778c4e0b26e719226053a204142c0cb54dd4b (patch)
tree88405c74373d0d04da351aff5f2cf92dcf11d2a9 /software
parent55136a72df6f6f64793be7ead298434d01721dc5 (diff)
parent557c3ed0dc025b73a919f3e2a4068808092f48c1 (diff)
Merge pull request #50 from sifive/common_plic
FE-203 Move plic_driver code to a common location.
Diffstat (limited to 'software')
-rw-r--r--software/demo_gpio/Makefile6
-rw-r--r--software/demo_gpio/demo_gpio.c2
-rw-r--r--software/demo_gpio/plic_driver.c127
-rw-r--r--software/demo_gpio/plic_driver.h46
4 files changed, 5 insertions, 176 deletions
diff --git a/software/demo_gpio/Makefile b/software/demo_gpio/Makefile
index 04a11b7..b181c5f 100644
--- a/software/demo_gpio/Makefile
+++ b/software/demo_gpio/Makefile
@@ -1,7 +1,9 @@
TARGET = demo_gpio
-C_SRCS += demo_gpio.c
-C_SRCS += plic_driver.c
CFLAGS += -O2 -fno-builtin-printf -DUSE_PLIC -DUSE_M_TIME
BSP_BASE = ../../bsp
+
+C_SRCS += demo_gpio.c
+C_SRCS += $(BSP_BASE)/drivers/plic/plic_driver.c
+
include $(BSP_BASE)/env/common.mk
diff --git a/software/demo_gpio/demo_gpio.c b/software/demo_gpio/demo_gpio.c
index 00bc8cd..bfa388e 100644
--- a/software/demo_gpio/demo_gpio.c
+++ b/software/demo_gpio/demo_gpio.c
@@ -4,7 +4,7 @@
#include <stdlib.h>
#include "platform.h"
#include <string.h>
-#include "plic_driver.h"
+#include "plic/plic_driver.h"
#include "encoding.h"
#include <unistd.h>
#include "stdatomic.h"
diff --git a/software/demo_gpio/plic_driver.c b/software/demo_gpio/plic_driver.c
deleted file mode 100644
index 01b7e6e..0000000
--- a/software/demo_gpio/plic_driver.c
+++ /dev/null
@@ -1,127 +0,0 @@
-// See LICENSE for license details.
-
-#include "sifive/devices/plic.h"
-#include "plic_driver.h"
-#include "platform.h"
-#include "encoding.h"
-#include <string.h>
-
-
-// Note that there are no assertions or bounds checking on these
-// parameter values.
-
-void volatile_memzero(uint8_t * base, unsigned int size)
-{
- volatile uint8_t * ptr;
- for (ptr = base; ptr < (base + size); ptr++){
- *ptr = 0;
- }
-}
-
-void PLIC_init (
- plic_instance_t * this_plic,
- uintptr_t base_addr,
- uint32_t num_sources,
- uint32_t num_priorities
- )
-{
-
- this_plic->base_addr = base_addr;
- this_plic->num_sources = num_sources;
- this_plic->num_priorities = num_priorities;
-
- // Disable all interrupts (don't assume that these registers are reset).
- unsigned long hart_id = read_csr(mhartid);
- volatile_memzero((uint8_t*) (this_plic->base_addr +
- PLIC_ENABLE_OFFSET +
- (hart_id << PLIC_ENABLE_SHIFT_PER_TARGET)),
- (num_sources + 8) / 8);
-
- // Set all priorities to 0 (equal priority -- don't assume that these are reset).
- volatile_memzero ((uint8_t *)(this_plic->base_addr +
- PLIC_PRIORITY_OFFSET),
- (num_sources + 1) << PLIC_PRIORITY_SHIFT_PER_SOURCE);
-
- // Set the threshold to 0.
- volatile plic_threshold* threshold = (plic_threshold*)
- (this_plic->base_addr +
- PLIC_THRESHOLD_OFFSET +
- (hart_id << PLIC_THRESHOLD_SHIFT_PER_TARGET));
-
- *threshold = 0;
-
-}
-
-void PLIC_set_threshold (plic_instance_t * this_plic,
- plic_threshold threshold){
-
- unsigned long hart_id = read_csr(mhartid);
- volatile plic_threshold* threshold_ptr = (plic_threshold*) (this_plic->base_addr +
- PLIC_THRESHOLD_OFFSET +
- (hart_id << PLIC_THRESHOLD_SHIFT_PER_TARGET));
-
- *threshold_ptr = threshold;
-
-}
-
-
-void PLIC_enable_interrupt (plic_instance_t * this_plic, plic_source source){
-
- unsigned long hart_id = read_csr(mhartid);
- volatile uint8_t * current_ptr = (volatile uint8_t *)(this_plic->base_addr +
- PLIC_ENABLE_OFFSET +
- (hart_id << PLIC_ENABLE_SHIFT_PER_TARGET) +
- (source >> 3));
- uint8_t current = *current_ptr;
- current = current | ( 1 << (source & 0x7));
- *current_ptr = current;
-
-}
-
-void PLIC_disable_interrupt (plic_instance_t * this_plic, plic_source source){
-
- unsigned long hart_id = read_csr(mhartid);
- volatile uint8_t * current_ptr = (volatile uint8_t *) (this_plic->base_addr +
- PLIC_ENABLE_OFFSET +
- (hart_id << PLIC_ENABLE_SHIFT_PER_TARGET) +
- (source >> 3));
- uint8_t current = *current_ptr;
- current = current & ~(( 1 << (source & 0x7)));
- *current_ptr = current;
-
-}
-
-void PLIC_set_priority (plic_instance_t * this_plic, plic_source source, plic_priority priority){
-
- if (this_plic->num_priorities > 0) {
- volatile plic_priority * priority_ptr = (volatile plic_priority *)
- (this_plic->base_addr +
- PLIC_PRIORITY_OFFSET +
- (source << PLIC_PRIORITY_SHIFT_PER_SOURCE));
- *priority_ptr = priority;
- }
-}
-
-plic_source PLIC_claim_interrupt(plic_instance_t * this_plic){
-
- unsigned long hart_id = read_csr(mhartid);
-
- volatile plic_source * claim_addr = (volatile plic_source * )
- (this_plic->base_addr +
- PLIC_CLAIM_OFFSET +
- (hart_id << PLIC_CLAIM_SHIFT_PER_TARGET));
-
- return *claim_addr;
-
-}
-
-void PLIC_complete_interrupt(plic_instance_t * this_plic, plic_source source){
-
- unsigned long hart_id = read_csr(mhartid);
- volatile plic_source * claim_addr = (volatile plic_source *) (this_plic->base_addr +
- PLIC_CLAIM_OFFSET +
- (hart_id << PLIC_CLAIM_SHIFT_PER_TARGET));
- *claim_addr = source;
-
-}
-
diff --git a/software/demo_gpio/plic_driver.h b/software/demo_gpio/plic_driver.h
deleted file mode 100644
index 66410be..0000000
--- a/software/demo_gpio/plic_driver.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// See LICENSE file for licence details
-
-#ifndef PLIC_DRIVER_H
-#define PLIC_DRIVER_H
-
-#include "platform.h"
-
-typedef struct __plic_instance_t
-{
- uintptr_t base_addr;
-
- uint32_t num_sources;
- uint32_t num_priorities;
-
-} plic_instance_t;
-
-typedef uint32_t plic_source;
-typedef uint32_t plic_priority;
-typedef uint32_t plic_threshold;
-
-void PLIC_init (
- plic_instance_t * this_plic,
- uintptr_t base_addr,
- uint32_t num_sources,
- uint32_t num_priorities
- );
-
-void PLIC_set_threshold (plic_instance_t * this_plic,
- plic_threshold threshold);
-
-void PLIC_enable_interrupt (plic_instance_t * this_plic,
- plic_source source);
-
-void PLIC_disable_interrupt (plic_instance_t * this_plic,
- plic_source source);
-
-void PLIC_set_priority (plic_instance_t * this_plic,
- plic_source source,
- plic_priority priority);
-
-plic_source PLIC_claim_interrupt(plic_instance_t * this_plic);
-
-void PLIC_complete_interrupt(plic_instance_t * this_plic,
- plic_source source);
-
-#endif