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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [altera_de0_nano_soc/] [rtl/] [verilog/] [opengfx430/] [ogfx_gpu_dma_addr.v] - Blame information for rev 224

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 221 olivier.gi
//----------------------------------------------------------------------------
2
// Copyright (C) 2015 Authors
3
//
4
// This source file may be used and distributed without restriction provided
5
// that this copyright statement is not removed from the file and that any
6
// derivative work contains the original copyright notice and the associated
7
// disclaimer.
8
//
9
// This source file is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU Lesser General Public License as published
11
// by the Free Software Foundation; either version 2.1 of the License, or
12
// (at your option) any later version.
13
//
14
// This source is distributed in the hope that it will be useful, but WITHOUT
15
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
// License for more details.
18
//
19
// You should have received a copy of the GNU Lesser General Public License
20
// along with this source; if not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
//
23
//----------------------------------------------------------------------------
24
//
25
// *File Name: ogfx_gpu_dma_addr.v
26
//
27
// *Module Description:
28
//                      Compute next Video-Ram address
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34
// $Rev$
35
// $LastChangedBy$
36
// $LastChangedDate$
37
//----------------------------------------------------------------------------
38
`ifdef OGFX_NO_INCLUDE
39
`else
40
`include "openGFX430_defines.v"
41
`endif
42
 
43
module  ogfx_gpu_dma_addr (
44
 
45
// OUTPUTs
46
    vid_ram_addr_nxt_o,                       // Next Video-RAM address
47
 
48
// INPUTs
49
    mclk,                                     // Main system clock
50
    puc_rst,                                  // Main system reset
51
    display_width_i,                          // Display width
52
    gfx_mode_1_bpp_i,                         // Graphic mode  1 bpp resolution
53
    gfx_mode_2_bpp_i,                         // Graphic mode  2 bpp resolution
54
    gfx_mode_4_bpp_i,                         // Graphic mode  4 bpp resolution
55
    gfx_mode_8_bpp_i,                         // Graphic mode  8 bpp resolution
56
    gfx_mode_16_bpp_i,                        // Graphic mode 16 bpp resolution
57
    vid_ram_addr_i,                           // Video-RAM address
58
    vid_ram_addr_init_i,                      // Video-RAM address initialization
59
    vid_ram_addr_step_i,                      // Video-RAM address step
60
    vid_ram_width_i,                          // Video-RAM width
61
    vid_ram_win_x_swap_i,                     // Video-RAM X-Swap configuration
62
    vid_ram_win_y_swap_i,                     // Video-RAM Y-Swap configuration
63
    vid_ram_win_cl_swap_i                     // Video-RAM CL-Swap configuration
64
);
65
 
66
// OUTPUTs
67
//=========
68
output   [`APIX_MSB:0] vid_ram_addr_nxt_o;    //  Next Video-RAM address
69
 
70
// INPUTs
71
//=========
72
input                  mclk;                  // Main system clock
73
input                  puc_rst;               // Main system reset
74
input    [`LPIX_MSB:0] display_width_i;       // Display width
75
input                  gfx_mode_1_bpp_i;      // Graphic mode  1 bpp resolution
76
input                  gfx_mode_2_bpp_i;      // Graphic mode  2 bpp resolution
77
input                  gfx_mode_4_bpp_i;      // Graphic mode  4 bpp resolution
78
input                  gfx_mode_8_bpp_i;      // Graphic mode  8 bpp resolution
79
input                  gfx_mode_16_bpp_i;     // Graphic mode 16 bpp resolution
80
input    [`APIX_MSB:0] vid_ram_addr_i;        // Video-RAM address
81
input                  vid_ram_addr_init_i;   // Video-RAM address initialization
82
input                  vid_ram_addr_step_i;   // Video-RAM address step
83
input    [`LPIX_MSB:0] vid_ram_width_i;       // Video-RAM width
84
input                  vid_ram_win_x_swap_i;  // Video-RAM X-Swap configuration
85
input                  vid_ram_win_y_swap_i;  // Video-RAM Y-Swap configuration
86
input                  vid_ram_win_cl_swap_i; // Video-RAM CL-Swap configuration
87
 
88
 
89
//=============================================================================
90
// 1)  COMPUTE NEXT MEMORY ACCESS
91
//=============================================================================
92
reg    [`APIX_MSB:0] vid_ram_line_addr;
93
reg    [`LPIX_MSB:0] vid_ram_column_count;
94
 
95
// Detect when the current line refresh is done
96
wire                 vid_ram_line_done    = vid_ram_addr_step_i & (vid_ram_column_count==(vid_ram_width_i-{{`LPIX_MSB{1'b0}}, 1'b1}));
97
 
98
// Mux between initialization value and display width
99
wire   [`LPIX_MSB:0] vid_ram_length_mux   = vid_ram_addr_init_i ? vid_ram_width_i : display_width_i ;
100
 
101
// Align depending on graphic mode
102
wire [`LPIX_MSB+4:0] vid_ram_length_align =  {`LPIX_MSB+5{gfx_mode_1_bpp_i }} & {4'b0000, vid_ram_length_mux[`LPIX_MSB:0]         } |
103
                                             {`LPIX_MSB+5{gfx_mode_2_bpp_i }} & {3'b000,  vid_ram_length_mux[`LPIX_MSB:0], 1'b0   } |
104
                                             {`LPIX_MSB+5{gfx_mode_4_bpp_i }} & {2'b00,   vid_ram_length_mux[`LPIX_MSB:0], 2'b00  } |
105
                                             {`LPIX_MSB+5{gfx_mode_8_bpp_i }} & {1'b0,    vid_ram_length_mux[`LPIX_MSB:0], 3'b000 } |
106
                                             {`LPIX_MSB+5{gfx_mode_16_bpp_i}} & {         vid_ram_length_mux[`LPIX_MSB:0], 4'b0000} ;
107
 
108
wire   [`APIX_MSB:0] plus_one_val         =  {`APIX_MSB+1{gfx_mode_1_bpp_i }} & {4'b0000, {{`VRAM_MSB{1'b0}}, 1'b1}               } |
109
                                             {`APIX_MSB+1{gfx_mode_2_bpp_i }} & {3'b000,  {{`VRAM_MSB{1'b0}}, 1'b1},       1'b0   } |
110
                                             {`APIX_MSB+1{gfx_mode_4_bpp_i }} & {2'b00,   {{`VRAM_MSB{1'b0}}, 1'b1},       2'b00  } |
111
                                             {`APIX_MSB+1{gfx_mode_8_bpp_i }} & {1'b0,    {{`VRAM_MSB{1'b0}}, 1'b1},       3'b000 } |
112
                                             {`APIX_MSB+1{gfx_mode_16_bpp_i}} & {         {{`VRAM_MSB{1'b0}}, 1'b1},       4'b0000} ;
113
 
114
// Zero extension for LINT cleanup
115
wire [`APIX_MSB*3:0] vid_ram_length_norm  =  {{`APIX_MSB*3-`LPIX_MSB-4{1'b0}}, vid_ram_length_align};
116
 
117
// Select base address for next calculation
118
wire   [`APIX_MSB:0] next_base_addr       =  (vid_ram_addr_init_i | ~vid_ram_line_done) ? vid_ram_addr_i    :
119
                                                                                          vid_ram_line_addr ;
120
// Compute next address
121
wire   [`APIX_MSB:0] next_addr            =   next_base_addr
122
                                            + (vid_ram_length_norm[`APIX_MSB:0] & {`APIX_MSB+1{~vid_ram_addr_init_i ? (~vid_ram_win_y_swap_i &  (vid_ram_win_cl_swap_i ^ vid_ram_line_done)) : 1'b0}})
123
                                            - (vid_ram_length_norm[`APIX_MSB:0] & {`APIX_MSB+1{~vid_ram_addr_init_i ? ( vid_ram_win_y_swap_i &  (vid_ram_win_cl_swap_i ^ vid_ram_line_done)) : 1'b0}})
124
                                            + (plus_one_val                     & {`APIX_MSB+1{~vid_ram_addr_init_i ? (~vid_ram_win_x_swap_i & ~(vid_ram_win_cl_swap_i ^ vid_ram_line_done)) : 1'b0}})
125
                                            - (plus_one_val                     & {`APIX_MSB+1{~vid_ram_addr_init_i ? ( vid_ram_win_x_swap_i & ~(vid_ram_win_cl_swap_i ^ vid_ram_line_done)) : 1'b0}});
126
 
127
wire                 update_line_addr     =   vid_ram_addr_init_i | vid_ram_line_done;
128
wire                 update_pixel_addr    =   update_line_addr    | vid_ram_addr_step_i;
129
 
130
// Start RAM address of currentely refreshed line
131
always @(posedge mclk or posedge puc_rst)
132
  if (puc_rst)               vid_ram_line_addr  <=  {`APIX_MSB+1{1'b0}};
133
  else if (update_line_addr) vid_ram_line_addr  <=  next_addr;
134
 
135
// Current RAM address of the currentely refreshed pixel
136
assign vid_ram_addr_nxt_o = update_pixel_addr ? next_addr : vid_ram_addr_i;
137
 
138
// Count the pixel number in the current line
139
// (used to detec the end of a line)
140
always @(posedge mclk or posedge puc_rst)
141
  if (puc_rst)                   vid_ram_column_count  <=  {`LPIX_MSB+1{1'b0}};
142
  else if (vid_ram_addr_init_i)  vid_ram_column_count  <=  {`LPIX_MSB+1{1'b0}};
143
  else if (vid_ram_line_done)    vid_ram_column_count  <=  {`LPIX_MSB+1{1'b0}};
144
  else if (vid_ram_addr_step_i)  vid_ram_column_count  <=  vid_ram_column_count + {{`LPIX_MSB{1'b0}}, 1'b1};
145
 
146
 
147
endmodule // ogfx_calc_vram_addr
148
 
149
`ifdef OGFX_NO_INCLUDE
150
`else
151
`include "openGFX430_undefines.v"
152
`endif

powered by: WebSVN 2.1.0

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