Skip to content

Commit

Permalink
regenerate apb wrapper to have gated clock and update fw
Browse files Browse the repository at this point in the history
  • Loading branch information
NouranAbdelaziz committed Jul 8, 2024
1 parent dc9cc39 commit 9bbb088
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 5 deletions.
4 changes: 2 additions & 2 deletions EF_SPI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ info:
license: APACHE 2.0
author: Mohamed Shalan
email: [email protected]
version: v1.0.5
date: 27-6-2024
version: v1.0.6
date: 08-07-2024
category: digital
tags:
- peripheral
Expand Down
4 changes: 4 additions & 0 deletions fw/EF_SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include <EF_SPI.h>

void EF_SPI_setGclkEnable (uint32_t spi_base, int value){
EF_SPI_TYPE* spi = (EF_SPI_TYPE*)spi_base;
spi->GCLK = value;
}

void EF_SPI_writeData(uint32_t spi_base, int data){

Expand Down
2 changes: 1 addition & 1 deletion fw/EF_SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <EF_SPI_regs.h>
#include <stdint.h>
#include <stdbool.h>

void EF_SPI_setGclkEnable (uint32_t spi_base, int value);
void EF_SPI_writeData(uint32_t spi_base, int data);
int EF_SPI_readData(uint32_t spi_base);
void EF_SPI_writepolarity(uint32_t spi_base, bool polarity);
Expand Down
1 change: 1 addition & 0 deletions fw/EF_SPI_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ typedef struct _EF_SPI_TYPE_ {
__R MIS;
__R RIS;
__W IC;
__W GCLK;
} EF_SPI_TYPE;

#endif
Expand Down
43 changes: 42 additions & 1 deletion hdl/rtl/bus_wrappers/EF_SPI_APB.pp.v
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@




















Expand All @@ -88,6 +102,10 @@ module EF_SPI_APB #(
CDW = 8,
FAW = 4
) (
`ifdef USE_POWER_PINS
input wire VPWR,
input wire VGND,
`endif
input wire PCLK,
input wire PRESETn,
input wire PWRITE,
Expand Down Expand Up @@ -121,7 +139,23 @@ module EF_SPI_APB #(
localparam MIS_REG_OFFSET = 16'hFF04;
localparam RIS_REG_OFFSET = 16'hFF08;
localparam IC_REG_OFFSET = 16'hFF0C;
wire clk = PCLK;

wire clk_g;
wire clk_gated_en = GCLK_REG[0];

(* keep *) sky130_fd_sc_hd__dlclkp_4 clk_gate(
`ifdef USE_POWER_PINS
.VPWR(VPWR),
.VGND(VGND),
.VNB(VGND),
.VPB(VPWR),
`endif
.GCLK(clk_g),
.GATE(clk_gated_en),
.CLK(PCLK)
);

wire clk = clk_g;
wire rst_n = PRESETn;


Expand Down Expand Up @@ -220,6 +254,12 @@ module EF_SPI_APB #(
else
TX_FIFO_FLUSH_REG <= 1'h0 & TX_FIFO_FLUSH_REG;

localparam GCLK_REG_OFFSET = 16'hFF10;
reg [0:0] GCLK_REG;
always @(posedge PCLK or negedge PRESETn) if(~PRESETn) GCLK_REG <= 0;
else if(apb_we & (PADDR[16-1:0]==GCLK_REG_OFFSET))
GCLK_REG <= PWDATA[1-1:0];

reg [5:0] IM_REG;
reg [5:0] IC_REG;
reg [5:0] RIS_REG;
Expand Down Expand Up @@ -317,6 +357,7 @@ module EF_SPI_APB #(
(PADDR[16-1:0] == MIS_REG_OFFSET) ? MIS_REG :
(PADDR[16-1:0] == RIS_REG_OFFSET) ? RIS_REG :
(PADDR[16-1:0] == IC_REG_OFFSET) ? IC_REG :
(PADDR[16-1:0] == GCLK_REG_OFFSET) ? GCLK_REG :
32'hDEADBEEF;

assign PREADY = 1'b1;
Expand Down
27 changes: 26 additions & 1 deletion hdl/rtl/bus_wrappers/EF_SPI_APB.v
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ module EF_SPI_APB #(
CDW = 8,
FAW = 4
) (
`ifdef USE_POWER_PINS
input wire VPWR,
input wire VGND,
`endif
`APB_SLAVE_PORTS,
input wire [1-1:0] miso,
output wire [1-1:0] mosi,
Expand All @@ -54,7 +58,23 @@ module EF_SPI_APB #(
localparam MIS_REG_OFFSET = `APB_AW'hFF04;
localparam RIS_REG_OFFSET = `APB_AW'hFF08;
localparam IC_REG_OFFSET = `APB_AW'hFF0C;
wire clk = PCLK;

wire clk_g;
wire clk_gated_en = GCLK_REG[0];

(* keep *) sky130_fd_sc_hd__dlclkp_4 clk_gate(
`ifdef USE_POWER_PINS
.VPWR(VPWR),
.VGND(VGND),
.VNB(VGND),
.VPB(VPWR),
`endif
.GCLK(clk_g),
.GATE(clk_gated_en),
.CLK(PCLK)
);

wire clk = clk_g;
wire rst_n = PRESETn;


Expand Down Expand Up @@ -133,6 +153,10 @@ module EF_SPI_APB #(
assign tx_flush = TX_FIFO_FLUSH_REG[0 : 0];
`APB_REG_AC(TX_FIFO_FLUSH_REG, 0, 1, 1'h0)

localparam GCLK_REG_OFFSET = `APB_AW'hFF10;
reg [0:0] GCLK_REG;
`APB_REG(GCLK_REG, 0, 1)

reg [5:0] IM_REG;
reg [5:0] IC_REG;
reg [5:0] RIS_REG;
Expand Down Expand Up @@ -224,6 +248,7 @@ module EF_SPI_APB #(
(PADDR[`APB_AW-1:0] == MIS_REG_OFFSET) ? MIS_REG :
(PADDR[`APB_AW-1:0] == RIS_REG_OFFSET) ? RIS_REG :
(PADDR[`APB_AW-1:0] == IC_REG_OFFSET) ? IC_REG :
(PADDR[`APB_AW-1:0] == GCLK_REG_OFFSET) ? GCLK_REG :
32'hDEADBEEF;

assign PREADY = 1'b1;
Expand Down

0 comments on commit 9bbb088

Please sign in to comment.