The header files for TLM 2.0 and the simple target convenience socket are included.
#include "tlm.h" #include "tlm_utils/simple_target_socket.h"
Convenience constants for the address mask, named register offsets and bit fields are then defined. The address mask is needed, since in this simple SoC model there is no arbiter/decoder to strip out the higher order bits from the address before the transaction is sent to the UART.
#define UART_ADDR_MASK 7 // Mask for addresses (3 bit bus)
Named constants are defined giving the address offset of each register of the UART
#define UART_BUF 0 // R/W: Rx/Tx buffer, DLAB=0 #define UART_IER 1 // R/W: Interrupt Enable Register, DLAB=0 #define UART_IIR 2 // R: Interrupt ID Register #define UART_LCR 3 // R/W: Line Control Register #define UART_MCR 4 // W: Modem Control Register #define UART_LSR 5 // R: Line Status Register #define UART_MSR 6 // R: Modem Status Register #define UART_SCR 7 // R/W: Scratch Register
Bit masks are declared for each of the bits and bit fields of interest in the UART. For example the interrupt identification register needs a mask for the pending bit of a mask for the two bits representing the highest priority interrupt and a mask for each possible interrupt.
#define UART_IIR_IPEND 0x01 // Interrupt pending (active low) #define UART_IIR_MASK 0x06 // the IIR status bits #define UART_IIR_RLS 0x06 // Receiver line status #define UART_IIR_RDA 0x04 // Receiver data available #define UART_IIR_THRE 0x02 // Transmitter holding reg empty #define UART_IIR_MOD 0x00 // Modem status