AMBA APB总线

  前面分析了AHB总线协议。接下来分析APB总线协议。

  (一) APB总线接口:

  PCLK APB总线时钟。

  PRESETn APB总线复位。低有效。

  PADDR 地址总线。

  PSELx 从设备选择。

  PENABLE APB传输选通。

  PWRITE 高为写传输,低为读。

  PRDATA 读数据总线。

  PWDATA 写数据总线。

  接口信号定义如下:

 1 interface   apb_slv_intf #(
 2     parameter   AW  = 32,
 3                 DW  = 32
 4 ) (
 5     input   logic       PCLK,
 6     input   logic       PRESETn
 7 );
 8     logic               PSEL;
 9     logic               PENABLE;
10     logic   [AW-1:0]    PADDR;
11     logic               PWRITE;
12     logic   [DW-1:0]    PWDATA;
13
14     logic   [DW-1:0]    PRDATA;
15
16
17     modport m (
18         input   PRDATA,
19         output  PSEL, PENABLE, PADDR, PWRITE, PWDATA
20     );
21
22     modport s (
23         input   PSEL, PENABLE, PADDR, PWRITE, PWDATA,
24         output  PRDATA
25     );
26
27 endinterface: apb_slv_intf

  (二) APB总线时序图:

写传输

读传输

  注意在PENABLE信号有效后从设备需要给出有效数据/读取有效数据。

  (三) AHB总线到APB总线转换桥

  1 module ahb2apb_bridge #(
  2     parameter   AHB_AW  = 32,
  3                 AHB_DW  = 32,
  4                 APB_AW  = 32,
  5                 APB_DW  = 32,
  6                 NSLV    = 16
  7 ) (
  8     input   logic   HCLK,
  9     input   logic   HRESETn,
 10     input   logic   PCLK,
 11     input   logic   PRESETn,
 12     ahb_slv_intf.s  ahb,
 13     apb_slv_intf.m  apbv[NSLV]
 14 );
 15
 16     logic   ahb_work;
 17     logic   apb_work;
 18
 19     genvar  i;
 20
 21     typedef enum logic [1:0] {
 22         AHB_IDLE    = 2‘b00,
 23         AHB_WRITE   = 2‘b01,
 24         AHB_READ    = 2‘b10,
 25         AHB_WAIT    = 2‘b11
 26     } ahb_state_e;
 27
 28     // Signal of AHB Domain
 29     struct {
 30         logic                   work;
 31         logic   [AHB_AW-1:0]    addr;
 32         logic   [AHB_DW-1:0]    data;
 33         logic                   write;
 34         ahb_state_e             cstate, nstate;
 35     } ahbd;
 36
 37     typedef enum logic [1:0] {
 38         APB_IDLE    = 2‘b00,
 39         APB_WRITE   = 2‘b01,
 40         APB_READ    = 2‘b10
 41     } apb_state_e;
 42
 43     // Signal of APB Domain
 44     struct {
 45         logic                   work;
 46         logic   [APB_DW-1:0]    data[NSLV];
 47         logic                   PSEL[NSLV];
 48         logic                   PENABLE[NSLV];
 49         apb_state_e             cstate, nstate;
 50     } apbd;
 51
 52
 53     // AHB Control Logic
 54     always_comb begin
 55         case (ahbd.cstate)
 56             AHB_IDLE: begin
 57                 if (ahb.HSEL && ahb.HTRANS == HTRANS_NONSEQ) begin
 58                     if (ahb.HWRITE)
 59                         ahbd.nstate = AHB_WRITE;
 60                     else
 61                         ahbd.nstate = AHB_READ;
 62                 end
 63                 else
 64                     ahbd.nstate = AHB_IDLE;
 65             end
 66             AHB_WRITE: begin
 67                 if (apbd.work)
 68                     ahbd.nstate = AHB_WAIT;
 69                 else
 70                     ahbd.nstate = AHB_WRITE;
 71             end
 72             AHB_READ: begin
 73                 if (apbd.work)
 74                     ahbd.nstate = AHB_WAIT;
 75                 else
 76                     ahbd.nstate = AHB_READ;
 77             end
 78             AHB_WAIT: begin
 79                 if (!apbd.work)
 80                     ahbd.nstate = AHB_IDLE;
 81                 else
 82                     ahbd.nstate = AHB_WAIT;
 83             end
 84             default: ahbd.nstate = AHB_IDLE;
 85         endcase
 86     end
 87
 88     always_ff @(posedge HCLK or negedge HRESETn) begin
 89         if (!HRESETn)
 90             ahbd.cstate <= AHB_IDLE;
 91         else
 92             ahbd.cstate <= ahbd.nstate;
 93     end
 94
 95     always_ff @(posedge HCLK or negedge HRESETn) begin
 96         if (!HRESETn) begin
 97             ahbd.work   <= 1‘b0;
 98             ahbd.addr   <= ‘0;
 99             ahbd.data   <= ‘0;
100             ahbd.write  <= 1‘b0;
101             ahb.HREADY  <= 1‘b1;
102             ahb.HRDATA[APB_DW-1:0]  <= ‘0;
103         end
104         else begin
105             case (ahbd.cstate)
106                 AHB_IDLE: begin
107                     if (ahb.HSEL && ahb.HTRANS == HTRANS_NONSEQ) begin
108                         ahbd.addr   <= ahb.HADDR;
109                         ahbd.write  <= ahb.HWRITE;
110                         ahb.HREADY  <= 1‘b0;
111                     end
112                     else begin
113                         ahbd.addr   <= ‘0;
114                         ahbd.write  <= 1‘b0;
115                         ahb.HREADY  <= 1‘b1;
116                     end
117                     ahbd.work   <= 1‘b0;
118                     ahbd.data   <= ‘0;
119                     ahb.HRDATA[APB_DW-1:0]  <= apbd.data[ahbd.addr[AHB_AW-5:AHB_AW-8]];
120                 end
121                 AHB_WRITE: begin
122                     ahb.HREADY  <= 1‘b0;
123                     ahbd.work   <= 1‘b1;
124                     ahbd.data   <= ahb.HWDATA;
125                     ahb.HRDATA[APB_DW-1:0]  <= ‘0;
126                 end
127                 AHB_READ: begin
128                     ahbd.work   <= 1‘b1;
129                     ahbd.data   <= ‘0;
130                     ahb.HREADY  <= 1‘b0;
131                     ahb.HRDATA[APB_DW-1:0]  <= ‘0;
132                 end
133                 AHB_WAIT: begin
134                     ahbd.work   <= 1‘b0;
135                     ahb.HREADY  <= 1‘b0;
136                     ahb.HRDATA[APB_DW-1:0]  <= ‘0;
137                 end
138             endcase
139         end
140     end
141
142     assign  ahb.HRESP = HRESP_OKAY;
143     // assign  ahb.HRDATA[AHB_DW-1:APB_DW] = ‘0;
144
145
146     // APB Control Logic
147     always_comb begin
148         case (apbd.cstate)
149             APB_IDLE: begin
150                 if (ahbd.work) begin
151                     if (ahbd.write)
152                         apbd.nstate = APB_WRITE;
153                     else
154                         apbd.nstate = APB_READ;
155                 end
156                 else
157                     apbd.nstate = APB_IDLE;
158             end
159             APB_WRITE:  apbd.nstate = APB_IDLE;
160             APB_READ:   apbd.nstate = APB_IDLE;
161             default:    apbd.nstate = APB_IDLE;
162         endcase
163     end
164
165     always_ff @(posedge PCLK or negedge PRESETn) begin
166         if (!PRESETn)
167             apbd.cstate <= APB_IDLE;
168         else
169             apbd.cstate <= apbd.nstate;
170     end
171
172     always_ff @(posedge PCLK or negedge PRESETn) begin
173         if (!PRESETn) begin
174             apbd.work   <= 1‘b0;
175             for (int j = 0; j < NSLV; j++) begin
176                 apbd.PSEL[j]    <= 1‘b0;
177                 apbd.PENABLE[j] <= 1‘b0;
178             end
179         end
180         else begin
181             case (apbd.cstate)
182                 APB_IDLE: begin
183                     if (ahbd.work) begin
184                         apbd.work <= 1‘b1;
185                         for (int j = 0; j < NSLV; j++)
186                             apbd.PSEL[j] <= (ahbd.addr[AHB_AW-5:AHB_AW-8] == j) ? 1‘b1 : 1‘b0;
187                     end
188                     else begin
189                         apbd.work <= 1‘b0;
190                         for (int j = 0; j < NSLV; j++)
191                             apbd.PSEL[j] <= 1‘b0;
192                     end
193                     for (int j = 0; j < NSLV; j++)
194                         apbd.PENABLE[j] <= 1‘b0;
195                 end
196                 APB_WRITE: begin
197                     apbd.work <= 1‘b1;
198                     for (int j = 0; j < NSLV; j++)
199                         apbd.PENABLE[j] <= (ahbd.addr[AHB_AW-5:AHB_AW-8] == j) ? 1‘b1 : 1‘b0;
200                 end
201                 APB_READ: begin
202                     apbd.work <= 1‘b1;
203                     for (int j = 0; j < NSLV; j++)
204                         apbd.PENABLE[j] <= (ahbd.addr[AHB_AW-5:AHB_AW-8] == j) ? 1‘b1 : 1‘b0;
205                 end
206             endcase
207         end
208     end
209
210     generate
211         for (i = 0; i < NSLV; i++) begin: apbv_loop
212             assign apbv[i].PADDR    = {4‘h0, ahbd.addr[APB_AW-4-1:0]};
213             assign apbv[i].PWRITE   = ahbd.write;
214             assign apbv[i].PWDATA   = ahbd.data[APB_DW-1:0];
215             assign apbd.data[i]     = apbv[i].PRDATA;
216             assign apbv[i].PSEL     = apbd.PSEL[i];
217             assign apbv[i].PENABLE  = apbd.PENABLE[i];
218         end
219     endgenerate
220
221 endmodule: ahb2apb_bridge
时间: 2024-10-28 21:36:16

AMBA APB总线的相关文章

APB总线

APB(Advance Peripheral Bus)是AMBA总线的一部分,从1998年第一版至今共有3个版本. AMBA 2 APB Specfication:定义最基本的信号interface, 读写transfer, APB bridge, APB slave. AMBA 3 APB:增加定义信号PREADY, PSLVERR来完成对wait state和Error reporting的功能. AMBA 4 APB:增加定义信号PPROT, PSTRB来支持secure, supervi

AHB总线和APB总线

AHB主要用于高性能模块(如CPU.DMA和DSP等)之间的连接,作为SoC的片上系统总线,它包括以下一些特性:单个时钟边沿操作:非三态的实现方式:支持突发传输:支持分段传输:支持多个主控制器:可配置32位~128位总线宽度:支持字节.半字节和字的传输.AHB 系统由主模块.从模块和基础结构(Infrastructure)3部分组成,整个AHB总线上的传输都由主模块发出,由从模块负责回应.基础结构则由仲裁器(arbiter).主模块到从模块的多路器.从模块到主模块的多路器.译码器(decoder

AMBA AHB总线

Advanced Microcontroller Bus Architecture, 即AMBA,是ARM公司提出的总线规范,被很多SoC设计所采用,常用的实现有AHB(Advanced High-Performance Bus)和APB(Advanced Peripheral Bus).AHB用于高性能系统,APB用于低速外设.以下代码实例使用的是SystemVerilog描述. (一)AHB总线信号接口: 包括AHB主设备,AHB从设备,AHB仲裁器等. 1 interface ahb_ms

AMBA AXI总线

目前, ARM公司设计的AMBA2.0 AHB总线规范以及AMBA3.0 AXI总线规范正被广泛运用于各种SOC芯片设计中.它们对接口和互联提供的标准,有助于模块化设计以适应设计超大规模SOC的需要. AXI总线与AHB总线相比,特点非常明显: 划分为5个独立的通道,单向传输,有助于提升时钟频率,减少延时 支持乱序 valid与ready握手方式,更加简单 burst方式下,只需提供初始地址,控制更加方便 对称的主从接口,系统互联更加灵活 支持低功耗模式 ? ? ? ? ? ? ? ? ? ?

STM32WB AHB总线、APB总线与外设

方框图: 如图所示: 1)APB1外设 2)APB2外设 3)AHB1外设 4)AHB2外设 5)AHB3外设 6)AHB4外设(ABH共享总线外设) 原文地址:https://www.cnblogs.com/yeshenmeng/p/11004176.html

AMBA总线介绍

The Advanced Microcontroller Bus Architecture (AMBA) specification defines an on- chip communications standard for designing high-performance embedded microcontrollers. 高级微控制器总线结构Advanced Microcontroller Bus Architecture(AMBA)定义了高性能嵌入式微控制器的通信标准. l  A

[转]AMBA、AHB、APB、ASB总线简介

[转]http://www.cnblogs.com/zhaozhong1989/articles/3092140.html 1.前言 随着深亚微米工艺技术日益成熟,集成电路芯片的规模越来越大.数字IC从基于时序驱动的设计方法,发展到基于IP复用的设计方法,并在SOC设计中得到了广泛应用.在基于IP复用的SoC设计中,片上总线设计是最关键的问题.为此,业界出现了很多片上总线标准.其中,由ARM公司推出的AMBA片上总线受到了广大IP开发商和SoC系统集成者的青睐,已成为一种流行的工业标准片上结构.

AMBA总线协议AHB、APB

一.什么是AMBA总线 AMBA总线规范是ARM公司提出的总线规范,被大多数SoC设计采用,它规定了AHB (Advanced High-performance Bus).ASB (Advanced System Bus).APB (Advanced Peripheral Bus).AHB用于高性能.高时钟频率的系统结构,典型的应用如ARM核与系统内部的高速RAM.NAND FLASH.DMA.Bridge的连接.APB用于连接外部设备,对性能要求不高,而考虑低功耗问题.ASB是AHB的一种替代

AMBA总线分析

一.AMBA总线标准 1. AMBA 全称"Advanced Microprocessor Bus Architectur",是ARM公司提出的一种开放性的SOC总线标准,现已经广泛应用于RISC的内核上上. 2. AMBA定义了一种多总线系统(multilevel busing system),包括系统总线和等级稍低的外设总线. AMBA支持32位.64位.128位的数据总线,和32位的地址总线,同时支持byte和half-word设计. 3. AMBA总线标准定义了三组总线:AHB