SD-Host SD_CLK模块
程序员文章站
2024-02-22 23:10:10
...
hclk的分频电路,作为HOST模块时钟输入。
功能: 1、允许软件干预时钟分频(in_sd_clk_enable):是否输出时钟、频率与参考时钟关系;
2、允许硬件干预时钟处理(hw_stop_clk) :是否输出时钟、频率与参考时钟关系;
信号描述:
Signals | I/O | Width | from | to | Declaration |
---|---|---|---|---|---|
hclk | input | 1 | AHB bus | 时钟信号 | |
hrst_n | input | 1 | AHB bus | 复位信号 | |
in_clk_divider | input | [7:0] | sd_if | 分频关系 | |
in_sd_clk_enable | input | 1 | sd_if | 分频使能 | |
hw_stop_clk | input | 1 | sd_if | 硬件停时钟使能,一个blcok操作后 | |
out_sd_clk_dft | output | 1 | 频率输出(dft模式下输出) | ||
fifo_sd_clk | output | 1 | sd domain clock | ||
in_TestMode | input | 1 | 测试模式(dft模式) |
代码实现:
module sd_clk(
hclk,
hrst_n,
in_clk_divider,
in_sd_clk_enable,
hw_stop_clk,
out_sd_clk_dft,
fifo_sd_clk,
in_TestMode
);
input in_TestMode;
input hclk;
input hrst_n;
input [7:0] in_clk_divider;
input in_sd_clk_enable;
input hw_stop_clk;
output fifo_sd_clk;
output out_sd_clk_dft;
reg out_sd_clk;
reg [7:0] div_counter;
wire divider_0_val;
wire out_sd_clk_tp;
wire clk_ena_stop;
assign divider_0_val = (in_clk_divider == 8'b0 );
assign clk_ena_stop = (!in_sd_clk_enable || hw_stop_clk);
aaa@qq.com(posedge hclk or negedge hrst_n) begin
if(!hrst_n)
out_sd_clk <= 8'b0;
else if (clk_ena_stop)
out_sd_clk <= out_sd_clk;
else if (div_0_val)
out_sd_clk <= hclk;
else if (div_counter == in_clk_divider-1)
out_sd_clk <= ~out_sd_clk;
end
aaa@qq.com(posedge hclk or negedge hrst_n) begin
if(!hrst_n)
div_counter <= 8'b0;
else if ( clk_ena_stop || div_0_val)
div_counter <= 8'b0;
else begin
if(div_counter == in_clk_divider-1)
div_counter <= 8'b0;
else
div_counter <= div_counter + 1;
end
end
assign fifo_sd_clk = div_0_val ? hclk : out_sd_clk;
assign out_sd_clk_dft = (!in_sd_clk_enable || hw_stop_clk) ?
1'b0 : (in_TestMode) ?
hclk : (in_clk_divider == 8'b0) ?
hclk : out_sd_clk;
endmodule