OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [lib/] [include/] [neorv32.h] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 zero_gravi
// #################################################################################################
2
// # << NEORV32: neorv32.h - Main Core Library File >>                                             #
3
// # ********************************************************************************************* #
4
// # BSD 3-Clause License                                                                          #
5
// #                                                                                               #
6
// # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
7
// #                                                                                               #
8
// # Redistribution and use in source and binary forms, with or without modification, are          #
9
// # permitted provided that the following conditions are met:                                     #
10
// #                                                                                               #
11
// # 1. Redistributions of source code must retain the above copyright notice, this list of        #
12
// #    conditions and the following disclaimer.                                                   #
13
// #                                                                                               #
14
// # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
15
// #    conditions and the following disclaimer in the documentation and/or other materials        #
16
// #    provided with the distribution.                                                            #
17
// #                                                                                               #
18
// # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
19
// #    endorse or promote products derived from this software without specific prior written      #
20
// #    permission.                                                                                #
21
// #                                                                                               #
22
// # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
23
// # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
24
// # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
25
// # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
26
// # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
27
// # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
28
// # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
29
// # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
30
// # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
31
// # ********************************************************************************************* #
32
// # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
33
// #################################################################################################
34
 
35
 
36
/**********************************************************************//**
37
 * @file neorv32.h
38
 * @author Stephan Nolting
39
 * @date 30 May 2020
40
 *
41
 * @brief Main NEORV32 core library file.
42
 *
43
 * @details This file defines the addresses of the IO devices and their according
44
 * registers and register bits as well as the available CPU CSRs and flags.
45
 **************************************************************************/
46
 
47
#ifndef neorv32_h
48
#define neorv32_h
49
 
50
// Standard libraries
51
#include <stdint.h>
52
#include <stdlib.h>
53
#include <string.h>
54
#include <stdbool.h>
55
#include <inttypes.h>
56
#include <limits.h>
57
 
58
 
59
/**********************************************************************//**
60
 * Available CPU Control and Status Registers (CSRs)
61
 **************************************************************************/
62
enum NEORV32_CPU_CSRS_enum {
63 6 zero_gravi
  CSR_MSTATUS     = 0x300, /**< 0x300 - mstatus (r/w): Machine status register */
64
  CSR_MISA        = 0x301, /**< 0x301 - misa    (r/-): CPU ISA and extensions */
65
  CSR_MIE         = 0x304, /**< 0x304 - mie     (r/w): Machine interrupt-enable register */
66
  CSR_MTVEC       = 0x305, /**< 0x305 - mtvec   (r/w): Machine trap-handler base address (for ALL traps) */
67 2 zero_gravi
 
68
  CSR_MSCRATCH    = 0x340, /**< 0x340 - mscratch (r/w): Machine scratch register */
69
  CSR_MEPC        = 0x341, /**< 0x341 - mepc     (r/w): Machine exception program counter */
70
  CSR_MCAUSE      = 0x342, /**< 0x342 - mcause   (r/-): Machine trap cause */
71
  CSR_MTVAL       = 0x343, /**< 0x343 - mtval    (r/-): Machine bad address or instruction */
72
  CSR_MIP         = 0x344, /**< 0x344 - mip      (r/w): Machine interrupt pending register */
73
  CSR_MTINST      = 0x34a, /**< 0x34a - mtinst   (r/-): Machine trap instruction (transformed) */
74
 
75
  CSR_MCYCLE      = 0xb00, /**< 0xb00 - mcycle    (r/-): Machine cycle counter low word */
76
  CSR_MINSTRET    = 0xb02, /**< 0xb02 - minstret  (r/-): Machine instructions-retired counter low word */
77
  CSR_MCYCLEH     = 0xb80, /**< 0xb80 - mcycleh   (r/-): Machine cycle counter high word */
78
  CSR_MINSTRETH   = 0xb82, /**< 0xb82 - minstreth (r/-): Machine instructions-retired counter high word */
79
 
80
  CSR_CYCLE       = 0xc00, /**< 0xc00 - cycle    (r/-): Cycle counter low word */
81
  CSR_TIME        = 0xc01, /**< 0xc01 - time     (r/-): Timer low word*/
82
  CSR_INSTRET     = 0xc02, /**< 0xc02 - instret  (r/-): Instructions-retired counter low word */
83
 
84
  CSR_CYCLEH      = 0xc80, /**< 0xc80 - cycleh   (r/-): Cycle counter high word */
85
  CSR_TIMEH       = 0xc81, /**< 0xc81 - timeh    (r/-): Timer high word*/
86
  CSR_INSTRETH    = 0xc82, /**< 0xc82 - instreth (r/-): Instructions-retired counter high word */
87
 
88
  CSR_MIMPID      = 0xf13, /**< 0xf13 - mimpid  (r/-): Implementation ID/version */
89
  CSR_MHARTID     = 0xf14, /**< 0xf14 - mhartid (r/-): Hardware thread ID (via HART_ID generic) */
90
 
91
  CSR_MFEATURES   = 0xfc0, /**< 0xfc0 - CUSTOM (r/-): Implemented processor devices/features (via IO_x_USE generics) */
92
  CSR_MCLOCK      = 0xfc1, /**< 0xfc1 - CUSTOM (r/-): Processor primary clock spedd in Hz (via CLOCK_FREQUENCY generic)*/
93
  CSR_MISPACEBASE = 0xfc4, /**< 0xfc4 - CUSTOM (r/-): Base address of instruction memory space (via MEM_ISPACE_BASE generic) */
94
  CSR_MDSPACEBASE = 0xfc5, /**< 0xfc5 - CUSTOM (r/-): Base address of data memory space (via MEM_DSPACE_BASE generic) */
95
  CSR_MISPACESIZE = 0xfc6, /**< 0xfc6 - CUSTOM (r/-): Total size of instruction memory space in byte (via MEM_ISPACE_SIZE generic) */
96
  CSR_MDSPACESIZE = 0xfc7  /**< 0xfc7 - CUSTOM (r/-): Total size of data memory space in byte (via MEM_DSPACE_SIZE generic) */
97
};
98
 
99
 
100
/**********************************************************************//**
101
 * CPU <b>mstatus</b> CSR (r/w): Machine status (RISC-V spec.)
102
 **************************************************************************/
103
enum NEORV32_CPU_MSTATUS_enum {
104
  CPU_MSTATUS_MIE  = 3, /**< CPU mstatus CSR (3): Machine interrupt enable bit (r/w) */
105
  CPU_MSTATUS_MPIE = 7  /**< CPU mstatus CSR (7): Machine previous interrupt enable bit (r/w) */
106
};
107
 
108
 
109
/**********************************************************************//**
110
 * CPU <b>mie</b> CSR (r/w): Machine interrupt enable (RISC-V spec.)
111
 **************************************************************************/
112
enum NEORV32_CPU_MIE_enum {
113
  CPU_MIE_MSIE  =  3, /**< CPU mie CSR (3): Machine software interrupt enable bit (r/w) */
114
  CPU_MIE_MTIE  =  7, /**< CPU mie CSR (7): Machine timer interrupt (MTIME) enable bit (r/w) */
115
  CPU_MIE_MEIE  = 11  /**< CPU mie CSR (11): Machine external interrupt (via CLIC) enable bit (r/w) */
116
};
117
 
118
 
119
/**********************************************************************//**
120
 * CPU <b>mip</b> CSR (r/w): Machine interrupt pending (RISC-V spec.)
121
 **************************************************************************/
122
enum NEORV32_CPU_MIP_enum {
123
  CPU_MIP_MSIP  =  3, /**< CPU mip CSR (3): Machine software interrupt pending (r/w), can be triggered when set */
124
  CPU_MIP_MTIP  =  7, /**< CPU mip CSR (7): Machine timer interrupt (MTIME) pending (r/-) */
125
  CPU_MIP_MEIP  = 11  /**< CPU mip CSR (11): Machine external interrupt (via CLIC) pending (r/-) */
126
};
127
 
128
 
129
/**********************************************************************//**
130 6 zero_gravi
 * CPU <b>misa</b> CSR (r/w): Machine instruction set extensions (RISC-V spec.)
131
 **************************************************************************/
132
enum NEORV32_CPU_MISA_enum {
133
  CPU_MISA_C_EXT      =  2, /**< CPU misa CSR  (2): C: Compressed instructions CPU extension available (r/w), can be switched on/off */
134
  CPU_MISA_E_EXT      =  4, /**< CPU misa CSR  (3): E: Embedded CPU extension available (r/-) */
135
  CPU_MISA_I_EXT      =  8, /**< CPU misa CSR  (8): I: Base integer ISA CPU extension available (r/-) */
136
  CPU_MISA_M_EXT      = 12, /**< CPU misa CSR (12): M: Multiplier/divider CPU extension available (r/w), can be switched on/off */
137
  CPU_MISA_X_EXT      = 23, /**< CPU misa CSR (23): X: Non-standard CPU extension available (r/-) */
138
  CPU_MISA_Z_EXT      = 25, /**< CPU misa CSR (25): Z: Privileged architecture CPU extension available (r/-) */
139
  CPU_MISA_MXL_LO_EXT = 30, /**< CPU misa CSR (30): MXL.lo: CPU data width (r/-) */
140
  CPU_MISA_MXL_HI_EXT = 31  /**< CPU misa CSR (31): MXL.Hi: CPU data width (r/-) */
141
};
142
 
143
 
144
/**********************************************************************//**
145 2 zero_gravi
 * CPU <b>mfeatures</b> CSR (r/-): Implemented processor devices/features (CUSTOM)
146
 **************************************************************************/
147
 enum NEORV32_CPU_MFEATURES_enum {
148
  CPU_MFEATURES_BOOTLOADER       =  0, /**< CPU mfeatures CSR (0) (r/-): Bootloader implemented when 1 (via BOOTLOADER_USE generic) */
149
  CPU_MFEATURES_MEM_EXT          =  1, /**< CPU mfeatures CSR (1) (r/-): External bus interface implemented when 1 (via MEM_EXT_USE generic) */
150
  CPU_MFEATURES_MEM_INT_IMEM     =  2, /**< CPU mfeatures CSR (2) (r/-): Processor-internal instruction memory implemented when 1 (via MEM_INT_IMEM_USE generic) */
151
  CPU_MFEATURES_MEM_INT_IMEM_ROM =  3, /**< CPU mfeatures CSR (3) (r/-): Processor-internal instruction memory implemented as ROM when 1 (via MEM_INT_IMEM_ROM generic) */
152
  CPU_MFEATURES_MEM_INT_DMEM     =  4, /**< CPU mfeatures CSR (4) (r/-): Processor-internal data memory implemented when 1 (via MEM_INT_DMEM_USE generic) */
153 6 zero_gravi
  CPU_MFEATURES_CSR_COUNTERS     =  5, /**< CPU mfeatures CSR (5) (r/-): RISC-V performance counters implemented when 1 (via CSR_COUNTERS_USE generic) */
154 2 zero_gravi
 
155
  CPU_MFEATURES_IO_GPIO          = 16, /**< CPU mfeatures CSR (16) (r/-): General purpose input/output port unit implemented when 1 (via IO_GPIO_USE generic) */
156
  CPU_MFEATURES_IO_MTIME         = 17, /**< CPU mfeatures CSR (17) (r/-): Machine system timer implemented when 1 (via IO_MTIME_USE generic) */
157
  CPU_MFEATURES_IO_UART          = 18, /**< CPU mfeatures CSR (18) (r/-): Universal asynchronous receiver/transmitter implemented when 1 (via IO_UART_USE generic) */
158
  CPU_MFEATURES_IO_SPI           = 19, /**< CPU mfeatures CSR (19) (r/-): Serial peripheral interface implemented when 1 (via IO_SPI_USE generic) */
159
  CPU_MFEATURES_IO_TWI           = 20, /**< CPU mfeatures CSR (20) (r/-): Two-wire interface implemented when 1 (via IO_TWI_USE generic) */
160
  CPU_MFEATURES_IO_PWM           = 21, /**< CPU mfeatures CSR (21) (r/-): Pulse-width modulation unit implemented when 1 (via IO_PWM_USE generic) */
161
  CPU_MFEATURES_IO_WDT           = 22, /**< CPU mfeatures CSR (22) (r/-): Watchdog timer implemented when 1 (via IO_WDT_USE generic) */
162
  CPU_MFEATURES_IO_CLIC          = 23, /**< CPU mfeatures CSR (23) (r/-): Core-local interrupt controller implemented when 1 (via IO_CLIC_USE generic) */
163 3 zero_gravi
  CPU_MFEATURES_IO_TRNG          = 24, /**< CPU mfeatures CSR (24) (r/-): True random number generator implemented when 1 (via IO_TRNG_USE generic) */
164
  CPU_MFEATURES_IO_DEVNULL       = 25  /**< CPU mfeatures CSR (24) (r/-): Dummy device implemented when 1 (via IO_DEVNULL_USE generic) */
165 2 zero_gravi
};
166
 
167
 
168
/**********************************************************************//**
169
 * Exception IDs.
170
 **************************************************************************/
171
enum NEORV32_EXCEPTION_IDS_enum {
172
  EXCID_I_MISALIGNED =  0, /**< 0: Instruction address misaligned */
173
  EXCID_I_ACCESS     =  1, /**< 1: Instruction (bus) access fault */
174
  EXCID_I_ILLEGAL    =  2, /**< 2: Illegal instruction */
175
  EXCID_BREAKPOINT   =  3, /**< 3: Breakpoint (EBREAK instruction) */
176
  EXCID_L_MISALIGNED =  4, /**< 4: Load address misaligned */
177
  EXCID_L_ACCESS     =  5, /**< 5: Load (bus) access fault */
178
  EXCID_S_MISALIGNED =  6, /**< 6: Store address misaligned */
179
  EXCID_S_ACCESS     =  7, /**< 7: Store (bus) access fault */
180
  EXCID_MENV_CALL    = 11, /**< 11: Environment call from machine mode (ECALL instruction) */
181
  EXCID_MSI          = 19, /**< 16 + 3: Machine software interrupt */
182
  EXCID_MTI          = 23, /**< 16 + 7: Machine timer interrupt (via MTIME) */
183
  EXCID_MEI          = 27  /**< 16 + 11: Machine external interrupt (via CLIC) */
184
};
185
 
186
 
187
/**********************************************************************//**
188
 * Processor clock prescalers
189
 **************************************************************************/
190
enum NEORV32_CLOCK_PRSC_enum {
191
  CLK_PRSC_2    =  0, /**< CPU_CLK / 2 */
192
  CLK_PRSC_4    =  1, /**< CPU_CLK / 4 */
193
  CLK_PRSC_8    =  2, /**< CPU_CLK / 8 */
194
  CLK_PRSC_64   =  3, /**< CPU_CLK / 64 */
195
  CLK_PRSC_128  =  4, /**< CPU_CLK / 128 */
196
  CLK_PRSC_1024 =  5, /**< CPU_CLK / 1024 */
197
  CLK_PRSC_2048 =  6, /**< CPU_CLK / 2048 */
198
  CLK_PRSC_4096 =  7  /**< CPU_CLK / 4096 */
199
};
200
 
201
 
202
/**********************************************************************//**
203
 * @name Helper macros for easy memory-mapped register access
204
 **************************************************************************/
205
/**@{*/
206
/** memory-mapped byte (8-bit) read/write register */
207
#define IO_REG8  (volatile uint8_t*)
208
/** memory-mapped half-word (16-bit) read/write register */
209
#define IO_REG16 (volatile uint16_t*)
210
/** memory-mapped word (32-bit) read/write register */
211
#define IO_REG32 (volatile uint32_t*)
212
/** memory-mapped double-word (64-bit) read/write register */
213
#define IO_REG64 (volatile uint64_t*)
214
/** memory-mapped byte (8-bit) read-only register */
215
#define IO_ROM8  (const volatile uint8_t*) 
216
/** memory-mapped half-word (16-bit) read-only register */
217
#define IO_ROM16 (const volatile uint16_t*)
218
/** memory-mapped word (32-bit) read-only register */
219
#define IO_ROM32 (const volatile uint32_t*)
220
/** memory-mapped double-word (64-bit) read-only register */
221
#define IO_ROM64 (const volatile uint64_t*)
222
/**@}*/
223
 
224
 
225
/**********************************************************************//**
226
 * @name Address space sections
227
 **************************************************************************/
228
/**@{*/
229
/** instruction memory base address (r/w/x) */
230 6 zero_gravi
// -> use value from MEM_ISPACE_BASE CSR
231 2 zero_gravi
/** data memory base address (r/w/x) */
232 6 zero_gravi
// -> use value from MEM_DSPACE_BASE CSR
233 2 zero_gravi
/** bootloader memory base address (r/-/x) */
234 6 zero_gravi
#define BOOTLOADER_BASE_ADDRESS (0xFFFF0000UL)
235 2 zero_gravi
/** peripheral/IO devices memory base address (r/w/x) */
236 6 zero_gravi
#define IO_BASE_ADDRESS (0xFFFFFF80UL)
237 2 zero_gravi
/**@}*/
238
 
239
 
240
/**********************************************************************//**
241
 * @name IO Device: General Purpose Input/Output Port Unit (GPIO)
242
 **************************************************************************/
243
/**@{*/
244
/** GPIO parallel input port (r/-) */
245 6 zero_gravi
#define GPIO_INPUT  (*(IO_ROM32 0xFFFFFF80UL))
246 2 zero_gravi
/** GPIO parallel output port (r/w) */
247 6 zero_gravi
#define GPIO_OUTPUT (*(IO_REG32 0xFFFFFF84UL))
248 2 zero_gravi
/**@}*/
249
 
250
 
251
/**********************************************************************//**
252
 * @name IO Device: Core Local Interrupts Controller (CLIC)
253
 **************************************************************************/
254
/**@{*/
255
/** CLIC control register (r/w) */
256 6 zero_gravi
#define CLIC_CT (*(IO_REG32 0xFFFFFF88UL))
257 2 zero_gravi
 
258
/** CLIC control register bits */
259
enum NEORV32_CLIC_CT_enum {
260
  CLIC_CT_SRC0        =  0, /**< CLIC control register(0) (r/-): IRQ source bit 0 */
261
  CLIC_CT_SRC1        =  1, /**< CLIC control register(1) (r/-): IRQ source bit 1 */
262
  CLIC_CT_SRC2        =  2, /**< CLIC control register(2) (r/-): IRQ source bit 2 */
263
  CLIC_CT_ACK         =  3, /**< CLIC control register(3) (-/w): Acknowledge current IRQ when set, auto-clears when set */
264
  CLIC_CT_EN          =  4, /**< CLIC control register(4) (r/w): Unit enable */
265
 
266
  CLIC_CT_IRQ0_EN     =  8, /**< CLIC control register(8)  (r/w): Enable IRQ channel 0 */
267
  CLIC_CT_IRQ1_EN     =  9, /**< CLIC control register(9)  (r/w): Enable IRQ channel 1 */
268
  CLIC_CT_IRQ2_EN     = 10, /**< CLIC control register(10) (r/w): Enable IRQ channel 2 */
269
  CLIC_CT_IRQ3_EN     = 11, /**< CLIC control register(11) (r/w): Enable IRQ channel 3 */
270
  CLIC_CT_IRQ4_EN     = 12, /**< CLIC control register(12) (r/w): Enable IRQ channel 4 */
271
  CLIC_CT_IRQ5_EN     = 13, /**< CLIC control register(13) (r/w): Enable IRQ channel 5 */
272
  CLIC_CT_IRQ6_EN     = 14, /**< CLIC control register(14) (r/w): Enable IRQ channel 6 */
273
  CLIC_CT_IRQ7_EN     = 15, /**< CLIC control register(15) (r/w): Enable IRQ channel 7 */
274
 
275
  CLIC_CT_SW_IRQ_SRC0 = 16, /**< CLIC control register(16) (-/w): SW IRQ trigger, IRQ select bit 0, auto-clears when set */
276
  CLIC_CT_SW_IRQ_SRC1 = 17, /**< CLIC control register(17) (-/w): SW IRQ trigger, IRQ select bit 1, auto-clears when set */
277
  CLIC_CT_SW_IRQ_SRC2 = 18, /**< CLIC control register(18) (-/w): SW IRQ trigger, IRQ select bit 2, auto-clears when set */
278
  CLIC_CT_SW_IRQ_EN   = 19  /**< CLIC control register(19) (-/w): SW IRQ trigger enable, auto-clears when set */
279
};
280
/**@}*/
281
 
282
 
283
/**********************************************************************//**
284
 * Core-local interrupt controller IRQ channel
285
 **************************************************************************/
286
enum NEORV32_CLIC_CHANNELS_enum {
287
  CLIC_CH_WDT   = 0, /**< CLIC channel 0: Watchdog timer overflow interrupt */
288
  CLIC_CH_RES   = 1, /**< CLIC channel 1: reserved */
289
  CLIC_CH_GPIO  = 2, /**< CLIC channel 2: GPIO pin-change interrupt */
290
  CLIC_CH_UART  = 3, /**< CLIC channel 3: UART RX available or TX done interrupt */
291
  CLIC_CH_SPI   = 4, /**< CLIC channel 4: SPI transmission done interrupt */
292
  CLIC_CH_TWI   = 5, /**< CLIC channel 5: TWI transmission done interrupt */
293
  CLIC_CH_EXT0  = 6, /**< CLIC channel 6: Processor-external interrupt request 0 */
294
  CLIC_CH_EXT1  = 7  /**< CLIC channel 7: Processor-external interrupt request 1 */
295
};
296
 
297
 
298
/**********************************************************************//**
299
 * @name IO Device: Watchdog Timer (WDT)
300
 **************************************************************************/
301
/**@{*/
302
/** Watchdog control register (r/w) */
303 6 zero_gravi
#define WDT_CT (*(IO_REG32 0xFFFFFF8CUL))
304 2 zero_gravi
 
305
/** WTD control register bits */
306
enum NEORV32_WDT_CT_enum {
307
  WDT_CT_CLK_SEL0     =  0, /**< WDT control register(0) (r/w): Clock prescaler select bit 0 */
308
  WDT_CT_CLK_SEL1     =  1, /**< WDT control register(1) (r/w): Clock prescaler select bit 1 */
309
  WDT_CT_CLK_SEL2     =  2, /**< WDT control register(2) (r/w): Clock prescaler select bit 2 */
310
  WDT_CT_EN           =  3, /**< WDT control register(3) (r/w): Watchdog enable */
311
  WDT_CT_MODE         =  4, /**< WDT control register(4) (r/w): Watchdog mode; when 0: timeout causes interrupt; when 1: timeout causes processor reset */
312
  WDT_CT_CAUSE        =  5, /**< WDT control register(5) (r/-): Last action (reset/IRQ) cause (0: external reset, 1: watchdog timeout) */
313
  WDT_CT_PWFAIL       =  6, /**< WDT control register(6) (r/-): Last Watchdog action (reset/IRQ) caused by wrong password when 1 */
314
 
315
  WDT_CT_PASSWORD_LSB =  8, /**< WDT control register(8)  (-/w): First bit / position begin for watchdog access password */
316
  WDT_CT_PASSWORD_MSB = 15  /**< WDT control register(15) (-/w): Last bit / position end for watchdog access password */
317
};
318
 
319
/** Watchdog access passwort, must be set in WDT_CT bits 15:8 for every control register access */
320
#define WDT_PASSWORD 0x47
321
/**@}*/
322
 
323
 
324
/**********************************************************************//**
325
 * @name IO Device: Machine System Timer (MTIME)
326
 **************************************************************************/
327
/**@{*/
328 4 zero_gravi
/** MTIME (time register) low word (r/-) */
329 6 zero_gravi
#define MTIME_LO     (*(IO_ROM32 0xFFFFFF90UL))
330 4 zero_gravi
/** MTIME (time register) high word (r/-) */
331 6 zero_gravi
#define MTIME_HI     (*(IO_ROM32 0xFFFFFF94UL))
332 2 zero_gravi
/** MTIMECMP (time compare register) low word (r/w) */
333 6 zero_gravi
#define MTIMECMP_LO  (*(IO_REG32 0xFFFFFF98UL))
334 2 zero_gravi
/** MTIMECMP (time register) high word (r/w) */
335 6 zero_gravi
#define MTIMECMP_HI  (*(IO_REG32 0xFFFFFF9CUL))
336 2 zero_gravi
 
337 4 zero_gravi
/** MTIME (time register) 64-bit access (r/-) */
338
#define MTIME        (*(IO_ROM64 (&MTIME_LO)))
339 2 zero_gravi
/** MTIMECMP (time compare register) low word (r/w) */
340
#define MTIMECMP     (*(IO_REG64 (&MTIMECMP_LO)))
341
/**@}*/
342
 
343
 
344
/**********************************************************************//**
345
 * @name IO Device: Universal Asynchronous Receiver and Transmitter (UART)
346
 **************************************************************************/
347
/**@{*/
348
/** UART control register (r/w) */
349 6 zero_gravi
#define UART_CT  (*(IO_REG32 0xFFFFFFA0UL))
350 2 zero_gravi
/** UART receive/transmit data register (r/w) */
351 6 zero_gravi
#define UART_DATA (*(IO_REG32 0xFFFFFFA4UL))
352 2 zero_gravi
 
353
/** UART control register bits */
354
enum NEORV32_UART_CT_enum {
355
  UART_CT_BAUD00  =  0, /**< UART control register(0)  (r/w): BAUD rate config value lsb (12-bi, bit 0) */
356
  UART_CT_BAUD01  =  1, /**< UART control register(1)  (r/w): BAUD rate config value (12-bi, bit 1) */
357
  UART_CT_BAUD02  =  2, /**< UART control register(2)  (r/w): BAUD rate config value (12-bi, bit 2) */
358
  UART_CT_BAUD03  =  3, /**< UART control register(3)  (r/w): BAUD rate config value (12-bi, bit 3) */
359
  UART_CT_BAUD04  =  4, /**< UART control register(4)  (r/w): BAUD rate config value (12-bi, bit 4) */
360
  UART_CT_BAUD05  =  5, /**< UART control register(5)  (r/w): BAUD rate config value (12-bi, bit 4) */
361
  UART_CT_BAUD06  =  6, /**< UART control register(6)  (r/w): BAUD rate config value (12-bi, bit 5) */
362
  UART_CT_BAUD07  =  7, /**< UART control register(7)  (r/w): BAUD rate config value (12-bi, bit 6) */
363
  UART_CT_BAUD08  =  8, /**< UART control register(8)  (r/w): BAUD rate config value (12-bi, bit 7) */
364
  UART_CT_BAUD09  =  9, /**< UART control register(9)  (r/w): BAUD rate config value (12-bi, bit 8) */
365
  UART_CT_BAUD10  = 10, /**< UART control register(10) (r/w): BAUD rate config value (12-bi, bit 9) */
366
  UART_CT_BAUD11  = 11, /**< UART control register(11) (r/w): BAUD rate config value msb (12-bi, bit 0)*/
367
 
368
  UART_CT_PRSC0   = 24, /**< UART control register(24) (r/w): BAUD rate clock prescaler select bit 0 */
369
  UART_CT_PRSC1   = 25, /**< UART control register(25) (r/w): BAUD rate clock prescaler select bit 1 */
370
  UART_CT_PRSC2   = 26, /**< UART control register(26) (r/w): BAUD rate clock prescaler select bit 2 */
371
  UART_CT_RXOR    = 27, /**< UART control register(27) (r/-): RX data overrun when set */
372
  UART_CT_EN      = 28, /**< UART control register(28) (r/w): UART global enable */
373
  UART_CT_RX_IRQ  = 29, /**< UART control register(29) (r/w): Activate interrupt on RX done */
374
  UART_CT_TX_IRQ  = 30, /**< UART control register(30) (r/w): Activate interrupt on TX done */
375
  UART_CT_TX_BUSY = 31  /**< UART control register(31) (r/-): Transmitter is busy when set */
376
};
377
 
378
/** UART receive/transmit data register bits */
379
enum NEORV32_UART_DATA_enum {
380
  UART_DATA_LSB   =  0, /**< UART receive/transmit data register(0)  (r/w): Receive/transmit data LSB (bit 0) */
381
  UART_DATA_MSB   =  7, /**< UART receive/transmit data register(7)  (r/w): Receive/transmit data MSB (bit 7) */
382
  UART_DATA_AVAIL = 31  /**< UART receive/transmit data register(31) (r/-): RX data available when set */
383
};
384
/**@}*/
385
 
386
 
387
/**********************************************************************//**
388
 * @name IO Device: Serial Peripheral Interface Master (SPI)
389
 **************************************************************************/
390
/**@{*/
391
/** SPI control register (r/w) */
392 6 zero_gravi
#define SPI_CT  (*(IO_REG32 0xFFFFFFA8UL))
393 2 zero_gravi
/** SPI receive/transmit data register (r/w) */
394 6 zero_gravi
#define SPI_DATA (*(IO_REG32 0xFFFFFFACUL))
395 2 zero_gravi
 
396
/** SPI control register bits */
397
enum NEORV32_SPI_CT_enum {
398
  SPI_CT_CS0    =  0, /**< UART control register(0) (r/w): Direct chip select line 0 (output is low when set) */
399
  SPI_CT_CS1    =  1, /**< UART control register(1) (r/w): Direct chip select line 1 (output is low when set) */
400
  SPI_CT_CS2    =  2, /**< UART control register(2) (r/w): Direct chip select line 2 (output is low when set) */
401
  SPI_CT_CS3    =  3, /**< UART control register(3) (r/w): Direct chip select line 3 (output is low when set) */
402
  SPI_CT_CS4    =  4, /**< UART control register(4) (r/w): Direct chip select line 4 (output is low when set) */
403
  SPI_CT_CS5    =  5, /**< UART control register(5) (r/w): Direct chip select line 5 (output is low when set) */
404
  SPI_CT_CS6    =  6, /**< UART control register(6) (r/w): Direct chip select line 6 (output is low when set) */
405
  SPI_CT_CS7    =  7, /**< UART control register(7) (r/w): Direct chip select line 7 (output is low when set) */
406
 
407
  SPI_CT_EN     =  8, /**< UART control register(8) (r/w): SPI unit enable */
408
  SPI_CT_CPHA   =  9, /**< UART control register(9) (r/w): Clock polarity (idle polarity) */
409
  SPI_CT_PRSC0  = 10, /**< UART control register(10) (r/w): Clock prescaler select bit 0 */
410
  SPI_CT_PRSC1  = 11, /**< UART control register(11) (r/w): Clock prescaler select bit 1 */
411
  SPI_CT_PRSC2  = 12, /**< UART control register(12) (r/w): Clock prescaler select bit 2 */
412
  SPI_CT_DIR    = 13, /**< UART control register(13) (r/w): Shift direction (0: MSB first, 1: LSB first) */
413
  SPI_CT_SIZE0  = 14, /**< UART control register(14) (r/w): Transfer data size lsb (00: 8-bit, 01: 16-bit, 10: 24-bit, 11: 32-bit) */
414
  SPI_CT_SIZE1  = 15, /**< UART control register(15) (r/w): Transfer data size lsb (00: 8-bit, 01: 16-bit, 10: 24-bit, 11: 32-bit) */
415
 
416
  SPI_CT_IRQ_EN = 16, /**< UART control register(16) (r/w): Transfer done interrupt enable */
417
 
418
  SPI_CT_BUSY   = 31  /**< UART control register(31) (r/-): SPI busy flag */
419
};
420
/**@}*/
421
 
422
 
423
/**********************************************************************//**
424
 * @name IO Device: Two-Wire Interface Master (TWI)
425
 **************************************************************************/
426
/**@{*/
427
/** TWI control register (r/w) */
428 6 zero_gravi
#define TWI_CT   (*(IO_REG32 0xFFFFFFB0UL))
429 2 zero_gravi
/** TWI receive/transmit data register (r/w) */
430 6 zero_gravi
#define TWI_DATA (*(IO_REG32 0xFFFFFFB4UL))
431 2 zero_gravi
 
432
/** TWI control register bits */
433
enum NEORV32_TWI_CT_enum {
434
  TWI_CT_EN     =  0, /**< TWI control register(0) (r/w): TWI enable */
435
  TWI_CT_START  =  1, /**< TWI control register(1) (-/w): Generate START condition, auto-clears */
436
  TWI_CT_STOP   =  2, /**< TWI control register(2) (-/w): Generate STOP condition, auto-clears */
437
  TWI_CT_IRQ_EN =  3, /**< TWI control register(3) (r/w): Enable transmission done interrupt */
438
  TWI_CT_PRSC0  =  4, /**< TWI control register(4) (r/w): Clock prescaler select bit 0 */
439
  TWI_CT_PRSC1  =  5, /**< TWI control register(5) (r/w): Clock prescaler select bit 1 */
440
  TWI_CT_PRSC2  =  6, /**< TWI control register(6) (r/w): Clock prescaler select bit 2 */
441
  TWI_CT_MACK   =  7, /**< TWI control register(7) (r/w): Generate master ACK for each transmission */
442
 
443
  TWI_CT_ACK    = 30, /**< TWI control register(30) (r/-): ACK received when set */
444
  TWI_CT_BUSY   = 31  /**< TWI control register(31) (r/-): Transfer in progress, busy flag */
445
};
446
 
447
/** WTD receive/transmit data register bits */
448
enum NEORV32_TWI_DATA_enum {
449
  TWI_DATA_LSB = 0, /**< TWI data register(0) (r/w): Receive/transmit data (8-bit) LSB */
450
  TWI_DATA_MSB = 7  /**< TWI data register(7) (r/w): Receive/transmit data (8-bit) MSB */
451
};
452
/**@}*/
453
 
454
 
455
/**********************************************************************//**
456
 * @name IO Device: Pulse Width Modulation Controller (PWM)
457
 **************************************************************************/
458
/**@{*/
459
/** PWM control register (r/w) */
460 6 zero_gravi
#define PWM_CT   (*(IO_REG32 0xFFFFFFB8UL)) // r/w: control register
461 2 zero_gravi
/** PWM duty cycle register (4-channels) (r/w) */
462 6 zero_gravi
#define PWM_DUTY (*(IO_REG32 0xFFFFFFBCUL)) // r/w: duty cycle channel 1 and 0
463 2 zero_gravi
 
464
/** PWM control register bits */
465
enum NEORV32_PWM_CT_enum {
466
  PWM_CT_EN    =  0, /**< PWM control register(0) (r/w): PWM controller enable */
467
  PWM_CT_PRSC0 =  1, /**< PWM control register(1) (r/w): Clock prescaler select bit 0 */
468
  PWM_CT_PRSC1 =  2, /**< PWM control register(2) (r/w): Clock prescaler select bit 1 */
469
  PWM_CT_PRSC2 =  3  /**< PWM control register(3) (r/w): Clock prescaler select bit 2 */
470
};
471
 
472
/**PWM duty cycle register bits */
473
enum NEORV32_PWM_DUTY_enum {
474
  PWM_DUTY_CH0_LSB =  0, /**< PWM duty cycle register(0)  (r/w): Channel 0 duty cycle (8-bit) LSB */
475
  PWM_DUTY_CH0_MSB =  7, /**< PWM duty cycle register(7)  (r/w): Channel 0 duty cycle (8-bit) MSB */
476
  PWM_DUTY_CH1_LSB =  8, /**< PWM duty cycle register(8)  (r/w): Channel 1 duty cycle (8-bit) LSB */
477
  PWM_DUTY_CH1_MSB = 15, /**< PWM duty cycle register(15) (r/w): Channel 1 duty cycle (8-bit) MSB */
478
  PWM_DUTY_CH2_LSB = 16, /**< PWM duty cycle register(16) (r/w): Channel 2 duty cycle (8-bit) LSB */
479
  PWM_DUTY_CH2_MSB = 23, /**< PWM duty cycle register(23) (r/w): Channel 2 duty cycle (8-bit) MSB */
480
  PWM_DUTY_CH3_LSB = 24, /**< PWM duty cycle register(24) (r/w): Channel 3 duty cycle (8-bit) LSB */
481
  PWM_DUTY_CH3_MSB = 31  /**< PWM duty cycle register(31) (r/w): Channel 3 duty cycle (8-bit) MSB */
482
};
483
/**@}*/
484
 
485
 
486
/**********************************************************************//**
487
 * @name IO Device: True Random Number Generator (TRNG)
488
 **************************************************************************/
489
/**@{*/
490
/** TRNG control register (r/w) */
491 6 zero_gravi
#define TRNG_CT   (*(IO_REG32 0xFFFFFFC0UL))
492 2 zero_gravi
/** TRNG data register (r/-) */
493 6 zero_gravi
#define TRNG_DATA (*(IO_ROM32 0xFFFFFFC4UL))
494 2 zero_gravi
 
495
/** TRNG control register bits */
496
enum NEORV32_TRNG_CT_enum {
497
  TRNG_CT_TAP_LSB =  0, /**< TRNG control register(0)  (r/w): TAP mask (16-bit) LSB */
498
  TRNG_CT_TAP_MSB = 15, /**< TRNG control register(15) (r/w): TAP mask (16-bit) MSB */
499
  TRNG_CT_EN      = 31  /**< TRNG control register(31) (r/w): TRNG enable */
500
};
501
 
502
/** WTD data register bits */
503
enum NEORV32_TRNG_DUTY_enum {
504
  TRNG_DATA_LSB   =  0, /**< TRNG data register(0)  (r/-): Random data (16-bit) LSB */
505
  TRNG_DATA_MSB   = 15, /**< TRNG data register(15) (r/-): Random data (16-bit) MSB */
506
  TRNG_DATA_VALID = 31  /**< TRNG data register(31) (r/-): Random data output valid */
507
};
508
/**@}*/
509
 
510
 
511 3 zero_gravi
/**********************************************************************//**
512
 * @name IO Device: Dummy Device (DEVNULL)
513
 **************************************************************************/
514
/**@{*/
515 6 zero_gravi
/** DEVNULL data register (r/w) */
516
#define DEVNULL_DATA (*(IO_REG32 0xFFFFFFFCUL))
517 3 zero_gravi
/**@}*/
518
 
519
 
520 2 zero_gravi
// ----------------------------------------------------------------------------
521
// Include all IO driver headers
522
// ----------------------------------------------------------------------------
523
// cpu core
524
#include "neorv32_cpu.h"
525
 
526
// neorv32 runtime environment
527
#include "neorv32_rte.h"
528
 
529
// io/peripheral devices
530
#include "neorv32_clic.h"
531
#include "neorv32_gpio.h"
532
#include "neorv32_mtime.h"
533
#include "neorv32_pwm.h"
534
#include "neorv32_spi.h"
535
#include "neorv32_trng.h"
536
#include "neorv32_twi.h"
537
#include "neorv32_uart.h"
538
#include "neorv32_wdt.h"
539
 
540
#endif // neorv32_h

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.