// Example code for an M0 AHBLite System // Iain McNally // ECS, University of Soutampton // // This module is an AHB-Lite Slave containing a single read-only location // // Number of addressable locations : 1 // Size of each addressable location : 32 bits // Supported transfer sizes : Word // Alignment of base address : Word aligned // // Address map : // Base addess + 0 : // Read Switches // // For simplicity, this interface supports only 32-bit transfers. // The most significant 16 bits of the value read will always be 0 // since there are only 16 switches. module ahb_switches( // AHB Global Signals input HCLK, input HRESETn, // AHB Signals from Master to Slave input [31:0] HADDR, // With this interface HADDR is ignored input [31:0] HWDATA, input [2:0] HSIZE, input [1:0] HTRANS, input HWRITE, input HREADY, input HSEL, // AHB Signals from Slave to Master output [31:0] HRDATA, output HREADYOUT, //Non-AHB Signals input [15:0] Switches ); // AHB transfer codes needed in this module localparam No_Transfer = 2'b0; //control signals are stored in registers logic write_enable, read_enable; //Generate the control signals in the address phase always_ff @(posedge HCLK, negedge HRESETn) if ( ! HRESETn ) begin read_enable <= '0; end else if ( HREADY && HSEL && (HTRANS != No_Transfer) ) begin read_enable <= ! HWRITE; end else begin read_enable <= '0; end //Act on control signals in the data phase //read // (output of zero when not enabled for read is not necessary but may help with debugging) assign HRDATA = ( read_enable ) ? Switches : '0; //Transfer Response assign HREADYOUT = '1; //Single cycle Write & Read. Zero Wait state operations endmodule