1 /*
2  * Copyright (C) 2019 ETH Zurich and University of Bologna
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  * Author: Robert Balas (balasr@iis.ee.ethz.ch)
18  */
19 
20 /* Driver to control and configure the PULP IRQ (apb_interrupt_control)*/
21 
22 #include <csr.h>
23 #include <pulp_io.h>
24 #include <stdint.h>
25 #include "core-v-mcu-pulp-mem-map.h"
26 #include "hal_irq.h"
27 
28 /* utility functions for PULPs external interrupt controller */
irq_mask(uint32_t mask)29 void irq_mask(uint32_t mask)
30 {
31 	writew(mask, (uintptr_t)(PULP_FC_IRQ_ADDR + IRQ_REG_MASK_OFFSET));
32 }
33 
irq_enable(uint32_t mask)34 void irq_enable(uint32_t mask)
35 {
36 	writew(mask, (uintptr_t)(PULP_FC_IRQ_ADDR + IRQ_REG_MASK_SET_OFFSET));
37 }
38 
irq_disable(uint32_t mask)39 void irq_disable(uint32_t mask)
40 {
41 	writew(mask, (uintptr_t)(PULP_FC_IRQ_ADDR + IRQ_REG_MASK_CLEAR_OFFSET));
42 }
43 
44 /* utility functions for the core level interrupt (CLINT) described in the
45  * RISC-V privileged specification */
46 
irq_clint_disable()47 uint32_t irq_clint_disable()
48 {
49 	uint32_t val = csr_read_clear(CSR_MSTATUS, MSTATUS_IE);
50 	return val;
51 }
52 
irq_clint_enable()53 uint32_t irq_clint_enable()
54 {
55 	uint32_t val = 0;
56 	val = csr_read(CSR_MSTATUS);
57 
58 	val = csr_read_set(CSR_MSTATUS, MSTATUS_IE);
59 
60 	val = csr_read(CSR_MSTATUS);
61 	return val;
62 }
63 
64 /* TODO: make this a constructor? */
irq_init()65 void irq_init()
66 {
67 	/* the debug module could have enabled irq so we disable it during
68 	 * initialization
69 	 */
70 	irq_disable(0xffffffff);
71 }
72 
73