blob: e3d2262eb93217c63cc786630b6bf9d5bf6a8a9c [file] [log] [blame] [view]
lowRISC Contributors802543a2019-08-31 12:12:56 +01001{{% lowrisc-doc-hdr Register Tool }}
2
3The register tool is used to construct register documentation, register RTL and header files.
4It is either used stand-alone or by being invoked as part of markdown processing.
5
6{{% toc 3 }}
7
8## Running standalone regtool.py
9
10The standalone `regtool.py` is a python3 tool to read configuration and register descriptions in Hjson and generate various output formats.
11Currently it can output html documentation, standard json, compact standard json (whitespace removed), Hjson, verilog RTL and various forms of C header files.
12
13The standard `--help` and `--version` command line flags are supported to print the usage and version information.
14Because the version includes information on libraries (which may be different between systems) reporting the version output is sometimes useful when issues are reported.
15
16### Setup and Examples
17
18Setup and examples of the tool are given in the README.md file in the `util/reggen` directory.
19
20## Configuration and Register Definition File Format
21
22The tool input is an Hjson file containing the Comportable description of the IP block and its registers.
23
24A description of Hjson (a varient of json) and the recommended style is in the [Hjson Usage and Style Guide](hjson_usage_style.md).
25
26The tables below describe valid keys for each context.
27It is an error if *required* keys are missing from the input json.
28*Optional* keys may be provided in the input file as needed, as noted in the tables the tool may insert them (with default or computed values) during validation so the output generators do not have to special case them.
29Keys marked as "inserted by tool" should not be in the input json (they will be silently overwritten if they are there), they are derived by the tool during validation of the input and available to the output generators.
30
31{{% include !../../util/regtool.py --doc }}
32
33The tool will normally generate the register address offset by starting from 0 and allocating the registers in the order they are in the input file.
34Between each register the offset is incremented by the number of bytes in the `regwidth` (4 bytes for the default 32-bit `regwidth`), so the registers end up packed into the smallest space.
35
36Space may be held for future registers (or to match some other layout) by reserving register slots.
37A group containing just the reserved key can be inserted in the list of registers to reserve space.
38For example to reserve space for four registers between REGA and REGB (thus make REGB offset be REGA offset plus 5 times the size in bytes of a register):
39
40```hjson
41 { name: "REGA",
42 ...register definition...
43 }
44 { reserved: "4" }
45 { name: "REGB",
46 ...register definition...
47 }
48```
49
50In other cases, such as separating functional groups of registers, the absolute offset can be specified.
51The next register will have the offset specified.
52It is an error if the requested offset is less than the current offset.
53For example to place ITCR at offset 0x100:
54
55```hjson
56 { skipto: "0x100" }
57 { name: "ITCR",
58 ...register definition...
59 }
60
61```
62
63Historically, peripherals have put multiple registers at the same offset either different based on read or write, or with some other bit controlling the overlay.
64This is not permitted for Coportable peripherals but may be required for compatibility.
65These registers are grouped in a list.
66For example to have REGA and REGB (and more) at the same offest:
67
68```hjson
69 { sameaddr: [
70 { name: "REGA",
71 ...register definition...
72 }
73 { name: "REGB",
74 ...register definition...
75 }
76 ...register definitions...
77 ]
78 }
79```
80
81The tool can reserve an area of the memory space for something that is not a simple register, for example access to a buffer memory.
82This is done with a `window` declaration.
83The window size is specified as `items:` where each item is a `regwidth` wide word.
84The size in bytes is thus `(items * (regwidth/8))` bytes.
85If byte writes are supported the `byte-write: "True"` flag can be given.
86The tool will normally increment the offset to align the region based on its size.
87
88```hjson
89 {window: {
90 name: "win1"
91 items: "64"
92 swaccess: "rw"
93 desc: '''
94 A simple 256 byte window that will be aligned.
95 '''
96 }
97 },
98
99```
100
101The tool will give a warning if the size is not a power of 2.
102The tool will also give a warning if the window has software access other than read-only, write-only or read-write.
103Both of these warnings are supressed if the description acknowledges there is something special about this window by setting `unusual: "True"` in the window declaration.
104
105The tool will normally increment the offset to align the region based on its size.
106The start address is aligned such that the base item in the window is at an address with all zeros in the low bits.
107For instance, if the current offset is 0x104, and the window size in 32-bit words is between 0x11 and 0x20 (inclusive) (i.e. 65-128 bytes), the window base will be set to 0x180.
108The alignment may be prevented by seting `noalign: "True"` in which case the hardware design must take care of the addressing offset.
109The next register will immedately follow the window, so will be at the window base address plus the window size in bytes.
110
111Putting these together an unaligned 60 byte window (15 32-bit words) could follow a single aligned register:
112
113
114```hjson
115 {skipto: "0x200"}
116 {name: "aligned_reg" ... }
117 {window: {
118 name: "unaligned_win"
119 items: "15"
120 noalign: "True"
121 unusual: "True"
122 byte-write: "True"
123 swaccess: "rw"
124 desc: '''
125 A 60 byte window that slots in after the register.
126 The addresses used in the window will be 0x204-0x23C.
127 The implementation must take account of the first
128 item being at address 0x04.
129 '''
130 }
131 },
132
133```
134
135Sometimes the window may need to map a structure that is not a full word wide (for example providing debug access to a the memory in a 12-bit wide fifo).
136In this case it may be convenient to have only the low bits of each word valid and use the word address directly as an index (rather than presenting a "packed" structure with the sub-word items packed into as few words as possible).
137The window declaration can be annotated to document this.
138For example debug access to a 64 entry 12-bit wide fifo could use a window:
139
140```hjson
141 {window: {
142 name: "fifodebug"
143 items: "64"
144 validbits: "12"
145 swaccess: "ro"
146 desc: '''
147 The 64 entry fifo is mapped into the low 12-bits
148 of each regwidth bit wide word.
149 '''
150 }
151 },
152
153```
154
155The tool can generate registers that follow a base pattern, for example when there are configuration fields for multiple instances.
156The base pattern defines the bits (which need not be contiguous) used for the first instance and the tool uses this to pack the required number of instances into one or more registers.
157
158For example a fancy gpio interrupt configiration may have 4 bits per GPIO to allow generation on rising and falling edge and a two bit enum to determing the interrupt severity.
159In this case the multireg can be used to build the multiple registers needed.
160The description below shows the fields given for GPIO0 and requests generation of 32 instances.
161If the registers are 32 bits wide then the tool will pack the four bit instances into four registers `INT_CTRL0`, `INT_CTRL1`, `INT_CTRL2` and `INT_CTRL3`.
162
163```hjson
164 { multireg: {
165 name: "INT_CTRL",
166 desc: "GPIO Interrupt control",
167 count: "32",
168 cname: "GPIO",
169 swaccess: "rw",
170 fields: [
171 { bits: "0", name: "POS", resval: "0",
172 desc: "Set to interrupt on rising edge"
173 }
174 { bits: "1", name: "NEG", resval: "0",
175 desc: "Set to interrupt on falling edge"
176 }
177 { bits: "3:2", name: "TYPE", resval: "0",
178 desc: "Type of interrupt to raise"
179 enum: [
180 {value: "0", name: "none", desc: "no interrupt, only log" },
181 {value: "1", name: "low", desc: "low priotiry interrupt" },
182 {value: "2", name: "high", desc: "high priotiry interrupt" },
183 {value: "3", name: "nmi", desc: "non maskable interrupt" }
184 ]
185 }
186 ]
187 }
188 },
189
190```
191
192Note that the definition bits for the base instance need not be contiguous.
193In this case the tool will match the patten for the other instances.
194For example the data bits and mask bits could be in the lower and upper parts of a register:
195
196```hjson
197 { multireg: {
198 name: "WDATA",
199 desc: "Write with mask to GPIO out register",
200 count: "32",
201 cname: "GPIO",
202 swaccess: "rw",
203 fields: [
204 { bits: "0", name: "D", resval: "0",
205 desc: "Data to write if mask bit is 1"
206 }
207 { bits: "16", name: "M", resval: "0",
208 desc: "Mask, set to allow data write"
209 }
210 ]
211 }
212 }
213```
214
215In this case instance 1 will use bits 1 and 17, instance 2 will use 2 and 18 and so on.
216Instance 16 does not fit, so will start a new register.
217
218## Register Tool Hardware Generation
219
220This section details the register generation for hardware instantiation.
221The input to the tool for this generation is the same `.hjson` file described above.
222The output is two verilog files that can be instantiated by a peripheral that follows the [Comportability Guidelines](comportability_specification.md).
223
224The register generation tool will generate the RTL if it is invoked with the `-r` flag.
225The `-t <directory>` flag is used to specify the output directory where the two files will be written.
226As an example the tool can be invoked to generate the uart registers with:
227
228```console
229$ cd hw/ip/uart/doc
230$ ../../../../util/regtool.py -r -t ../rtl uart.hjson
231```
232
233The first created file (`name_reg_pkg.sv`, from `name.hjson`) contains a SystemVerilog package definition that includes type definitions for two packed structures that have details of the registers and fields (all names are converted to lowercase).
234The `name_reg2hw_t` structure contains the signals that are driven from the register module to the rest of the hardware (this contains any required `.q, .qe`, and `.re` signals described below).
235The `name_hw2reg_t` structure contains the signals that are driven from the rest of the hardware to the register module (this contains any required `.d` and `.de` signals described below).
236The file also contains parameters giving the byte address offsets of the registers (these are prefixed with the peripheral `name` and converted to uppercase).
237
238The second file (`name_reg_top.sv`) is a SystemVerilog file that contains a module (`name_reg_top`) that instantiates the registers.
239This module connects to the TL-UL system bus interface and provides the register connections to the rest of the hardware.
240If the register definition contains memory windows then there will be subordinate TL-UL bus connections for each window.
241The module signature is:
242
243```systemverilog
244module name_reg_top (
245 input clk_i,
246 input rst_ni,
247
248 // Below Regster interface can be changed
249 input tlul_pkg::tl_h2d_t tl_i,
250 output tlul_pkg::tl_d2h_t tl_o,
251
252 // This section is only provided if the definition includes
253 // 1 or more "window" definitions and contains an array of
254 // secondary TL-UL bus connectors for each window
255 // Output port for window
256 output tlul_pkg::tl_h2d_t tl_win_o [1],
257 input tlul_pkg::tl_d2h_t tl_win_i [1],
258
259 // To HW
260 output uart_reg_pkg::uart_reg2hw_t reg2hw, // Write
261 input uart_reg_pkg::uart_hw2reg_t hw2reg // Read
262);
263```
264
265The sections below describe the hardware functionality of each register type both in terms of the RTL created, and the wires in the structures that will come along with the register.
266
267## Overall block diagram
268
269The diagram below gives an overview of the register module, `name_reg_top`.
270
271![reg_top](reg_top.svg)
272
273In this diagram, the TL-UL bus is shown on the left.
274Logic then breaks down individual write requests and read requests based upon the assigned address of the bus requests.
275Writes that match an address create an internal write enable to an individual register (or collection of registers in the case of a field), and return a successful write response.
276Reads that match an address return the associated data content for that register.
277See the section below on requests that don't match any register address.
278
279In the middle are the collections of registers, which are a function of the `hjson` input, and a definition of the functionality of each register (read-only, read-write, etc), detailed below.
280These are instantiations of the primitives `prim_subreg` and `prim_subreg_ext` found in the lowRISC primitive library (lowrisc:prim:all).
281These take as inputs the write requests from the bus as well as the hardware struct inputs associated with that register.
282They create as output the current state of the register and a potential write enable.
283The `prim_subreg` module takes a parameter `SWACCESS` that is used to adjust the implementation to the access type required.
284
285On the right are the typedef structs that gather the `q` and `qe`s into one output bundle, and receive the bundled `d` and `de` inputs.
286
287The addess decode and TL-UL 1:N adapter shown at the bottom are created only if the register definition includes one or more `window:` descriptions.
288Each window is given its own TL-UL connection and the implementation must provide a device interface.
289
290It is notable that in the current definition, each field of a register has its own register instantiation.
291This is required because the definitions allow unique `swaccess` and `hwaccess` values per field, but could be done at the register level otherwise.
292The individual bundled wires are associated with the fields rather than the full register, so the designer of the rest of the peripheral does not need to know the bit range association of the individual fields.
293
294### Error responses
295
296Writes and reads that target addresses that are not represented within the register list typically return an error.
297However, for security modules (Comportability definition forthcoming), this is under the control of a register module input signal `devmode_i`.
298This signal indicates whether the whole SOC device is in development or production mode.
299For security peripherals in production mode, it is desired to **not** send an error response, so write misses silently fail, and read misses silently fail, but return either random data (TBD) or all `1`s for response data (i.e. `0xFFFFFFFF` for a 32b register).
300For non-security peripherals, or when in development mode (`devmode_i == 1`) these writes and reads to undefined addresses will return with TL-UL error response.
301
302Other error responses (always sent, regardless of `devmode_i`) include for the following reasons:
303
304* TL-UL `a_opcode` illegal value
305* TL-UL writes of size smaller than register size
306 * I.e. writes of size 8b to registers > 8b will cause error (explicitly: if it has field bits within `[31:08]`)
307 * I.e. writes of size 16b to registers > 16b will cause error (explicitly: if it has field bits within `[31:16]`)
308* TL-UL writes of size smaller than 32b that are not word-aligned
309 * I.e. writes of size 8b or 16b that are not to an address that is 4B aligned return in error.
310
311Reads of size smaller than full word (32b) return the full register content and do not signal error.
312Reads response data is always in its byte-channel, i.e. a one-byte read to `address 0x3` will return the full word with the correct MSB in bits `[31:24]` on the TL-UL response bus (as well as the not-asked-for bytes 2:0 in `[23:0]`).
313
314Note with the windowing option, a new TL-UL bus (or more) is spawned and managed outside of this register module.
315Any window that makes use of the byte masks will include the `byte-write: "true"` keyword in their definition.
316Error handling by that TL-UL bus is **completely under the control of the logic that manages this bus.**
317It is recommended to follow the above error rules (including `devmode_i` for address misses on security peripherals) based on the declared number of `validbits`: for the window, but there are some cases where this might be relaxed.
318For example, if the termination of the TL-UL bus is a memory that handles byte and halfword writes via masking, errors do not need be returned for unaligned sub-word writes.
319
320## Register definitions per type
321
322The definition of what exactly is in each register type is described in this section.
323As shown above, the maximally featured register has inputs and outputs to/from both the bus interface side of the design as well as the hardware interface side.
324Some register types don’t require all of these inputs and outputs.
325For instance, a read-only register does not require write data from the bus interface (this is configured by the `SWACCESS` parameter to the `prim_subreg` module).
326The maximally defined inputs to this register block (termed the `subreg` from here forward) are given in the table below.
327Note that these are instantiated per field, not per register, so the width is the width of the field.
328The direction is the Verilog signal definition of `subreg` for that type.
329
330<table>
331 <tr>
332 <td><strong>name</strong>
333 </td>
334 <td><strong>direction</strong>
335 </td>
336 <td><strong>description</strong>
337 </td>
338 </tr>
339 <tr>
340 <td><code>we</code>
341 </td>
342 <td>input
343 </td>
344 <td>Write enable from the bus interface, scalar
345 </td>
346 </tr>
347 <tr>
348 <td><code>wd[]</code>
349 </td>
350 <td>input
351 </td>
352 <td>Write data from the bus interface, size == field size
353 </td>
354 </tr>
355 <tr>
356 <td><code>qs[]</code>
357 </td>
358 <td>output
359 </td>
360 <td>Output to read response data mux, size == field_size. This is typically the same as <code>q[]</code> except for <code>hwext</code> registers.
361 </td>
362 </tr>
363 <tr>
364 <td><code>de</code>
365 </td>
366 <td>input
367 </td>
368 <td>Hardware data enable from peripheral logic, scalar, should be set when the hardware wishes to update the register field
369 </td>
370 </tr>
371 <tr>
372 <td><code>d[]</code>
373 </td>
374 <td>input
375 </td>
376 <td>Hardware data from peripheral logic, size == field size
377 </td>
378 </tr>
379 <tr>
380 <td><code>qe</code>
381 </td>
382 <td>output
383 </td>
384 <td>Output register enable, scalar, true when bus interface writes to subreg
385 </td>
386 </tr>
387 <tr>
388 <td><code>q[]</code>
389 </td>
390 <td>output
391 </td>
392 <td>Output register content, size == field size. This output typically goes to both the hardware bundle output <code>q</code> as well as the software read response mux output <code>qs[]</code>.
393 </td>
394 </tr>
395 <tr>
396 <td><code>re</code>
397 </td>
398 <td>output
399 </td>
400 <td>Indicates to hwext registers that the bus is reading the register.
401 </td>
402 </tr>
403</table>
404
405
406
407### Type RW
408
409The first register type is the read-write register, invoked with an `hjson` attribute `swaccess` type of `rw`.
410There is a variant of this below, this is the default variant.
411This uses the `prim_subreg` with the connections shown.
412The connectivity to the hardware struct bundles are a function of the `hwaccess` and `hwqe` attributes, and will be discussed here as well.
413
414![subreg_rw](subreg_rw.svg)
415
416
417In this diagram, the maximum connection for subreg_rw is shown.
418Coming in from the left (bus) are the software write enable and write data, which has the highest priority in modifying the register contents.
419These are present for all RW types.
420The “final answer” for the register content is stored in the subreg module, and presented to the peripheral hardware as the output `q` and to bus reads as the output `qs`.
421Optionally, if the `hwaccess` attribute allows writes from the hardware, the hardware can present updated values in the form of data enable (`de`) and update data (`d`).
422If the data enable is true, the register content is updated with the update data.
423If both software and hardware request an update in the same clock cycle (i.e. both `de` and `we` are true), the software updated value is used, as shown in the diagram.
424
425The `hwaccess` attribute value does not change the contents of the subreg, but the connections are potentially modified.
426The attribute `hwaccess` has four potential values, as shown earlier in the document: `hrw, hro, hwo, none`.
427A `hwaccess` value of `hrw` means that the hardware wants the ability to update the register content (i.e. needs connection to `d` and `de`), as well as see the updated output (`q`).
428`hwo` doesn’t care about the output `q`, but wants to update the register value.
429This is the default for registers marked for software read-only access.
430`hro` conversely indicates the hardware doesn’t need to update the content, but just wants to see the value written by software.
431This is the default for fields where the software access is read-write or write-only.
432Finally an attribute value of `none` asks for no interface to the hardware, and might be used for things like scratch registers or DV test registers where only software can modify the value, or informational registers like version numbers that are read-only by the software.
433
434Another attribute in the register description `hwqe`, when true indicates that the hardware wants to see the software write enable exported to the peripheral logic.
435This is just a registered version of the bus side write-enable `we` so that its rising edge aligns with the change in the `q` output.
436There only needs to be one instantiated `qe` flop per register, but it is provided in the reg2hw structure for each field.
437
438### Type RW HWExt
439
440There is an attribute called `hwext` which indicates, when true, that the register value will be maintained **outside** the auto-generated logic.
441It is up to the external logic to implement the correct functionality as indicated by the `swaccess` attribute.
442In other words, **there is no guarantee** that the custom logic will correctly implement `rw`, or whichever attribute is included in the register definition.
443It is expected that this functionality is only needed for custom features outside the scope of the list of supported swaccess features, such as masked writes or access to FIFOs.
444Note that these could be done non-hwext as well, with `swaccess==rw` and `hwaccess=rw`, but could lose atomicity due to the register included within the autogenerated region.
445The block diagram below shows the maximally functional `hwext` `RW` register, with some assumption of the implementation of the register on the outside.
446This is implemented by the `prim_subreg_ext` module which is implemented with `assign` statements just as the wiring shown suggests.
447In this diagram the `q` is the `q` output to the hardware, while the `qs` is the output to the read response mux on the software side.
448The storage register is shown in the custom portion of the logic.
449Finally, note that no `de` input is required from the rest of the peripheral hardware, only the `d` is added to the struct bundle.
450
451![subreg_ext](subreg_ext.svg)
452
453Note the timing of `qe` is one cycle earlier in this model than in the non-hwext model.
454
455
456### Type RO, with hwext and zero-gate options
457
458Read-only type registers can be thought of as identical as `RW` types with no `wd` and `we` input.
459They are implemented as `prim_subreg` with those inputs disabled.
460Similarly `hwext RO` registers simply pass the d input from the outside world to the data mux for software read response.
461
462There is one special case here [not yet implemented] where `swaccess` is `ro` and `hwaccess` is `none` or `hro` and `hwext` is true.
463In this case, a hardwired value is returned for a software read equal to the default value assigned to the register this can be useful for auto-generated register values with no storage register required.
464
465### Type RC
466
467Registers of software access type `rc` are special cases of `RO`, but require an additional signal from the address decode logic.
468This signal `re` indicates that this register is being read, in which case the contents should be set to zero.
469Note this register is not recommended but might be required for backwards compatibility to other IP functionality.
470At the moment `hwext` is not allowed to be true for `RC` since there is no exporting of the `re` signal.
471If this is required, please add a feature request.
472
473### Type WO
474
475Write only registers are variants of `prim_subreg` where there is no output back to the software read response mux, so the `d` and `de` pins are tied off.
476If there is no storage required, only an indication of the act of writing, then `hwext` should be set to true and the outside hardware can handle the write event.
477
478### Type R0W1C, RW1S, RW1C and RW0C
479
480Certain `RW` register types must be implemented with special configuration of `prim_subreg` since the act of writing causes the values to be set in unique ways.
481These types are shown in the block diagrams below.
482Type `R0W1C` not shown is just a special case of `RW1C` where the q output is not sent back to the software read response mux, but the value `0` is sent instead.
483Note the `qe` is removed for readability but is available with the hwqe attribute.
484
485![subreg_rw1c](subreg_rw1c.svg)
486
487![subreg_rw0c](subreg_rw0c.svg)
488
489![subreg_rw1s](subreg_rw1s.svg)
490
491
492#### Simultaneous SW and HW access
493
494As shown in the module descriptions, the subreg needs to handle the case when both hardware and software attempt to write at the same time.
495As is true with the RW type, the software has precedence, but it is more tricky here.
496The goal for these types of registers is to have software clear or set certain bits at the same time hardware is clearing or setting other bits.
497So in theory what software is clearing, hardware is setting, or vice-versa.
498An example would be where hardware is setting interrupt status bits, and software is clearing them, using RW1C.
499The logic for RW1C shows how this is implemented in the module:
500
501```systemverilog
502q <= (de ? d : q) & (we ? ~wd : '1)
503```
504
505In this description if the hardware is writing, its value is sent to the logic that potentially clears that value or the stored value.
506So if the hardware accidentally clears fields that the software hasn’t cleared yet, there is a risk that events will not be seen by software.
507The recommendation is that the hardware feed the `q` value back into `d`, only setting bits with new events.
508Then there will be no “collision” between hardware setting events and software clearing events.
509The HW could have chosen to simply treat `d` and `de` as set-only, but the preference is to leave the `subreg` simple and allow the hardware to do either “the right thing” or whatever it feels is appropriate for its needs.
510(Perhaps it is a feature to clear all events in the hardware.)
511
512The one “conflict” that is common and worth mentioning is `RW1C` on an interrupt vector.
513This is the typical scenario where hardware sets bits (representing an interrupt event), and software clears bits (indicating the event has been handled).
514The assumption is that between the hardware setting and software clearing, **software has cleaned up whatever caused the event in the first place**.
515But if the event is still true (the HW `d` input is still `1`) then the clear should still have effect for one cycle in order to create a new interrupt edge.
516Since `d` is still `1` the `q` will return to `1` after one cycle, since the clean up was not successful.
517
518#### HWExt RW1C etc.
519
520It is legal to create `RW1C`, `RW1S`, etc. with `hwext` true.
521In these cases the auto-generated hardware is simply the same as the hwext `RW` register shown earlier.
522This causes all of the implementation to be done outside of the generated register block.
523There is no way to guarantee that hardware is doing the right thing, but at least the `RW1C` conveys the notion to software the intended effect.
524
525Similarly it is legal to set `hwqe` true for any of these register types if the clearing wants to be monitored by the hardware outside.
526
527## Generating C Header Files
528
529The register tool can be used to generate C header files.
530It is intended that there will be several generators to output different formats of header file.
531
532### Simple hello_world test headers
533
534The register generation tool will generate simple headers if it is invoked with the `-D` flag.
535The `-o <file.h>` flag may be used to specify the output file.
536As an example the tool can be invoked to generate the uart headers with:
537
538```console
539$ cd hw/ip/uart/doc
540$ ../../../../util/regtool.py -D -o ~/src/uart.h uart.hjson
541```
542
543This format assumes that there is a base address `NAME`n`_BASE_ADDR` defined where n is an identifying number to allow for multiple instantiations of peripherals.
544It provides a definition `NAME_REG(n)` that provides the address of the register in instantiation n.
545Single-bit fields have a define with their bit offset.
546Multi-bit fields have a define for the bit offset and an mask and may have defines giving the enumerated names and values.
547For example:
548
549```c
550// UART control register
551#define UART_CTRL(id) (UART ## id ## _BASE_ADDR + 0x0)
552# define UART_CTRL_TX 0
553# define UART_CTRL_RX 1
554# define UART_CTRL_NF 2
555# define UART_CTRL_SLPBK 4
556# define UART_CTRL_LLPBK 5
557# define UART_CTRL_PARITY_EN 6
558# define UART_CTRL_PARITY_ODD 7
559# define UART_CTRL_RXBLVL_MASK 0x3
560# define UART_CTRL_RXBLVL_OFFSET 8
561# define UART_CTRL_RXBLVL_BREAK2 0
562# define UART_CTRL_RXBLVL_BREAK4 1
563# define UART_CTRL_RXBLVL_BREAK8 2
564# define UART_CTRL_RXBLVL_BREAK16 3
565```
566
567### Titan style headers
568
569The register generation tool will generate Titan project style headers if it is invoked with the `-T` flag.
570The `-o <file.h>` flag may be used to specify the output file.
571As an example the tool can be invoked to generate the uart headers with:
572
573```console
574$ cd hw/ip/uart/doc
575$ ../../../../util/regtool.py -T -o ~/src/titan/uart.h uart.hjson
576```
577
578This format assumes that there is a base address `NAME`n`_BASE_ADDR` defined where n is an identifying number to allow for multiple instantiations of peripherals.
579It provides a definition `NAME_REG(n)` that provides the address of the register in instantiation n and also a definition `NAME_REG_OFFSET` that has the byte offset of the register from the base address.
580Fields have a define for the LSB bit offset, the access mask, the size in bits and the default value and may have defines giving the enumerated names and values.
581For example:
582
583
584```c
585// UART control register
586#define UART_CTRL(id) (UART ## id ## _BASE_ADDR + 0x0)
587#define UART_CTRL_OFFSET 0x0
588# define UART_CTRL_TX_LSB 0x0
589# define UART_CTRL_TX_MASK 0x1
590# define UART_CTRL_TX_SIZE 0x1
591# define UART_CTRL_TX_DEFAULT 0x0
592# define UART_CTRL_RX_LSB 0x1
593# define UART_CTRL_RX_MASK 0x1
594# define UART_CTRL_RX_SIZE 0x1
595# define UART_CTRL_RX_DEFAULT 0x0
596# define UART_CTRL_NF_LSB 0x2
597# define UART_CTRL_NF_MASK 0x1
598# define UART_CTRL_NF_SIZE 0x1
599# define UART_CTRL_NF_DEFAULT 0x0
600# define UART_CTRL_SLPBK_LSB 0x4
601# define UART_CTRL_SLPBK_MASK 0x1
602# define UART_CTRL_SLPBK_SIZE 0x1
603# define UART_CTRL_SLPBK_DEFAULT 0x0
604# define UART_CTRL_LLPBK_LSB 0x5
605# define UART_CTRL_LLPBK_MASK 0x1
606# define UART_CTRL_LLPBK_SIZE 0x1
607# define UART_CTRL_LLPBK_DEFAULT 0x0
608# define UART_CTRL_PARITY_EN_LSB 0x6
609# define UART_CTRL_PARITY_EN_MASK 0x1
610# define UART_CTRL_PARITY_EN_SIZE 0x1
611# define UART_CTRL_PARITY_EN_DEFAULT 0x0
612# define UART_CTRL_PARITY_ODD_LSB 0x7
613# define UART_CTRL_PARITY_ODD_MASK 0x1
614# define UART_CTRL_PARITY_ODD_SIZE 0x1
615# define UART_CTRL_PARITY_ODD_DEFAULT 0x0
616# define UART_CTRL_RXBLVL_LSB 0x8
617# define UART_CTRL_RXBLVL_MASK 0x3
618# define UART_CTRL_RXBLVL_SIZE 0x2
619# define UART_CTRL_RXBLVL_DEFAULT 0x0
620# define UART_CTRL_RXBLVL_BREAK2 0x0
621# define UART_CTRL_RXBLVL_BREAK4 0x1
622# define UART_CTRL_RXBLVL_BREAK8 0x2
623# define UART_CTRL_RXBLVL_BREAK16 0x3
624```
625
626## Generating documentation
627
628The register tool can be used standalone to generate html documentation of the registers.
629However, this is normally done as part of the markdown documentation using the special tags to include the register definition file and insert the configuration and register information.