/* fir_regs.h * Register map and driver API for the AXI4-Lite register file in axil_regs.sv. * The offsets here must match the RTL; cocotb_axil_regs.py reads them from * this file, so a mismatch fails the simulation tests. */ #ifndef FIR_REGS_H #define FIR_REGS_H #include #include /* Byte offsets from the block's base address. */ #define FIR_REG_CTRL 0x00u #define FIR_REG_STATUS 0x04u #define FIR_REG_ID 0x08u #define FIR_REG_COEF0 0x10u /* COEF[k] at FIR_REG_COEF0 + 4*k */ #define FIR_N_COEF 8u /* CTRL bits */ #define FIR_CTRL_ENABLE 0x1u /* level: block runs while set */ #define FIR_CTRL_START 0x2u /* write 1: one-cycle start pulse; reads 0 */ /* STATUS bits, driven by the hardware block (convention for this example) */ #define FIR_STATUS_BUSY 0x1u #define FIR_STATUS_DONE 0x2u #define FIR_ID_VALUE 0x46495231u /* "FIR1" */ typedef struct { volatile uint32_t *base; /* base address of the register block */ } fir_dev; /* 32-bit register access. volatile makes the compiler emit every access in * program order, which memory-mapped I/O needs. */ static inline void fir_write32(const fir_dev *dev, uint32_t offset, uint32_t value) { dev->base[offset / 4u] = value; } static inline uint32_t fir_read32(const fir_dev *dev, uint32_t offset) { return dev->base[offset / 4u]; } /* Returns 0 if the ID register matches, -1 otherwise. */ int fir_init(fir_dev *dev, volatile uint32_t *base); /* Writes n coefficients (Q1.15), sign-extended to 32 bits. -1 if n is too large. */ int fir_set_coefs(const fir_dev *dev, const int16_t *coef, size_t n); /* Sets ENABLE and pulses START in one write. */ void fir_start(const fir_dev *dev); /* Polls STATUS until DONE is set. Returns the number of polls used, or -1 on timeout. */ long fir_wait_done(const fir_dev *dev, long max_polls); #endif /* FIR_REGS_H */