OpenCores
URL https://opencores.org/ocsvn/oms8051mini/oms8051mini/trunk

Subversion Repositories oms8051mini

[/] [oms8051mini/] [trunk/] [verif/] [agents/] [spi/] [spi_tasks.v] - Diff between revs 10 and 34

Only display areas with differences | Details | Blame | View Log

Rev 10 Rev 34
 
 
// #################################################################
// #################################################################
// Module: spi tasks
// Module: spi tasks
//
//
// Description : All ST and ATMEL commands are made into tasks
// Description : All ST and ATMEL commands are made into tasks
// #################################################################
// #################################################################
 
 
event      spi_error_detected;
event      spi_error_detected;
reg  [1:0] spi_chip_no;
reg  [1:0] spi_chip_no;
 
 
integer spi_err_cnt;
integer spi_err_cnt;
 
 
task spi_init;
task spi_init;
begin
begin
   spi_err_cnt = 0;
   spi_err_cnt = 0;
   spi_chip_no = 0;
   spi_chip_no = 0;
end
end
endtask
endtask
 
 
 
 
always @spi_error_detected
always @spi_error_detected
begin
begin
  `TB_GLBL.test_err;
  `TB_GLBL.test_err;
        spi_err_cnt = spi_err_cnt + 1;
        spi_err_cnt = spi_err_cnt + 1;
end
end
 
 
// Write One Byte
// Write One Byte
task spi_write_byte;
task spi_write_byte;
    input [7:0] datain;
    input [7:0] datain;
    reg  [31:0] read_data;
    reg  [31:0] read_data;
    begin
    begin
 
 
      @(posedge tb_top.app_clk)
      @(posedge tb_top.app_clk)
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h4,{datain,24'h0});
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h4,{datain,24'h0});
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h0,{1'b1,6'h0,
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h0,{1'b1,1'h0,
                                spi_chip_no[1:0],
                                spi_chip_no[1:0],
                                2'b0,    // Write Operatopm
                                2'b0,    // Write Operatopm
                                2'b0,    // Single Transfer
                                2'b0,    // Single Transfer
                                6'h10,    // sck clock period
                                8'h10,    // sck clock period
                                5'h2,    // cs setup/hold period
                                8'h2,    // cs setup/hold period
                                8'h40 }); // cs bit information
                                8'h40 }); // cs bit information
 
 
     tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
     tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
     while(read_data[31]) begin
     while(read_data[31]) begin
        @(posedge tb_top.app_clk) ;
        @(posedge tb_top.app_clk) ;
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
      end
      end
    end
    end
endtask
endtask
 
 
//***** ST : Write Enable task ******//
//***** ST : Write Enable task ******//
task spi_write_dword;
task spi_write_dword;
    input [31:0] cmd;
    input [31:0] cmd;
    input [7:0]  cs_byte;
    input [7:0]  cs_byte;
    reg   [31:0] read_data;
    reg   [31:0] read_data;
    begin
    begin
      @(posedge tb_top.app_clk)
      @(posedge tb_top.app_clk)
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h4,{cmd});
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h4,{cmd});
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h0,{1'b1,6'h0,
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h0,{1'b1,1'h0,
                                spi_chip_no[1:0],
                                spi_chip_no[1:0],
                                2'b0,    // Write Operatopm
                                2'b0,    // Write Operatopm
                                2'h3,    // 4 Transfer
                                2'h3,    // 4 Transfer
                                6'h10,    // sck clock period
                                8'h10,    // sck clock period
                                5'h2,    // cs setup/hold period
                                8'h2,    // cs setup/hold period
                                cs_byte[7:0] }); // cs bit information
                                cs_byte[7:0] }); // cs bit information
 
 
     tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
     tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
     while(read_data[31]) begin
     while(read_data[31]) begin
        @(posedge tb_top.app_clk) ;
        @(posedge tb_top.app_clk) ;
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
      end
      end
    end
    end
endtask
endtask
 
 
 
 
//***** ST : Write Enable task ******//
//***** ST : Write Enable task ******//
task spi_read_dword;
task spi_read_dword;
    output [31:0] dataout;
    output [31:0] dataout;
    input  [7:0]  cs_byte;
    input  [7:0]  cs_byte;
    reg    [31:0] read_data;
    reg    [31:0] read_data;
    begin
    begin
 
 
      @(posedge tb_top.app_clk)
      @(posedge tb_top.app_clk)
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h0,{1'b1,6'h0,
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h0,{1'b1,1'h0,
                                spi_chip_no[1:0],
                                spi_chip_no[1:0],
                                2'b1,    // Read Operatopm
                                2'b1,    // Read Operatopm
                                2'h3,    // 4 Transfer
                                2'h3,    // 4 Transfer
                                6'h10,    // sck clock period
                                8'h10,    // sck clock period
                                5'h2,    // cs setup/hold period
                                8'h2,    // cs setup/hold period
                                cs_byte[7:0] }); // cs bit information
                                cs_byte[7:0] }); // cs bit information
 
 
     tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
     tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
 
 
     while(read_data[31]) begin
     while(read_data[31]) begin
        @(posedge tb_top.app_clk) ;
        @(posedge tb_top.app_clk) ;
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
     end
     end
 
 
     tb_top.cpu_read(`ADDR_SPACE_SPI,'h8,dataout);
     tb_top.cpu_read(`ADDR_SPACE_SPI,'h8,dataout);
 
 
    end
    end
endtask
endtask
 
 
 
 
 
 
task spi_sector_errase;
task spi_sector_errase;
    input [23:0] address;
    input [23:0] address;
    reg   [31:0] read_data;
    reg   [31:0] read_data;
    begin
    begin
 
 
      @(posedge tb_top.app_clk) ;
      @(posedge tb_top.app_clk) ;
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h4,{8'hD8,address[23:0]});
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h4,{8'hD8,address[23:0]});
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h0,{1'b1,6'h0,
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h0,{1'b1,1'h0,
                                spi_chip_no[1:0],
                                spi_chip_no[1:0],
                                2'b0,    // Write Operatopm
                                2'b0,    // Write Operatopm
                                2'h3,    // 4 Transfer
                                2'h3,    // 4 Transfer
                                6'h10,    // sck clock period
                                8'h10,    // sck clock period
                                5'h2,    // cs setup/hold period
                                8'h2,    // cs setup/hold period
                                8'h1 }); // cs bit information
                                8'h1 }); // cs bit information
 
 
     tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
     tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
 
 
      $display("%t : %m : Sending Sector Errase for Address : %x",$time,address);
      $display("%t : %m : Sending Sector Errase for Address : %x",$time,address);
 
 
 
 
     tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
     tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
     while(read_data[31]) begin
     while(read_data[31]) begin
        @(posedge tb_top.app_clk) ;
        @(posedge tb_top.app_clk) ;
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
     end
     end
   end
   end
endtask
endtask
 
 
 
 
task spi_page_write;
task spi_page_write;
    input [23:0] address;
    input [23:0] address;
    reg [7:0] i;
    reg [7:0] i;
    reg [31:0] write_data;
    reg [31:0] write_data;
    begin
    begin
 
 
      spi_write_dword({8'h02,address[23:0]},8'h0);
      spi_write_dword({8'h02,address[23:0]},8'h0);
 
 
      for(i = 0; i < 252 ; i = i + 4) begin
      for(i = 0; i < 252 ; i = i + 4) begin
         write_data [31:24]  = i;
         write_data [31:24]  = i;
         write_data [23:16]  = i+1;
         write_data [23:16]  = i+1;
         write_data [15:8]   = i+2;
         write_data [15:8]   = i+2;
         write_data [7:0]    = i+3;
         write_data [7:0]    = i+3;
         spi_write_dword(write_data,8'h0);
         spi_write_dword(write_data,8'h0);
         $display("%m : Writing Data : %x",write_data);
         $display("%m : Writing Data : %x",write_data);
      end
      end
 
 
      // Writting last 4 byte with de-selecting the chip select 
      // Writting last 4 byte with de-selecting the chip select 
         write_data [31:24]  = i;
         write_data [31:24]  = i;
         write_data [23:16]  = i+1;
         write_data [23:16]  = i+1;
         write_data [15:8]   = i+2;
         write_data [15:8]   = i+2;
         write_data [7:0]    = i+3;
         write_data [7:0]    = i+3;
      spi_write_dword(write_data,8'h1);
      spi_write_dword(write_data,8'h1);
      $display("%m : Writing Data : %x",write_data);
      $display("%m : Writing Data : %x",write_data);
 
 
    end
    end
endtask
endtask
 
 
 
 
task spi_page_read_verify;
task spi_page_read_verify;
    input [23:0] address;
    input [23:0] address;
    reg   [31:0] read_data;
    reg   [31:0] read_data;
    reg [7:0] i;
    reg [7:0] i;
    reg [31:0] exp_data;
    reg [31:0] exp_data;
    begin
    begin
 
 
      spi_write_dword({8'h03,address[23:0]},8'h0);
      spi_write_dword({8'h03,address[23:0]},8'h0);
 
 
      for(i = 0; i < 252 ; i = i + 4) begin
      for(i = 0; i < 252 ; i = i + 4) begin
         exp_data [31:24]  = i;
         exp_data [31:24]  = i;
         exp_data [23:16]  = i+1;
         exp_data [23:16]  = i+1;
         exp_data [15:8]   = i+2;
         exp_data [15:8]   = i+2;
         exp_data [7:0]    = i+3;
         exp_data [7:0]    = i+3;
         spi_read_dword(read_data,8'h0);
         spi_read_dword(read_data,8'h0);
         if(read_data != exp_data) begin
         if(read_data != exp_data) begin
            -> spi_error_detected;
            -> spi_error_detected;
            $display("%m : ERROR : Exp Data : %x Rxd Data : %x",exp_data,read_data);
            $display("%m : ERROR : Exp Data : %x Rxd Data : %x",exp_data,read_data);
         end else begin
         end else begin
            $display("%m : STATUS :  Data Matched : %x ",read_data);
            $display("%m : STATUS :  Data Matched : %x ",read_data);
         end
         end
 
 
      end
      end
 
 
      // Reading last 4 byte with de-selecting the chip select 
      // Reading last 4 byte with de-selecting the chip select 
         exp_data [31:24]  = i;
         exp_data [31:24]  = i;
         exp_data [23:16]  = i+1;
         exp_data [23:16]  = i+1;
         exp_data [15:8]   = i+2;
         exp_data [15:8]   = i+2;
         exp_data [7:0]    = i+3;
         exp_data [7:0]    = i+3;
 
 
         spi_read_dword(read_data,8'h0);
         spi_read_dword(read_data,8'h0);
         if(read_data != exp_data) begin
         if(read_data != exp_data) begin
            -> spi_error_detected;
            -> spi_error_detected;
            $display("%m : ERROR : Exp Data : %x Rxd Data : %x",exp_data,read_data);
            $display("%m : ERROR : Exp Data : %x Rxd Data : %x",exp_data,read_data);
         end else begin
         end else begin
            $display("%m : STATUS :  Data Matched : %x ",read_data);
            $display("%m : STATUS :  Data Matched : %x ",read_data);
         end
         end
 
 
    end
    end
endtask
endtask
 
 
 
 
 
 
 
 
task spi_op_over;
task spi_op_over;
    reg [31:0] read_data;
    reg [31:0] read_data;
    begin
    begin
     tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
     tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
      while(read_data[31]) begin
      while(read_data[31]) begin
        @(posedge tb_top.app_clk) ;
        @(posedge tb_top.app_clk) ;
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
      end
      end
      #100;
      #100;
    end
    end
endtask
endtask
 
 
task spi_wait_busy;
task spi_wait_busy;
    reg [31:0] read_data;
    reg [31:0] read_data;
    reg        exit_flag;
    reg        exit_flag;
    integer    pretime;
    integer    pretime;
begin
begin
    read_data = 1;
    read_data = 1;
 
 
    pretime = $time;
    pretime = $time;
 
 
 
 
   exit_flag = 1;
   exit_flag = 1;
   while(exit_flag == 1) begin
   while(exit_flag == 1) begin
 
 
    tb_top.cpu_write(`ADDR_SPACE_SPI,'h4,{8'h05,24'h0});
    tb_top.cpu_write(`ADDR_SPACE_SPI,'h4,{8'h05,24'h0});
    tb_top.cpu_write(`ADDR_SPACE_SPI,'h0,{1'b1,6'h0,
    tb_top.cpu_write(`ADDR_SPACE_SPI,'h0,{1'b1,1'h0,
                                spi_chip_no[1:0],
                                spi_chip_no[1:0],
                                2'b0,    // Write Operation
                                2'b0,    // Write Operation
                                2'b0,    // 1 Transfer
                                2'b0,    // 1 Transfer
                                6'h10,    // sck clock period
                                8'h10,    // sck clock period
                                5'h2,    // cs setup/hold period
                                8'h2,    // cs setup/hold period
                                8'h0 }); // cs bit information
                                8'h0 }); // cs bit information
 
 
 
 
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
        while(read_data[31]) begin
        while(read_data[31]) begin
          @(posedge tb_top.app_clk) ;
          @(posedge tb_top.app_clk) ;
          tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
          tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
        end
        end
 
 
     // Send Status Request Cmd
     // Send Status Request Cmd
 
 
 
 
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h0,{1'b1,6'h0,
      tb_top.cpu_write(`ADDR_SPACE_SPI,'h0,{1'b1,1'h0,
                                spi_chip_no[1:0],
                                spi_chip_no[1:0],
                                2'b1,    // Read Operation
                                2'b1,    // Read Operation
                                2'b0,    // 1 Transfer
                                2'b0,    // 1 Transfer
                                6'h10,    // sck clock period
                                8'h10,    // sck clock period
                                5'h2,    // cs setup/hold period
                                8'h2,    // cs setup/hold period
                                8'h40 }); // cs bit information
                                8'h40 }); // cs bit information
 
 
 
 
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
        while(read_data[31]) begin
        while(read_data[31]) begin
          @(posedge tb_top.app_clk) ;
          @(posedge tb_top.app_clk) ;
          tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
          tb_top.cpu_read(`ADDR_SPACE_SPI,'h0,read_data);
        end
        end
 
 
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h8,read_data);
        tb_top.cpu_read(`ADDR_SPACE_SPI,'h8,read_data);
        exit_flag = read_data[24];
        exit_flag = read_data[24];
        $display("Total time Elapsed: %0t(us): %m : Checking the SPI RDStatus : %x",($time - pretime)/1000000 ,read_data);
        $display("Total time Elapsed: %0t(us): %m : Checking the SPI RDStatus : %x",($time - pretime)/1000000 ,read_data);
      repeat (1000) @ (posedge tb_top.app_clk) ;
      repeat (1000) @ (posedge tb_top.app_clk) ;
     end
     end
  end
  end
endtask
endtask
 
 
 
 
 
 
task spi_tb_status;
task spi_tb_status;
begin
begin
 
 
   $display("#############################");
   $display("#############################");
   $display("   Test Statistic            ");
   $display("   Test Statistic            ");
   if(spi_err_cnt >0) begin
   if(spi_err_cnt >0) begin
      $display("TEST STATUS : FAILED ");
      $display("TEST STATUS : FAILED ");
      $display("TOTAL ERROR COUNT : %d ",spi_err_cnt);
      $display("TOTAL ERROR COUNT : %d ",spi_err_cnt);
   end else begin
   end else begin
      $display("TEST STATUS : PASSED ");
      $display("TEST STATUS : PASSED ");
   end
   end
   $display("#############################");
   $display("#############################");
end
end
endtask
endtask
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.