1 // See LICENSE for license details.
\r
3 #ifndef _SIFIVE_PLATFORM_H
\r
4 #define _SIFIVE_PLATFORM_H
\r
6 // Some things missing from the official encoding.h
\r
7 #define MCAUSE_INT 0x80000000
\r
8 #define MCAUSE_CAUSE 0x7FFFFFFF
\r
10 #include "sifive/const.h"
\r
11 #include "sifive/devices/aon.h"
\r
12 #include "sifive/devices/clint.h"
\r
13 #include "sifive/devices/gpio.h"
\r
14 #include "sifive/devices/otp.h"
\r
15 #include "sifive/devices/plic.h"
\r
16 #include "sifive/devices/prci.h"
\r
17 #include "sifive/devices/pwm.h"
\r
18 #include "sifive/devices/spi.h"
\r
19 #include "sifive/devices/uart.h"
\r
21 /****************************************************************************
\r
22 * Platform definitions
\r
23 *****************************************************************************/
\r
26 #define MASKROM_MEM_ADDR _AC(0x00001000,UL)
\r
27 #define TRAPVEC_TABLE_CTRL_ADDR _AC(0x00001010,UL)
\r
28 #define OTP_MEM_ADDR _AC(0x00020000,UL)
\r
29 #define CLINT_CTRL_ADDR _AC(0x02000000,UL)
\r
30 #define PLIC_CTRL_ADDR _AC(0x0C000000,UL)
\r
31 #define AON_CTRL_ADDR _AC(0x10000000,UL)
\r
32 #define PRCI_CTRL_ADDR _AC(0x10008000,UL)
\r
33 #define OTP_CTRL_ADDR _AC(0x10010000,UL)
\r
34 #define GPIO_CTRL_ADDR _AC(0x10012000,UL)
\r
35 #define UART0_CTRL_ADDR _AC(0x10013000,UL)
\r
36 #define SPI0_CTRL_ADDR _AC(0x10014000,UL)
\r
37 #define PWM0_CTRL_ADDR _AC(0x10015000,UL)
\r
38 #define UART1_CTRL_ADDR _AC(0x10023000,UL)
\r
39 #define SPI1_CTRL_ADDR _AC(0x10024000,UL)
\r
40 #define PWM1_CTRL_ADDR _AC(0x10025000,UL)
\r
41 #define SPI2_CTRL_ADDR _AC(0x10034000,UL)
\r
42 #define PWM2_CTRL_ADDR _AC(0x10035000,UL)
\r
43 #define SPI0_MEM_ADDR _AC(0x20000000,UL)
\r
44 #define MEM_CTRL_ADDR _AC(0x80000000,UL)
\r
47 #define IOF0_SPI1_MASK _AC(0x000007FC,UL)
\r
48 #define SPI11_NUM_SS (4)
\r
49 #define IOF_SPI1_SS0 (2u)
\r
50 #define IOF_SPI1_SS1 (8u)
\r
51 #define IOF_SPI1_SS2 (9u)
\r
52 #define IOF_SPI1_SS3 (10u)
\r
53 #define IOF_SPI1_MOSI (3u)
\r
54 #define IOF_SPI1_MISO (4u)
\r
55 #define IOF_SPI1_SCK (5u)
\r
56 #define IOF_SPI1_DQ0 (3u)
\r
57 #define IOF_SPI1_DQ1 (4u)
\r
58 #define IOF_SPI1_DQ2 (6u)
\r
59 #define IOF_SPI1_DQ3 (7u)
\r
61 #define IOF0_SPI2_MASK _AC(0xFC000000,UL)
\r
62 #define SPI2_NUM_SS (1)
\r
63 #define IOF_SPI2_SS0 (26u)
\r
64 #define IOF_SPI2_MOSI (27u)
\r
65 #define IOF_SPI2_MISO (28u)
\r
66 #define IOF_SPI2_SCK (29u)
\r
67 #define IOF_SPI2_DQ0 (27u)
\r
68 #define IOF_SPI2_DQ1 (28u)
\r
69 #define IOF_SPI2_DQ2 (30u)
\r
70 #define IOF_SPI2_DQ3 (31u)
\r
72 //#define IOF0_I2C_MASK _AC(0x00003000,UL)
\r
74 #define IOF0_UART0_MASK _AC(0x00030000, UL)
\r
75 #define IOF_UART0_RX (16u)
\r
76 #define IOF_UART0_TX (17u)
\r
78 #define IOF0_UART1_MASK _AC(0x03000000, UL)
\r
79 #define IOF_UART1_RX (24u)
\r
80 #define IOF_UART1_TX (25u)
\r
82 #define IOF1_PWM0_MASK _AC(0x0000000F, UL)
\r
83 #define IOF1_PWM1_MASK _AC(0x00780000, UL)
\r
84 #define IOF1_PWM2_MASK _AC(0x00003C00, UL)
\r
86 // Interrupt numbers
\r
87 #define INT_RESERVED 0
\r
88 #define INT_WDOGCMP 1
\r
89 #define INT_RTCCMP 2
\r
90 #define INT_UART0_BASE 3
\r
91 #define INT_UART1_BASE 4
\r
92 #define INT_SPI0_BASE 5
\r
93 #define INT_SPI1_BASE 6
\r
94 #define INT_SPI2_BASE 7
\r
95 #define INT_GPIO_BASE 8
\r
96 #define INT_PWM0_BASE 40
\r
97 #define INT_PWM1_BASE 44
\r
98 #define INT_PWM2_BASE 48
\r
100 // Helper functions
\r
101 #define _REG32(p, i) (*(volatile uint32_t *) ((p) + (i)))
\r
102 #define _REG32P(p, i) ((volatile uint32_t *) ((p) + (i)))
\r
103 #define AON_REG(offset) _REG32(AON_CTRL_ADDR, offset)
\r
104 #define CLINT_REG(offset) _REG32(CLINT_CTRL_ADDR, offset)
\r
105 #define GPIO_REG(offset) _REG32(GPIO_CTRL_ADDR, offset)
\r
106 #define OTP_REG(offset) _REG32(OTP_CTRL_ADDR, offset)
\r
107 #define PLIC_REG(offset) _REG32(PLIC_CTRL_ADDR, offset)
\r
108 #define PRCI_REG(offset) _REG32(PRCI_CTRL_ADDR, offset)
\r
109 #define PWM0_REG(offset) _REG32(PWM0_CTRL_ADDR, offset)
\r
110 #define PWM1_REG(offset) _REG32(PWM1_CTRL_ADDR, offset)
\r
111 #define PWM2_REG(offset) _REG32(PWM2_CTRL_ADDR, offset)
\r
112 #define SPI0_REG(offset) _REG32(SPI0_CTRL_ADDR, offset)
\r
113 #define SPI1_REG(offset) _REG32(SPI1_CTRL_ADDR, offset)
\r
114 #define SPI2_REG(offset) _REG32(SPI2_CTRL_ADDR, offset)
\r
115 #define UART0_REG(offset) _REG32(UART0_CTRL_ADDR, offset)
\r
116 #define UART1_REG(offset) _REG32(UART1_CTRL_ADDR, offset)
\r
120 #include <stdint.h>
\r
122 #define NUM_GPIO 32
\r
124 #define PLIC_NUM_INTERRUPTS 52
\r
125 #define PLIC_NUM_PRIORITIES 7
\r
127 #include "hifive1.h"
\r
129 unsigned long get_cpu_freq(void);
\r
130 unsigned long get_timer_freq(void);
\r
131 uint64_t get_timer_value(void);
\r
133 #endif /* _SIFIVE_PLATFORM_H */
\r