bit Byte bps Bps

  • 位:位(bit,缩写为b)是存储器的最小单位,可以表示一位二进制数.

  • 字节:1字节(Byte,缩写为B)由8个位组成,即1Byte=8bit,是存储器的基本单位,通常被作为一个存储单元。一个B(常用大写的B来表示Byte)可代表一个字元(AZ)、数字(09)、或符号(,.?!%&±*/),但中文字需要2个Byte。

  • 16个位为一个字,它代表计算机处理指令或数据的二进制数位数,是计算机进行数据存储和数据处理的运算的单位。通常称16位是一个字,

  • B与b不同,注意区分,KB是千字节,Kb是千比特位。

  • 网线有两种做法,一种是交叉线,一种是平行线 
    568A标准:绿白,绿,橙白,蓝,蓝白,橙,棕白,棕  
    568B标准:橙白,橙,绿白,蓝,蓝白,绿,棕白,棕
    两种做法的差别就是橙色和绿色对换而已。  
    如果连接的双方地位不对等的,则使用平行线,例如电脑连接到路由器或交换机 如果连接的两台设备是对等的,则使用交叉线,例如电脑连接到电脑

  • 为什么内存地址是以字节为单位?

  • bit、Byte、bps、Bps、pps、Gbps的单位详细说明及换算

bps
bits per second”常用于表示数据机及网络通讯的传输速率。例如GigabitEthernet端口:
5 minute input rate 38410000 bits/sec, 6344 packets/sec
382410000 bits/sec = 382.41Mbps
所以常说的快速以太网能达到百兆传输,其实实际传输文件大小只有10MB = 100Mb
注意:在计算传输速率时,直接用1000来换算(1 Mb = 1000 Kb = 1000,000 bit)

Bps
Byte per second”电脑一般都以Bps显示速度,但有时会跟传输速率混淆,例如ADSL宣称的带宽为1Mbps ,但在实际应用中,下载速度没有1MB ,只有1Mbps/8 = 128kBps
也就是说与传输速度有关的b一般指的是bit。
与容量有关的B一般指的是Byte。

1. 以下是用System Verilog书写的7位数据位,1位偶校验,波特率为115200bps的uart串行发送端: ```systemverilog module uart_tx ( input clk, input reset, input [6:0] data_in, output reg tx_out ); // 波特率计算 localparam BAUD_RATE = 115200; localparam BIT_TIME = $floor(1000000000/BAUD_RATE); // 单位:ns // 发送状态机 typedef enum logic [2:0] { IDLE, START_BIT, DATA_BITS, PARITY_BIT, STOP_BIT } TxState; reg [2:0] state = IDLE; reg [6:0] data = 7'b0000000; reg parity = 1'b0; reg [3:0] bit_cnt = 4'd0; reg [31:0] bit_timer = 32'd0; // 计时器 always @(posedge clk) begin if (reset) begin bit_timer <= 0; end else begin bit_timer <= bit_timer + 1; end end // 状态机 always @(posedge clk) begin if (reset) begin state <= IDLE; data <= 7'b0000000; parity <= 1'b0; bit_cnt <= 4'd0; tx_out <= 1'b1; end else begin case (state) IDLE: begin if (!tx_out) begin state <= START_BIT; bit_cnt <= 4'd0; bit_timer <= 0; end end START_BIT: begin if (bit_timer >= BIT_TIME) begin tx_out <= 1'b0; state <= DATA_BITS; bit_cnt <= 4'd1; bit_timer <= 0; end end DATA_BITS: begin if (bit_timer >= BIT_TIME) begin data[bit_cnt-1] <= data_in[bit_cnt-1]; parity <= parity ^ data_in[bit_cnt-1]; bit_cnt <= bit_cnt + 1; if (bit_cnt == 8) begin state <= PARITY_BIT; bit_cnt <= 4'd0; end else begin bit_timer <= 0; end end end PARITY_BIT: begin if (bit_timer >= BIT_TIME) begin tx_out <= parity; state <= STOP_BIT; bit_timer <= 0; end end STOP_BIT: begin if (bit_timer >= BIT_TIME) begin tx_out <= 1'b1; state <= IDLE; bit_timer <= 0; end end default: state <= IDLE; endcase end end endmodule ``` 2. 以下是用SV书写的对应的行为模型(接收端),并输出激励中的字节值,奇偶性错误的,输出校验错误: ```systemverilog module uart_rx ( input clk, input reset, input rx_in, output [6:0] data_out, output reg valid, output reg parity_error, output reg frame_error ); // 波特率计算 localparam BAUD_RATE = 115200; localparam BIT_TIME = $floor(1000000000/BAUD_RATE); // 单位:ns // 接收状态机 typedef enum logic [2:0] { IDLE, START_BIT, DATA_BITS, PARITY_BIT, STOP_BIT } RxState; reg [2:0] state = IDLE; reg [6:0] data = 7'b0000000; reg parity = 1'b0; reg [3:0] bit_cnt = 4'd0; reg [31:0] bit_timer = 32'd0; // 计时器 always @(posedge clk) begin if (reset) begin bit_timer <= 0; end else begin bit_timer <= bit_timer + 1; end end // 状态机 always @(posedge clk) begin if (reset) begin state <= IDLE; data <= 7'b0000000; parity <= 1'b0; bit_cnt <= 4'd0; valid <= 1'b0; parity_error <= 1'b0; frame_error <= 1'b0; end else begin case (state) IDLE: begin if (!rx_in) begin state <= START_BIT; bit_cnt <= 4'd0; bit_timer <= 0; end end START_BIT: begin if (bit_timer >= BIT_TIME) begin state <= DATA_BITS; bit_cnt <= 4'd1; bit_timer <= 0; end end DATA_BITS: begin if (bit_timer >= BIT_TIME) begin data[bit_cnt-1] <= rx_in; parity <= parity ^ rx_in; bit_cnt <= bit_cnt + 1; if (bit_cnt == 8) begin state <= PARITY_BIT; bit_cnt <= 4'd0; end else begin bit_timer <= 0; end end end PARITY_BIT: begin if (bit_timer >= BIT_TIME) begin if (rx_in != parity) begin parity_error <= 1'b1; end state <= STOP_BIT; bit_timer <= 0; end end STOP_BIT: begin if (bit_timer >= BIT_TIME) begin if (rx_in) begin frame_error <= 1'b1; end else begin data_out <= data; valid <= 1'b1; end state <= IDLE; bit_timer <= 0; end end default: state <= IDLE; endcase end end endmodule ``` 3. 以下是编写的testcase: ```systemverilog module testbench; // 参数 localparam BAUD_RATE = 115200; localparam BIT_TIME = $floor(1000000000/BAUD_RATE); // 单位:ns // 实例化 uart_tx tx ( .clk(clk), .reset(reset), .data_in(data_in), .tx_out(tx_out) ); uart_rx rx ( .clk(clk), .reset(reset), .rx_in(rx_in), .data_out(data_out), .valid(valid), .parity_error(parity_error), .frame_error(frame_error) ); // 输入 reg clk = 1; reg reset = 0; reg [6:0] data_in; reg [31:0] timer = 0; reg [31:0] rand_seed = 1; // 输出 wire tx_out; wire [6:0] data_out; wire valid; wire parity_error; wire frame_error; // 生成随机字节 function automatic void gen_byte(ref byte b); repeat (8) begin b[$] = $urandom(rand_seed) % 2; end endfunction // 生成随机奇偶校验的字节 function automatic void gen_parity_byte(ref byte b, ref bit p); repeat (8) begin b[$] = $urandom(rand_seed) % 2; p ^= b[$]; end b[$] = p; endfunction // 生成随机错误字节(奇偶性错误,数据位错误,停止位错误) function automatic void gen_error_byte(ref byte b, input bit parity, input bit data, input bit stop); repeat (8) begin b[$] = $urandom(rand_seed) % 2; end b[0] = ~b[0] ^ parity; if (data) begin b[$-1] = ~b[$-1]; end if (stop) begin b[$] = ~b[$]; end endfunction // 生成随机字节序列 function automatic void gen_bytes(ref byte [][8] bytes, input int count, input bit parity); bit p; for (int i = 0; i < count; i++) begin gen_parity_byte(bytes[i], p); if (parity == 0) begin p = ~p; end end endfunction // 生成随机错误字节序列 function automatic void gen_error_bytes(ref byte [][8] bytes, input int count, input bit parity, input bit data, input bit stop); bit p; for (int i = 0; i < count; i++) begin gen_error_byte(bytes[i], parity, data, stop); end endfunction // 计时器 always @(posedge clk) begin timer <= timer + 1; end // 时钟 always #5 clk <= ~clk; // 测试过程 initial begin // 测试1:连续发送100个随机字节 $display("Test 1: send 100 random bytes"); gen_bytes(data_in, 100, 1); repeat (100) begin #1; end repeat (10) begin #1; end // 测试2:发送一个有奇偶校验错误的字节 $display("Test 2: send a byte with parity error"); gen_error_bytes(data_in, 1, 1, 0, 0); repeat (10) begin #1; end // 测试3:发送一个有数据位错误的字节 $display("Test 3: send a byte with data error"); gen_error_bytes(data_in, 1, 0, 1, 0); repeat (10) begin #1; end // 测试4:发送一个有停止位错误的字节 $display("Test 4: send a byte with stop error"); gen_error_bytes(data_in, 1, 0, 0, 1); repeat (10) begin #1; end // 结束 $finish; end endmodule ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值