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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [actel_m1a3pl_dev_kit/] [rtl/] [verilog/] [dac_spi_if.v] - Diff between revs 107 and 111

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 107 Rev 111
Line 55... Line 55...
    mclk,                           // Main system clock
    mclk,                           // Main system clock
    per_addr,                       // Peripheral address
    per_addr,                       // Peripheral address
    per_din,                        // Peripheral data input
    per_din,                        // Peripheral data input
    per_en,                         // Peripheral enable (high active)
    per_en,                         // Peripheral enable (high active)
    per_we,                         // Peripheral write enable (high active)
    per_we,                         // Peripheral write enable (high active)
    puc                             // Main system reset
    puc_rst                         // Main system reset
);
);
 
 
// PARAMETERs
// PARAMETERs
//============
//============
parameter           SCLK_DIV  = 0;       // Serial clock divider (Tsclk=Tmclk*(SCLK_DIV+1)*2)
parameter           SCLK_DIV  = 0;       // Serial clock divider (Tsclk=Tmclk*(SCLK_DIV+1)*2)
Line 75... Line 75...
output              sync_n;         // SPI Frame synchronization signal (low active)
output              sync_n;         // SPI Frame synchronization signal (low active)
 
 
// INPUTs
// INPUTs
//=========
//=========
input               mclk;           // Main system clock
input               mclk;           // Main system clock
input         [7:0] per_addr;       // Peripheral address
input        [13:0] per_addr;       // Peripheral address
input        [15:0] per_din;        // Peripheral data input
input        [15:0] per_din;        // Peripheral data input
input               per_en;         // Peripheral enable (high active)
input               per_en;         // Peripheral enable (high active)
input         [1:0] per_we;         // Peripheral write enable (high active)
input         [1:0] per_we;         // Peripheral write enable (high active)
input               puc;            // Main system reset
input               puc_rst;        // Main system reset
 
 
 
 
//=============================================================================
//=============================================================================
// 1)  PARAMETER DECLARATION
// 1)  PARAMETER DECLARATION
//=============================================================================
//=============================================================================
 
 
// Register addresses
// Decoder bit width (defines how many bits are considered for address decoding)
parameter           DAC_VAL    = BASE_ADDR;
parameter              DEC_WD      =  3;
parameter           DAC_STAT   = BASE_ADDR+2;
 
parameter           CNTRL1     = BASE_ADDR+4;
 
parameter           CNTRL2     = BASE_ADDR+6;
 
 
 
 
// Register addresses offset
 
parameter [DEC_WD-1:0] DAC_VAL     = 'h0,
 
                       DAC_STAT    = 'h2,
 
                       CNTRL1      = 'h4,
 
                       CNTRL2      = 'h6;
 
 
 
// Register one-hot decoder utilities
 
parameter              DEC_SZ      =  2**DEC_WD;
 
parameter [DEC_SZ-1:0] BASE_REG    =  {{DEC_SZ-1{1'b0}}, 1'b1};
 
 
// Register one-hot decoder
// Register one-hot decoder
parameter           DAC_VAL_D  = (512'h1 << DAC_VAL);
parameter [DEC_SZ-1:0] DAC_VAL_D   = (BASE_REG << DAC_VAL),
parameter           DAC_STAT_D = (512'h1 << DAC_STAT);
                       DAC_STAT_D  = (BASE_REG << DAC_STAT),
parameter           CNTRL1_D   = (512'h1 << CNTRL1);
                       CNTRL1_D    = (BASE_REG << CNTRL1),
parameter           CNTRL2_D   = (512'h1 << CNTRL2);
                       CNTRL2_D    = (BASE_REG << CNTRL2);
 
 
 
 
//============================================================================
//============================================================================
// 2)  REGISTER DECODER
// 2)  REGISTER DECODER
//============================================================================
//============================================================================
 
 
 
// Local register selection
 
wire              reg_sel   =  per_en & (per_addr[13:DEC_WD-1]==BASE_ADDR[14:DEC_WD]);
 
 
 
// Register local address
 
wire [DEC_WD-1:0] reg_addr  =  {per_addr[DEC_WD-2:0], 1'b0};
 
 
// Register address decode
// Register address decode
reg  [511:0]  reg_dec;
wire [DEC_SZ-1:0] reg_dec   =  (DAC_VAL_D  &  {DEC_SZ{(reg_addr == DAC_VAL )}})  |
always @(per_addr)
                               (DAC_STAT_D &  {DEC_SZ{(reg_addr == DAC_STAT)}})  |
  case ({per_addr,1'b0})
                               (CNTRL1_D   &  {DEC_SZ{(reg_addr == CNTRL1  )}})  |
    DAC_VAL :     reg_dec  =  DAC_VAL_D;
                               (CNTRL2_D   &  {DEC_SZ{(reg_addr == CNTRL2  )}});
    DAC_STAT:     reg_dec  =  DAC_STAT_D;
 
    CNTRL1  :     reg_dec  =  CNTRL1_D;
 
    CNTRL2  :     reg_dec  =  CNTRL2_D;
 
    default :     reg_dec  =  {512{1'b0}};
 
  endcase
 
 
 
// Read/Write probes
// Read/Write probes
wire         reg_write =  |per_we   & per_en;
wire              reg_write =  |per_we & reg_sel;
wire         reg_read  = ~|per_we   & per_en;
wire              reg_read  = ~|per_we & reg_sel;
 
 
// Read/Write vectors
// Read/Write vectors
wire [511:0] reg_wr    = reg_dec & {512{reg_write}};
wire [DEC_SZ-1:0] reg_wr    = reg_dec & {DEC_SZ{reg_write}};
wire [511:0] reg_rd    = reg_dec & {512{reg_read}};
wire [DEC_SZ-1:0] reg_rd    = reg_dec & {DEC_SZ{reg_read}};
 
 
 
 
//============================================================================
//============================================================================
// 3) REGISTERS
// 3) REGISTERS
//============================================================================
//============================================================================
Line 136... Line 143...
reg         dac_pd0;
reg         dac_pd0;
reg         dac_pd1;
reg         dac_pd1;
 
 
wire        dac_val_wr = reg_wr[DAC_VAL];
wire        dac_val_wr = reg_wr[DAC_VAL];
 
 
always @ (posedge mclk or posedge puc)
always @ (posedge mclk or posedge puc_rst)
  if (puc)
  if (puc_rst)
    begin
    begin
       dac_val <= 12'h000;
       dac_val <= 12'h000;
       dac_pd0 <=  1'b0;
       dac_pd0 <=  1'b0;
       dac_pd1 <=  1'b0;
       dac_pd1 <=  1'b0;
    end
    end
Line 157... Line 164...
//------------------   
//------------------   
reg   [3:0] cntrl1;
reg   [3:0] cntrl1;
 
 
wire        cntrl1_wr = reg_wr[CNTRL1];
wire        cntrl1_wr = reg_wr[CNTRL1];
 
 
always @ (posedge mclk or posedge puc)
always @ (posedge mclk or posedge puc_rst)
  if (puc)            cntrl1 <=  4'h0;
  if (puc_rst)        cntrl1 <=  4'h0;
  else if (cntrl1_wr) cntrl1 <=  per_din;
  else if (cntrl1_wr) cntrl1 <=  per_din;
 
 
 
 
// CNTRL2 Register
// CNTRL2 Register
//------------------   
//------------------   
reg   [3:0] cntrl2;
reg   [3:0] cntrl2;
 
 
wire        cntrl2_wr = reg_wr[CNTRL2];
wire        cntrl2_wr = reg_wr[CNTRL2];
 
 
always @ (posedge mclk or posedge puc)
always @ (posedge mclk or posedge puc_rst)
  if (puc)            cntrl2 <=  4'h0;
  if (puc_rst)        cntrl2 <=  4'h0;
  else if (cntrl2_wr) cntrl2 <=  per_din;
  else if (cntrl2_wr) cntrl2 <=  per_din;
 
 
 
 
 
 
//============================================================================
//============================================================================
Line 196... Line 203...
// 5) SPI INTERFACE
// 5) SPI INTERFACE
//============================================================================
//============================================================================
 
 
// SPI Clock divider
// SPI Clock divider
reg [3:0] spi_clk_div;
reg [3:0] spi_clk_div;
always @ (posedge mclk or posedge puc)
always @ (posedge mclk or posedge puc_rst)
  if (puc)                 spi_clk_div <=  SCLK_DIV;
  if (puc_rst)             spi_clk_div <=  SCLK_DIV;
  else if (spi_clk_div==0) spi_clk_div <=  SCLK_DIV;
  else if (spi_clk_div==0) spi_clk_div <=  SCLK_DIV;
  else                     spi_clk_div <=  spi_clk_div-1;
  else                     spi_clk_div <=  spi_clk_div-1;
 
 
// SPI Clock generation
// SPI Clock generation
reg       sclk;
reg       sclk;
always @ (posedge mclk or posedge puc)
always @ (posedge mclk or posedge puc_rst)
  if (puc)                 sclk        <=  1'b0;
  if (puc_rst)             sclk        <=  1'b0;
  else if (spi_clk_div==0) sclk        <=  ~sclk;
  else if (spi_clk_div==0) sclk        <=  ~sclk;
 
 
wire      sclk_re = (spi_clk_div==0) & ~sclk;
wire      sclk_re = (spi_clk_div==0) & ~sclk;
 
 
// SPI Transfer trigger
// SPI Transfer trigger
reg       spi_tfx_trig;
reg       spi_tfx_trig;
always @ (posedge mclk or posedge puc)
always @ (posedge mclk or posedge puc_rst)
  if (puc)                   spi_tfx_trig <= 1'b0;
  if (puc_rst)               spi_tfx_trig <= 1'b0;
  else if (dac_val_wr)       spi_tfx_trig <= 1'b1;
  else if (dac_val_wr)       spi_tfx_trig <= 1'b1;
  else if (sclk_re & sync_n) spi_tfx_trig <= 1'b0;
  else if (sclk_re & sync_n) spi_tfx_trig <= 1'b0;
 
 
wire      spi_tfx_init = spi_tfx_trig & sync_n;
wire      spi_tfx_init = spi_tfx_trig & sync_n;
 
 
// Data counter
// Data counter
reg [3:0] spi_cnt;
reg [3:0] spi_cnt;
wire      spi_cnt_done = (spi_cnt==4'hf);
wire      spi_cnt_done = (spi_cnt==4'hf);
always @ (posedge mclk or posedge puc)
always @ (posedge mclk or posedge puc_rst)
  if (puc)                   spi_cnt <=  4'hf;
  if (puc_rst)               spi_cnt <=  4'hf;
  else if (sclk_re)
  else if (sclk_re)
    if (spi_tfx_init)        spi_cnt <=  4'he;
    if (spi_tfx_init)        spi_cnt <=  4'he;
    else if (~spi_cnt_done)  spi_cnt <=  spi_cnt-1;
    else if (~spi_cnt_done)  spi_cnt <=  spi_cnt-1;
 
 
 
 
// Frame synchronization signal (low active)
// Frame synchronization signal (low active)
reg sync_n;
reg sync_n;
always @ (posedge mclk or posedge puc)
always @ (posedge mclk or posedge puc_rst)
  if (puc)                   sync_n  <=  1'b1;
  if (puc_rst)               sync_n  <=  1'b1;
  else if (sclk_re)
  else if (sclk_re)
    if (spi_tfx_init)        sync_n  <=  1'b0;
    if (spi_tfx_init)        sync_n  <=  1'b0;
    else if (spi_cnt_done)   sync_n  <=  1'b1;
    else if (spi_cnt_done)   sync_n  <=  1'b1;
 
 
 
 
// Value to be shifted_out
// Value to be shifted_out
reg  [15:0] dac_shifter;
reg  [15:0] dac_shifter;
always @ (posedge mclk or posedge puc)
always @ (posedge mclk or posedge puc_rst)
  if (puc)            dac_shifter <=  16'h000;
  if (puc_rst)        dac_shifter <=  16'h000;
  else if (sclk_re)
  else if (sclk_re)
    if (spi_tfx_init) dac_shifter <=  {2'b00, dac_pd1, dac_pd0, dac_val[11:0]};
    if (spi_tfx_init) dac_shifter <=  {2'b00, dac_pd1, dac_pd0, dac_val[11:0]};
    else              dac_shifter <=  {dac_shifter[14:0], 1'b0};
    else              dac_shifter <=  {dac_shifter[14:0], 1'b0};
 
 
assign din = dac_shifter[15];
assign din = dac_shifter[15];

powered by: WebSVN 2.1.0

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