1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 // png2rgb.cpp : Defines the entry point for the console application.
79 //
80 #ifdef MSOS_TYPE_LINUX_KERNEL
81 #include <linux/module.h>
82 #include <linux/kernel.h>
83 #include <linux/time.h>
84 #include <linux/unistd.h>
85 #else
86 #include <stdio.h>
87 #include <stdlib.h>
88 #include <unistd.h>
89 #endif
90 #include "MsCommon.h"
91 #include "png.h"
92 #include "gpd_reg.h"
93 #include "drvgpd.h"
94 #include "mdrvgpd.h"
95 #include "gpd.h"
96 #include "MsOS.h"
97 #ifdef CONFIG_MSTAR_CLKM
98 #ifdef MSOS_TYPE_LINUX_KERNEL
99 #include <linux/clkm.h>
100 #else
101 #include "drvCLKM.h"
102 #endif
103 #endif
104 //#include <semihost_io.h>
105
106 #define PRINT_GPD_DECODE_TIME TRUE
107 #define PNG_DECODE_TIMEOUT 3000
108
109 static my_png_buffer mybuff;
110 static my_png_buffer *my_buff=&mybuff;
111
112 //struct png_struct_def pngstruct;
113 //struct png_info_struct infostruct;
114
115 //MS_U8 length_addr[4];
116 //MS_U8 type_addr[4];
117 static MS_U32 this_ichk_start;
118 //MS_U32 next_ichk_start;
119 //MS_U32 this_ichk_end;
120 static MS_U32 this_ichk_len;
121 static MS_U32 next_ichk_len;
122 //MS_U32 this_read_addr;
123 //MS_U32 next_read_addr;
124 //MS_U32 addr_count;
125 static MS_U8 no_ichk;
126 static MS_U8 last_ichk;
127 //MS_U8 no_fragment;
128 //MS_U8 set;
129 static MS_U8 read_num = 0;
130 extern MS_U32 g_gpd_set_access_region;
131 extern MS_VIRT g_gpd_clock;
132
133
134 //MS_U32 ichk_start_addr[350];
135 //MS_U32 ichk_len[350];
136 //MS_U32 ichk_num=0;
137 static MS_U32 iccp_en=0;
138 //MS_U32 ichk_count=0;
139
140 static char *IHDR="IHDR";
141 static char *IDAT="IDAT";
142 static char *PLTE="PLTE";
143 static char *tRNS="tRNS";
144
145 static gpd_addr_info * buf_addr;
146 static PngInfo info;
147 static PngInfop infoptr=&info;
148
149 static MS_U32 bend;
150
151 extern MS_U32 ZEXPORT gpdinflateReset(z_streamp strm);
152 MS_U16 show_fifo(MS_U32 n);
153
154
PNG_GET_MS_U32REG_Twice(MS_U32 index)155 MS_U32 PNG_GET_MS_U32REG_Twice(MS_U32 index)
156 {
157 MS_U32 u32Reg1, u32Reg2;
158 while(1)
159 {
160 u32Reg1 = GPD_GET_MS_U32REG(index);
161 u32Reg2 = GPD_GET_MS_U32REG(index);
162 if(u32Reg1 == u32Reg2)
163 {
164 return u32Reg1;
165 }
166 }
167 }
168
169
170
PNG_Get_reg_iofifo_state(void)171 void PNG_Get_reg_iofifo_state(void)
172 {
173 MS_U32 _reg_iofifo_state = PNG_GET_MS_U32REG_Twice(reg_iofifo_state);
174
175 console_printf("ofifo_wr_cs[2:0] = 0x%tx \n", (ptrdiff_t)_reg_iofifo_state&0x7);
176 console_printf("ofifo_rd_cs[2:0] = 0x%tx \n", (ptrdiff_t)(_reg_iofifo_state>>3)&0x7);
177 console_printf("ififo_eco_rd[2:0] = 0x%tx \n", (ptrdiff_t)(_reg_iofifo_state>>6)&0x7);
178 console_printf("ififo_eco_wr = 0x%tx \n", (ptrdiff_t)(_reg_iofifo_state>>9)&0x1);
179 }
180
181
PNG_Get_reg_png_state(void)182 void PNG_Get_reg_png_state(void)
183 {
184 MS_U32 _reg_png_state = PNG_GET_MS_U32REG_Twice(reg_png_state);
185
186 console_printf("rw_st[2:0] = 0x%tx \n", (ptrdiff_t)_reg_png_state&0x7);
187 console_printf("decom_st[2:0] = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>3)&0x7);
188 console_printf("fifo_empty = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>6)&0x1);
189 console_printf("decom_rdy = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>7)&0x1);
190 console_printf("deflt_ack_ufifo0 = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>8)&0x1);
191 console_printf("deflt_st[1:0] = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>9)&0x3);
192 console_printf("flg1 = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>11)&0x1);
193 console_printf("flg0 = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>12)&0x1);
194 console_printf("descan_ack_ufifo1 = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>13)&0x1);
195 console_printf("deflt_rdy = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>14)&0x1);
196 console_printf("deflt_ack = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>15)&0x1);
197 console_printf("decom_rdy_ufifo0 = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>16)&0x1);
198 console_printf("descan_st[3:0] = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>17)&0xf);
199 console_printf("ofifo_wrdy = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>21)&0x1);
200 console_printf("descan_rdy = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>22)&0x1);
201 console_printf("descan_ack_a1t = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>23)&0x1);
202 console_printf("deflt_rdy = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>24)&0x1);
203 console_printf("fifo1_empty = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>25)&0x1);
204 console_printf("fifo0_empty = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>26)&0x1);
205 console_printf("reg_gif_local_tbl = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>27)&0x1);
206 console_printf("flt_psram_full|lz_psram_full = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>28)&0x1);
207 console_printf("gpd_time_out = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>29)&0x1);
208 console_printf("ofifo_empty = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>30)&0x1);
209 console_printf("err_flg = 0x%tx \n", (ptrdiff_t)(_reg_png_state>>31)&0x1);
210 }
211
PNG_Get_DebugMux1(void)212 void PNG_Get_DebugMux1(void)
213 {
214 GPD_SET_MS_U32REG(reg_debug_mux, 1);
215 MS_U32 _reg_gpd_debug = PNG_GET_MS_U32REG_Twice(reg_gpd_debug);
216
217 console_printf ("rw_st[2:0] = 0x%tx \n", (ptrdiff_t)_reg_gpd_debug&0x7);
218 console_printf ("decom_st[2:0] = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>3)&0x7);
219 console_printf ("fifo_empty = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>6)&0x1);
220 console_printf ("decom_rdy = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>7)&0x1);
221 console_printf ("deflt_ack_ufifo0 = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>8)&0x1);
222 console_printf ("deflt_st[1:0] = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>9)&0x3);
223 console_printf ("flg1 = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>11)&0x1);
224 console_printf ("flg0 = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>12)&0x1);
225 console_printf ("descan_ack_ufifo1 = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>13)&0x1);
226 console_printf ("deflt_rdy = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>14)&0x1);
227 console_printf ("deflt_ack = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>15)&0x1);
228 console_printf ("decom_rdy_ufifo0 = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>16)&0x1);
229 console_printf ("descan_st[3:0] = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>17)&0xf);
230 console_printf ("ofifo_wrdy = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>21)&0x1);
231 console_printf ("descan_rdy = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>22)&0x1);
232 console_printf ("descan_ack_a1t = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>23)&0x1);
233 }
234
PNG_Get_DebugMux2(void)235 void PNG_Get_DebugMux2(void)
236 {
237 GPD_SET_MS_U32REG(reg_debug_mux, 2);
238 MS_U32 _reg_gpd_debug = PNG_GET_MS_U32REG_Twice(reg_gpd_debug);
239
240 console_printf ("deflt_rdy = 0x%tx \n", (ptrdiff_t)_reg_gpd_debug&0x1);
241 console_printf ("fifo1_empty = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>1)&0x1);
242 console_printf ("fifo0_empty = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>2)&0x1);
243 console_printf ("reg_gif_local_tbl = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>3)&0x1);
244 console_printf ("flt_psram_full|lz_psram_full = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>4)&0x1);
245 console_printf ("gpd_time_out = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>5)&0x1);
246 console_printf ("ofifo_empty = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>6)&0x1);
247 console_printf ("err_flg = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>7)&0x1);
248 console_printf ("gif_cs[12:0] = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>8)&0x1FFF);
249 console_printf ("gif_err = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>21)&0x1);
250 }
251
PNG_Get_DebugMux3(void)252 void PNG_Get_DebugMux3(void)
253 {
254 GPD_SET_MS_U32REG(reg_debug_mux, 3);
255 MS_U32 _reg_gpd_debug = PNG_GET_MS_U32REG_Twice(reg_gpd_debug);
256
257 console_printf ("wr_st = 0x%tx \n", (ptrdiff_t)_reg_gpd_debug&0x1);
258 console_printf ("gnt[5:0] = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>1)&0x3F);
259 console_printf ("rw_gnt[5:0] = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>7)&0x3F);
260 console_printf ("pg2ar_rdrq_rdy = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>13)&0x1);
261 console_printf ("pg2ar_wtrq_rdy = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>14)&0x1);
262 console_printf ("cc2ar_rdrq_rdy = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>15)&0x1);
263 console_printf ("cc2ar_wtrq_rdy = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>16)&0x1);
264 console_printf ("zc2ar_rdrq_rdy = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>17)&0x1);
265 console_printf ("zc2ar_wtrq_rdy = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>18)&0x1);
266 console_printf ("pg2ar_rdrq_pgend = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>19)&0x1);
267 console_printf ("pg2ar_wtrq_pgend = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>20)&0x1);
268 console_printf ("cc2ar_rdrq_pgend = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>21)&0x1);
269 console_printf ("cc2ar_wtrq_pgend = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>22)&0x1);
270 console_printf ("zc2ar_rdrq_pgend = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>23)&0x1);
271
272 }
273
PNG_Get_DebugMux4(void)274 void PNG_Get_DebugMux4(void)
275 {
276 GPD_SET_MS_U32REG(reg_debug_mux, 4);
277 MS_U32 _reg_gpd_debug = PNG_GET_MS_U32REG_Twice(reg_gpd_debug);
278
279 console_printf ("rdq_sram_full = 0x%tx \n", (ptrdiff_t)_reg_gpd_debug&0x1);
280 console_printf ("cmd_sram_full = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>1)&0x1);
281 console_printf ("data_sram_full = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>2)&0x1);
282 console_printf ("rdq_sram_empty = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>3)&0x1);
283 console_printf ("cmd_sram_empty = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>4)&0x1);
284 console_printf ("data_sram_empty = 0x%tx \n", (ptrdiff_t)(_reg_gpd_debug>>5)&0x1);
285
286 }
287
PNG_Get_DebugMux5(void)288 void PNG_Get_DebugMux5(void)
289 {
290 GPD_SET_MS_U32REG(reg_debug_mux, 5);
291 MS_U32 _reg_gpd_debug = PNG_GET_MS_U32REG_Twice(reg_gpd_debug);
292
293 console_printf ("reg_ififo_radr[27:26] = 0x%tx \n", (ptrdiff_t)_reg_gpd_debug&0x3);
294
295 }
296
297
PNG_Debug_PrintReg(void)298 void PNG_Debug_PrintReg(void)
299 {
300
301 #ifndef READ_BYTE
302 #define READ_BYTE(_reg) (*(volatile MS_U8*)(MS_VIRT)(_reg))
303 #define READ_WORD(_reg) (*(volatile MS_U16*)(MS_VIRT)(_reg))
304 #define READ_LONG(_reg) (*(volatile MS_U32*)(MS_VIRT)(_reg))
305 #define WRITE_BYTE(_reg, _val) { (*((volatile MS_U8*)(MS_VIRT)(_reg))) = (MS_U8)(_val); }
306 #define WRITE_WORD(_reg, _val) { (*((volatile MS_U16*)(MS_VIRT)(_reg))) = (MS_U16)(_val); }
307 #define WRITE_LONG(_reg, _val) { (*((volatile MS_U32*)(MS_VIRT)(_reg))) = (MS_U32)(_val); }
308 #endif
309
310 #define GPD_READ_BYTE(addr) READ_BYTE( (drv_gpd_get_RIU_BASE() + (addr)) )
311 #define GPD_READ_WORD(addr) READ_WORD( (drv_gpd_get_RIU_BASE() + (addr)) )
312 #define GPD_WRITE_BYTE(addr, val) WRITE_BYTE( (drv_gpd_get_RIU_BASE() + (addr)), (val) )
313 #define GPD_WRITE_WORD(addr, val) WRITE_WORD( (drv_gpd_get_RIU_BASE() + (addr)), (val) )
314
315 #define __HAL_GPD_ReadByte( u32Reg ) GPD_READ_BYTE(((u32Reg) << 1) - ((u32Reg) & 1))
316
317 #define __HAL_GPD_Read2Byte( u32Reg ) (GPD_READ_WORD((u32Reg)<<1))
318
319 MS_U8 u8i;
320 #define GPD_OFFSET(x) ((x)<<1)
321 #define GPD_CHIP_REG_BASE 0x1E00
322 #define GPD_CLKGEN0_BASE 0x00B00
323 #define GPD_CLKGEN1_BASE 0x03300
324 #define GPD_CLKGEN2_BASE 0x00A00
325 #define GPD_MIU0_BASE 0x1200
326 #define GPD_MIU1_BASE 0x0600
327 #define BK_CHIPTOP_GENERAL(x) (GPD_CHIP_REG_BASE+GPD_OFFSET(x))
328 #define BK_CLKGEN0_GENERAL(x) (GPD_CLKGEN0_BASE+GPD_OFFSET(x))
329 #define BK_CLKGEN1_GENERAL(x) (GPD_CLKGEN1_BASE+GPD_OFFSET(x))
330 #define BK_CLKGEN2_GENERAL(x) (GPD_CLKGEN2_BASE+GPD_OFFSET(x))
331 #define BK_MIU0_GENERAL(x) (GPD_MIU0_BASE+GPD_OFFSET(x))
332 #define BK_MIU1_GENERAL(x) (GPD_MIU1_BASE+GPD_OFFSET(x))
333 #define GPD_BASE 0x13E00 //monaco
334 //#define GPD_BASE 0x10E00 //keres
335
336 #define BK_GPD_GENERAL(x) (GPD_BASE+GPD_OFFSET(x))
337
338 console_printf("=======================================================\n");
339 console_printf("MIU0 | 00/08 01/09 02/0A 03/0B 04/0C 05/0D 06/0E 07/0F\n");
340 console_printf("=======================================================\n");
341 for(u8i=0; u8i<0x80; u8i+=8)
342 {
343 console_printf("%02x | %04x %04x %04x %04x %04x %04x %04x %04x \n",u8i,
344 __HAL_GPD_Read2Byte(BK_MIU0_GENERAL(u8i)),
345 __HAL_GPD_Read2Byte(BK_MIU0_GENERAL(u8i+1)),
346 __HAL_GPD_Read2Byte(BK_MIU0_GENERAL(u8i+2)),
347 __HAL_GPD_Read2Byte(BK_MIU0_GENERAL(u8i+3)),
348 __HAL_GPD_Read2Byte(BK_MIU0_GENERAL(u8i+4)),
349 __HAL_GPD_Read2Byte(BK_MIU0_GENERAL(u8i+5)),
350 __HAL_GPD_Read2Byte(BK_MIU0_GENERAL(u8i+6)),
351 __HAL_GPD_Read2Byte(BK_MIU0_GENERAL(u8i+7))
352 );
353 }
354 console_printf("=======================================================\n");
355
356 console_printf("=======================================================\n");
357 console_printf("MIU1 | 00/08 01/09 02/0A 03/0B 04/0C 05/0D 06/0E 07/0F\n");
358 console_printf("=======================================================\n");
359 for(u8i=0; u8i<0x80; u8i+=8)
360 {
361 console_printf("%02x | %04x %04x %04x %04x %04x %04x %04x %04x \n",u8i,
362 __HAL_GPD_Read2Byte(BK_MIU1_GENERAL(u8i)),
363 __HAL_GPD_Read2Byte(BK_MIU1_GENERAL(u8i+1)),
364 __HAL_GPD_Read2Byte(BK_MIU1_GENERAL(u8i+2)),
365 __HAL_GPD_Read2Byte(BK_MIU1_GENERAL(u8i+3)),
366 __HAL_GPD_Read2Byte(BK_MIU1_GENERAL(u8i+4)),
367 __HAL_GPD_Read2Byte(BK_MIU1_GENERAL(u8i+5)),
368 __HAL_GPD_Read2Byte(BK_MIU1_GENERAL(u8i+6)),
369 __HAL_GPD_Read2Byte(BK_MIU1_GENERAL(u8i+7))
370 );
371 }
372 console_printf("=======================================================\n");
373
374 console_printf("=======================================================\n");
375 console_printf("CHIP | 00/08 01/09 02/0A 03/0B 04/0C 05/0D 06/0E 07/0F\n");
376 console_printf("=======================================================\n");
377 for(u8i=0; u8i<0x80; u8i+=8)
378 {
379 console_printf("%02x | %04x %04x %04x %04x %04x %04x %04x %04x \n",u8i,
380 __HAL_GPD_Read2Byte(BK_CHIPTOP_GENERAL(u8i)),
381 __HAL_GPD_Read2Byte(BK_CHIPTOP_GENERAL(u8i+1)),
382 __HAL_GPD_Read2Byte(BK_CHIPTOP_GENERAL(u8i+2)),
383 __HAL_GPD_Read2Byte(BK_CHIPTOP_GENERAL(u8i+3)),
384 __HAL_GPD_Read2Byte(BK_CHIPTOP_GENERAL(u8i+4)),
385 __HAL_GPD_Read2Byte(BK_CHIPTOP_GENERAL(u8i+5)),
386 __HAL_GPD_Read2Byte(BK_CHIPTOP_GENERAL(u8i+6)),
387 __HAL_GPD_Read2Byte(BK_CHIPTOP_GENERAL(u8i+7))
388 );
389 }
390 console_printf("=======================================================\n");
391
392 console_printf("=======================================================\n");
393 console_printf("GEN0 | 00/08 01/09 02/0A 03/0B 04/0C 05/0D 06/0E 07/0F\n");
394 console_printf("=======================================================\n");
395 for(u8i=0; u8i<0x80; u8i+=8)
396 {
397 console_printf("%02x | %04x %04x %04x %04x %04x %04x %04x %04x \n",u8i,
398 __HAL_GPD_Read2Byte(BK_CLKGEN0_GENERAL(u8i)),
399 __HAL_GPD_Read2Byte(BK_CLKGEN0_GENERAL(u8i+1)),
400 __HAL_GPD_Read2Byte(BK_CLKGEN0_GENERAL(u8i+2)),
401 __HAL_GPD_Read2Byte(BK_CLKGEN0_GENERAL(u8i+3)),
402 __HAL_GPD_Read2Byte(BK_CLKGEN0_GENERAL(u8i+4)),
403 __HAL_GPD_Read2Byte(BK_CLKGEN0_GENERAL(u8i+5)),
404 __HAL_GPD_Read2Byte(BK_CLKGEN0_GENERAL(u8i+6)),
405 __HAL_GPD_Read2Byte(BK_CLKGEN0_GENERAL(u8i+7))
406 );
407 }
408 console_printf("=======================================================\n");
409
410 console_printf("=======================================================\n");
411 console_printf("GEN1 | 00/08 01/09 02/0A 03/0B 04/0C 05/0D 06/0E 07/0F\n");
412 console_printf("=======================================================\n");
413 for(u8i=0; u8i<0x80; u8i+=8)
414 {
415 console_printf("%02x | %04x %04x %04x %04x %04x %04x %04x %04x \n",u8i,
416 __HAL_GPD_Read2Byte(BK_CLKGEN1_GENERAL(u8i)),
417 __HAL_GPD_Read2Byte(BK_CLKGEN1_GENERAL(u8i+1)),
418 __HAL_GPD_Read2Byte(BK_CLKGEN1_GENERAL(u8i+2)),
419 __HAL_GPD_Read2Byte(BK_CLKGEN1_GENERAL(u8i+3)),
420 __HAL_GPD_Read2Byte(BK_CLKGEN1_GENERAL(u8i+4)),
421 __HAL_GPD_Read2Byte(BK_CLKGEN1_GENERAL(u8i+5)),
422 __HAL_GPD_Read2Byte(BK_CLKGEN1_GENERAL(u8i+6)),
423 __HAL_GPD_Read2Byte(BK_CLKGEN1_GENERAL(u8i+7))
424 );
425 }
426 console_printf("=======================================================\n");
427
428 console_printf("=======================================================\n");
429 console_printf("GEN2 | 00/08 01/09 02/0A 03/0B 04/0C 05/0D 06/0E 07/0F\n");
430 console_printf("=======================================================\n");
431 for(u8i=0; u8i<0x80; u8i+=8)
432 {
433 console_printf("%02x | %04x %04x %04x %04x %04x %04x %04x %04x \n",u8i,
434 __HAL_GPD_Read2Byte(BK_CLKGEN2_GENERAL(u8i)),
435 __HAL_GPD_Read2Byte(BK_CLKGEN2_GENERAL(u8i+1)),
436 __HAL_GPD_Read2Byte(BK_CLKGEN2_GENERAL(u8i+2)),
437 __HAL_GPD_Read2Byte(BK_CLKGEN2_GENERAL(u8i+3)),
438 __HAL_GPD_Read2Byte(BK_CLKGEN2_GENERAL(u8i+4)),
439 __HAL_GPD_Read2Byte(BK_CLKGEN2_GENERAL(u8i+5)),
440 __HAL_GPD_Read2Byte(BK_CLKGEN2_GENERAL(u8i+6)),
441 __HAL_GPD_Read2Byte(BK_CLKGEN2_GENERAL(u8i+7))
442 );
443 }
444 console_printf("=======================================================\n");
445
446
447 console_printf("=======================================================\n");
448 console_printf("GPD | 00/08 01/09 02/0A 03/0B 04/0C 05/0D 06/0E 07/0F\n");
449 console_printf("=======================================================\n");
450 for(u8i=0; u8i<0x80; u8i+=8)
451 {
452 console_printf("%02x | %04x %04x %04x %04x %04x %04x %04x %04x \n",u8i,
453 __HAL_GPD_Read2Byte(BK_GPD_GENERAL(u8i)),
454 __HAL_GPD_Read2Byte(BK_GPD_GENERAL(u8i+1)),
455 __HAL_GPD_Read2Byte(BK_GPD_GENERAL(u8i+2)),
456 __HAL_GPD_Read2Byte(BK_GPD_GENERAL(u8i+3)),
457 __HAL_GPD_Read2Byte(BK_GPD_GENERAL(u8i+4)),
458 __HAL_GPD_Read2Byte(BK_GPD_GENERAL(u8i+5)),
459 __HAL_GPD_Read2Byte(BK_GPD_GENERAL(u8i+6)),
460 __HAL_GPD_Read2Byte(BK_GPD_GENERAL(u8i+7))
461 );
462 }
463 console_printf("=======================================================\n");
464 // for(u8i=0; u8i<reg_gpd_version; u8i+=1)
465 // {
466 // GPD_GET_MS_U32REG_dbg(u8i);
467 // }
468
469 }
470
PNG_Debug(void)471 void PNG_Debug(void)
472 {
473 GPD_GET_MS_U32REG_dbg(reg_int_status);
474 GPD_GET_MS_U32REG_dbg(reg_frun_cnt);
475 GPD_GET_MS_U32REG_dbg(reg_gpd_read_bits);
476 console_printf("show bits:%x\n",show_fifo(16));
477
478 PNG_Get_reg_iofifo_state();
479 PNG_Get_reg_png_state();
480 PNG_Get_DebugMux1();
481 PNG_Get_DebugMux2();
482 PNG_Get_DebugMux3();
483 PNG_Get_DebugMux4();
484 PNG_Get_DebugMux5();
485
486
487 #if 0
488 console_printf("set reg_debug2_mux = 0\n");
489 GPD_SET_MS_U32REG(reg_debug2_mux, 0);
490 GPD_GET_MS_U32REG_dbg(reg_gpd_debug2);
491
492 console_printf("set reg_debug2_mux = 1\n");
493 GPD_SET_MS_U32REG(reg_debug2_mux, 1);
494 GPD_GET_MS_U32REG_dbg(reg_gpd_debug2);
495 #endif
496
497 #if 0
498 MDrv_GPD_PrintGPDBuf();
499 #endif
500
501 }
502
503
PNG_DumpRegTable(void)504 void PNG_DumpRegTable(void)
505 {
506 MS_U8 u8i;
507 console_printf("=======================================================\n");
508 console_printf("Dump register!!!!!\n");
509 console_printf("=======================================================\n");
510 for(u8i=0; u8i<reg_gpd_debug2; u8i++)
511 {
512 GPD_GET_MS_U32REG_dbg(u8i);
513 }
514 console_printf("=======================================================\n");
515 }
516
get_length(MS_U8 * addr)517 MS_U32 get_length(MS_U8 *addr)
518 {
519
520 return ((*addr)<<24)+
521 ((*(addr+1))<<16)+
522 ((*(addr+2))<<8)+
523 *(addr+3);
524 }
525
get_next_IDAT(void)526 void get_next_IDAT(void)
527 {
528 MS_U8 *addr=my_buff->data+my_buff->data_offset;
529 addr=addr+4; //type
530 this_ichk_len=next_ichk_len;
531
532 this_ichk_start=(MS_U32) (MS_VIRT)addr;
533 addr=addr+this_ichk_len+4;
534 next_ichk_len=get_length(addr);
535 addr=addr+4;
536 if(memcmp(addr,IDAT,2))
537 last_ichk=1;
538 my_buff->data_offset=addr-my_buff->data;
539
540 console_printf("get_next_IDAT: [%tx, %tx, %tx, %tx %tx]\n", (ptrdiff_t)this_ichk_len, (ptrdiff_t)this_ichk_start,
541 (ptrdiff_t)next_ichk_len, (ptrdiff_t)last_ichk, (ptrdiff_t)my_buff->data_offset);
542
543 }
544
545
546
547
548
check_excess_bend(void)549 MS_U32 check_excess_bend(void)
550 {
551 MS_U32 addr;
552
553 addr = drv_gpd_ififo_radr();
554 addr = ((addr>>6)&0x1FFFFFF)<<3;
555 if((addr>(bend&(~DRAMBASE))))
556 {
557 return 1;
558 }
559 return 0;
560 }
561
562
check_engin_idle(void)563 MS_U32 check_engin_idle(void)
564 {
565 MS_U32 dcm_sta;
566 MS_U32 dfl_sta;
567 MS_U32 dsc_sta;
568 MS_U32 data;
569
570 data = drv_gpd_png_state();
571 dcm_sta = ((data>>2)&0x7);
572 dfl_sta = ((data>>8)&0x3);
573 dsc_sta = ((data>>15)&0xF);
574
575 UNUSED(dfl_sta);
576 UNUSED(dsc_sta);
577
578 if(dcm_sta==0x7||dcm_sta==0)
579 {
580 return 1;
581 }
582 return 0;
583 }
584
check_baddr_not_full(void)585 MS_U32 check_baddr_not_full(void)
586 {
587 MS_U32 i=1;
588 while(i)
589 {
590 if (drv_gpd_bsadr_full())
591 return 0;
592
593 i--;
594 }
595 return 1;
596 }
597
set_bsadr(void)598 void set_bsadr(void)
599 {
600 if(!no_ichk)
601 {
602 #ifdef PA
603 this_ichk_start=this_ichk_start-(MS_U32)(MS_VIRT)my_buff->data+buf_addr->u32PA_ReadBufferAddr;
604 #endif
605 if(!last_ichk)
606 {
607 console_printf("@1 drv_gpd_set_bstart_end: (0x%tx, 0x%tx)\n", (ptrdiff_t)this_ichk_start, (ptrdiff_t)(this_ichk_start+this_ichk_len-1));
608 drv_gpd_set_bstart_end(this_ichk_start,this_ichk_start+this_ichk_len-1);
609
610 bend =this_ichk_start+this_ichk_len-1;
611
612 console_printf("bend=%td\n", (ptrdiff_t)bend);
613 get_next_IDAT();
614
615 }
616 else
617 {
618 console_printf("@2 drv_gpd_set_bstart_end: (0x%tx, 0x%tx)\n", (ptrdiff_t)this_ichk_start, (ptrdiff_t)(this_ichk_start+this_ichk_len-1+32));
619 drv_gpd_set_bstart_end(this_ichk_start,this_ichk_start+this_ichk_len-1+32);
620
621 bend = this_ichk_start+this_ichk_len-1+32;
622
623 no_ichk=1;
624 }
625 }
626 }
627
read_fifo(MS_U32 n)628 MS_U16 read_fifo(MS_U32 n)
629 {
630 read_num += n;
631
632 MS_U32 u32Time=MsOS_GetSystemTime();
633
634 while (drv_gpd_ififo_empty())
635 {
636
637 if(check_baddr_not_full())
638 set_bsadr();
639 if((MsOS_GetSystemTime() - u32Time) >= PNG_DECODE_TIMEOUT)
640 {
641 GPD_DRV_ERROR("read_fifo Timeout!!!\n");
642 return 0;
643 }
644 MsOS_DelayTaskUs(10);
645
646 }
647 return read_bits_reg(n);
648 }
649
show_fifo(MS_U32 n)650 MS_U16 show_fifo(MS_U32 n)
651 {
652 MS_U32 u32Time=MsOS_GetSystemTime();
653 while(drv_gpd_ififo_empty())
654 {
655
656 if(check_baddr_not_full())
657 set_bsadr();
658
659 if((MsOS_GetSystemTime() - u32Time) >= PNG_DECODE_TIMEOUT)
660 {
661 GPD_DRV_ERROR("show_fifo Timeout!!!\n");
662 return 0;
663 }
664 MsOS_DelayTaskUs(10);
665
666 }
667 return show_bits_reg(n);
668 }
669
handle_IHDR(MS_U8 * addr)670 void handle_IHDR(MS_U8 *addr)
671 {
672
673 infoptr->png_width = ((*addr)<<24)+
674 ((*(addr+1))<<16)+
675 ((*(addr+2))<<8)+
676 *(addr+3);
677 infoptr->png_height = ((*(addr+4))<<24)+
678 ((*(addr+5))<<16)+
679 ((*(addr+6))<<8)+
680 *(addr+7);
681 infoptr->bps = *(addr+8);
682 infoptr->color_type = *(addr+9);
683 infoptr->compression = *(addr+10);
684 infoptr->filter = *(addr+11);
685 infoptr->interlace = *(addr+12);
686
687 switch (infoptr->color_type)
688 {
689 case PNG_COLOR_TYPE_GRAY:
690
691 case PNG_COLOR_TYPE_PALETTE:
692 infoptr->bpp =infoptr->bps* 1;
693 break;
694
695 case PNG_COLOR_TYPE_RGB:
696 infoptr->bpp=infoptr->bps* 3;
697 break;
698
699 case PNG_COLOR_TYPE_GRAY_ALPHA:
700 infoptr->bpp=infoptr->bps* 2;
701 break;
702
703 case PNG_COLOR_TYPE_RGB_ALPHA:
704 infoptr->bpp=infoptr->bps* 4;
705 break;
706 }
707
708 }
709
handle_PLTE(MS_U8 * addr,MS_U32 length)710 void handle_PLTE(MS_U8 *addr,MS_U32 length)
711 {
712
713 infoptr->palette=addr;
714 infoptr->palette_num=length/3;
715
716 }
717
handle_tRNS(MS_U8 * addr,MS_U32 length)718 void handle_tRNS(MS_U8 *addr,MS_U32 length)
719 {
720
721 infoptr->trans=addr;
722 infoptr->num_trans=length;
723 infoptr->trns_en=1;
724
725 }
726
handle_first_IDAT(MS_U8 ** addr,MS_U32 length)727 void handle_first_IDAT(MS_U8 **addr,MS_U32 length)
728 {
729 *addr=*addr+4; //type
730 this_ichk_len=length;
731 this_ichk_start=(MS_U32)(MS_VIRT)(*addr);
732 *addr=*addr+length+4;
733 next_ichk_len=get_length(*addr);
734 *addr=*addr+4;
735 if(memcmp(*addr,IDAT,2))
736 last_ichk=1;
737 }
738
parse_header(void)739 void parse_header(void)
740 {
741 MS_U32 length;
742 MS_U8 *cur_addr;
743 my_png_buffer *png_buff = my_buff;
744
745 cur_addr = png_buff->data + png_buff->data_offset;
746 cur_addr += 8; //signature
747 MS_U32 u32Time=MsOS_GetSystemTime();
748
749 while(1)
750 {
751 length = get_length(cur_addr);
752 cur_addr += 4; //length
753
754 if (!memcmp(cur_addr,IHDR, 2))
755 {
756 cur_addr += 4; //type
757 handle_IHDR(cur_addr);
758 cur_addr += length; //data
759 }
760 else if(!memcmp(cur_addr,PLTE, 2))
761 {
762 cur_addr+=4; //type
763 handle_PLTE(cur_addr,length);
764 cur_addr+=length; //data
765 }
766 else if(!memcmp(cur_addr,tRNS, 2))
767 {
768 cur_addr+=4; //type
769 handle_tRNS(cur_addr,length);
770 cur_addr+=length; //data
771 }
772 else if(!memcmp(cur_addr,IDAT, 2))
773 {
774
775 handle_first_IDAT(&cur_addr,length);
776 break;
777 }
778 else
779 {
780 cur_addr+=4; //type
781 cur_addr+=length; //data
782 }
783 cur_addr+=4; //crc
784
785 if((MsOS_GetSystemTime() - u32Time) >= PNG_DECODE_TIMEOUT)
786 {
787 GPD_DRV_ERROR("parse_header Timeout!!!\n");
788 break;
789 }
790 MsOS_DelayTaskUs(10);
791 }
792 png_buff->data_offset=cur_addr-png_buff->data;
793 }
794
795 MS_U32 blk_cnt = 0;
796 MS_U32 starttime;
797 MS_U32 checkfulltime;
798 MS_U32 bsaddrtime;
799 MS_U32 totaltime = 0;
800 MS_U32 donetime;
801 MS_U32 gotime;
802 MS_U32 timetable[1];
803
verifyBitstream3(MS_PHY u32PA,MS_U32 u32Size)804 void verifyBitstream3(MS_PHY u32PA, MS_U32 u32Size)
805 {
806 MS_U32 i = 0;
807 MS_VIRT u32VA;
808 if (FALSE == drv_gpd_get_cacheable())
809 {
810 u32VA = MsOS_PA2KSEG1(u32PA);
811 }
812 else
813 {
814 u32VA = MsOS_PA2KSEG0(u32PA);
815 }
816
817 console_printf("PA:0x%tx, VA:0x%tx, Size:0x%tx\n", (ptrdiff_t)u32PA, (ptrdiff_t)u32VA, (ptrdiff_t)u32Size);
818 drv_gpd_set_bstart_end(u32PA, u32PA+u32Size - 1+8);
819
820 for (i = 0; i < 4; i++)
821 read_bits_reg(16);
822
823 console_printf("printf read buffer start===================\n");
824 for(i=0; i<u32Size/16; i++)
825 {
826 console_printf("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x \n",
827 *(((MS_U8*)u32VA) + i*16+0),
828 *(((MS_U8*)u32VA) + i*16+1),
829 *(((MS_U8*)u32VA) + i*16+2),
830 *(((MS_U8*)u32VA) + i*16+3),
831 *(((MS_U8*)u32VA) + i*16+4),
832 *(((MS_U8*)u32VA) + i*16+5),
833 *(((MS_U8*)u32VA) + i*16+6),
834 *(((MS_U8*)u32VA) + i*16+7),
835 *(((MS_U8*)u32VA) + i*16+8),
836 *(((MS_U8*)u32VA) + i*16+9),
837 *(((MS_U8*)u32VA) + i*16+10),
838 *(((MS_U8*)u32VA) + i*16+11),
839 *(((MS_U8*)u32VA) + i*16+12),
840 *(((MS_U8*)u32VA) + i*16+13),
841 *(((MS_U8*)u32VA) + i*16+14),
842 *(((MS_U8*)u32VA) + i*16+15)
843 );
844 }
845 console_printf("printf read buffer end===================\n");
846
847 console_printf("printf fifo start===================\n");
848 for(i=0; i<u32Size/16; i++)
849 {
850 console_printf("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x \n",
851 read_bits_reg(8),
852 read_bits_reg(8),
853 read_bits_reg(8),
854 read_bits_reg(8),
855 read_bits_reg(8),
856 read_bits_reg(8),
857 read_bits_reg(8),
858 read_bits_reg(8),
859 read_bits_reg(8),
860 read_bits_reg(8),
861 read_bits_reg(8),
862 read_bits_reg(8),
863 read_bits_reg(8),
864 read_bits_reg(8),
865 read_bits_reg(8),
866 read_bits_reg(8)
867 );
868 }
869 console_printf("printf fifo end===================\n");
870
871 }
872
VerifyBitstream2(void)873 void VerifyBitstream2(void)
874 {
875 MS_U32 i = 0;
876
877 console_printf("Verify Bitstream start(PA):%tx length:%tx\n", (ptrdiff_t)buf_addr->u32PA_ReadBufferAddr, (ptrdiff_t)buf_addr->u32ReadBufferSize);
878 console_printf("Verify Bitstream start(VA):[%tx]\n", (ptrdiff_t)buf_addr->u32VA_ReadBufferAddr);
879 console_printf("Verify Bitstream start(VA2PA):[%tx]\n", (ptrdiff_t)MsOS_VA2PA(buf_addr->u32VA_ReadBufferAddr));
880
881 MsOS_FlushMemory();
882 console_printf("Flush~~\n");
883
884 console_printf("READBITBASE = 0x%tx\n", (ptrdiff_t)READBITBASE);
885
886 drv_gpd_set_bstart_end(buf_addr->u32PA_ReadBufferAddr, buf_addr->u32PA_ReadBufferAddr+buf_addr->u32ReadBufferSize - 1 + 32);
887
888 for (i = 0; i < 4; i++)
889 read_bits_reg(16);
890
891 console_printf("printf read buffer start===================\n");
892 for(i=0; i<80; i++)
893 {
894 console_printf("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x \n",
895 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+0),
896 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+1),
897 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+2),
898 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+3),
899 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+4),
900 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+5),
901 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+6),
902 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+7),
903 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+8),
904 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+9),
905 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+10),
906 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+11),
907 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+12),
908 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+13),
909 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+14),
910 *(((MS_U8*)buf_addr->u32VA_ReadBufferAddr) + i*16+15)
911 );
912 }
913 console_printf("printf read buffer end===================\n");
914
915 console_printf("printf fifo start===================\n");
916 for(i=0; i<80; i++)
917 {
918 console_printf("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x \n",
919 read_bits_reg(8),
920 read_bits_reg(8),
921 read_bits_reg(8),
922 read_bits_reg(8),
923 read_bits_reg(8),
924 read_bits_reg(8),
925 read_bits_reg(8),
926 read_bits_reg(8),
927 read_bits_reg(8),
928 read_bits_reg(8),
929 read_bits_reg(8),
930 read_bits_reg(8),
931 read_bits_reg(8),
932 read_bits_reg(8),
933 read_bits_reg(8),
934 read_bits_reg(8)
935 );
936 }
937 console_printf("printf fifo end===================\n");
938
939 PNG_Debug_PrintReg();
940
941 }
942
VerifyBitstream(void)943 MS_U32 VerifyBitstream(void)
944 {
945
946 MS_U32 i = 0;
947
948 console_printf("Verify Bitstream start:%tx length:%tx\n", (ptrdiff_t)buf_addr->u32PA_ReadBufferAddr, (ptrdiff_t)buf_addr->u32ReadBufferSize);
949
950 drv_gpd_set_bstart_end(buf_addr->u32PA_ReadBufferAddr, buf_addr->u32PA_ReadBufferAddr+buf_addr->u32ReadBufferSize - 1 + 32);
951
952 for (i = 0; i < 4; i++)
953 read_bits_reg(16);
954
955 for (i = 0; i < buf_addr->u32ReadBufferSize; i++)
956 {
957 if (*(((MS_U8*)((MS_VIRT)buf_addr->u32VA_ReadBufferAddr)) + i) != read_bits_reg(8))
958 {
959 return 1;
960 }
961 console_printf(".");
962 }
963
964 return 0;
965
966 }
967
968
969
PngProcess(void * ptr,MS_U32 ocolor,MS_U32 mode,void * roi)970 PngInfop PngProcess(void *ptr, MS_U32 ocolor, MS_U32 mode, void *roi)
971 {
972
973 //K2 default setting
974 MS_U8 gpd_hipri = 0x15;
975 MS_U32 i, loop = 0;
976 MS_U32 free_count = (1 << 26) - 1;
977 MS_U32 pitch;
978 MS_U32 interesting_width;
979 MS_U8 timeout = 0;
980 MS_U32 status = 0;
981 MS_U8 default_alpha = 255;
982 MS_U8 png_sca = 0;
983 MS_U8 gpd_pgend = 0;
984 MS_U16 png_trns_r = 0;
985 MS_U16 png_trns_g = 0;
986 MS_U16 png_trns_b = 0;
987 MS_U8 *streambuf;
988 MS_U32 framebuf;
989 MS_U32 pixelbytes = 0;
990 MS_U32 frame_size = 0;
991 MS_U32 scaling_en, scaling_mode;
992 MS_U32 nBlkNumber = 0;
993 //MS_U32 iofifo_state = 0;
994 gpd_roi_info *roi_ptr;
995 buf_addr=(gpd_addr_info*)ptr;
996 roi_ptr=(gpd_roi_info*)roi;
997 streambuf=(MS_U8*)(MS_VIRT)buf_addr->u32VA_ReadBufferAddr;
998 framebuf=(MS_U32)(MS_VIRT)buf_addr->u32PA_WriteBufferAddr;
999
1000
1001 #ifdef GPD_CLOCK_PATCH
1002
1003 hal_gpd_enable_clock();
1004
1005 #else
1006
1007 if (TRUE == g_gpd_set_access_region)
1008 {
1009 #ifdef CONFIG_MSTAR_CLKM
1010 drv_gpd_power_on();
1011 #else
1012 *((volatile MS_U32 *)(MS_VIRT)g_gpd_clock) = 0;
1013 #endif
1014 }
1015
1016 #endif
1017
1018
1019 drv_gpd_png_en();
1020
1021 drv_gpd_Init();
1022
1023 console_printf("gpd sw reset\n");
1024
1025
1026
1027 #if 0
1028
1029 if (VerifyBitstream())
1030 console_printf("Verify fail\n");
1031 else
1032 console_printf("Verify success\n");
1033
1034 #elif 0
1035 VerifyBitstream2();
1036 PNG_Debug();
1037 while(1);
1038 #endif
1039
1040 no_ichk = 0;
1041 last_ichk = 0;
1042 blk_cnt = 0;
1043 totaltime = 0;
1044
1045 my_buff->data = streambuf;
1046 my_buff->data_offset = 0;
1047
1048 memset((void*)&info, 0, sizeof(info));
1049 gpdinflateInit(&infoptr->zstream);
1050 parse_header();
1051
1052 #if 0
1053 if (infoptr->png_height > 2048 || infoptr->png_width > 2048)
1054 {
1055 console_printf("height or width exceeds 2048\n");
1056 return 0;
1057 }
1058 #endif
1059
1060 switch (ocolor)
1061 {
1062 case ARGB8888:
1063 pixelbytes = 4; break;
1064 case RGB565:
1065 case YUV422:
1066 case YVYU422:
1067 case GRAY_ALPHA:
1068 pixelbytes = 2; break;
1069 case GRAY:
1070 pixelbytes = 1; break;
1071 default:
1072 console_printf("Unsupported output color %td\n", (ptrdiff_t)ocolor);
1073 return NULL;
1074 }
1075
1076 /* Check buffer size */
1077 if (mode == 2)
1078 frame_size = ((roi_ptr->width* pixelbytes + 7) & ~7) * (roi_ptr->height);
1079 else if (mode == 0)
1080 frame_size = ((infoptr->png_width * pixelbytes + 7) & ~7) * infoptr->png_height;
1081
1082 if((drv_gpd_get_scaling_mode() & 0x1) && mode==0)
1083 {
1084 switch(drv_gpd_get_scaling_mode() >> 1)
1085 {
1086 case 0:
1087 frame_size/=4;
1088 break;
1089 case 1:
1090 frame_size/=16;
1091 break;
1092 case 2:
1093 frame_size/=64;
1094 break;
1095 case 3:
1096 frame_size/=256;
1097 break;
1098 default:
1099 break;
1100 }
1101 }
1102
1103 if (frame_size > buf_addr->u32WriteBufferSize)
1104 {
1105 console_printf("Frame buffer is too small\n");
1106 return NULL;
1107 }
1108
1109 switch(infoptr->bps)
1110 {
1111 case 1:
1112 infoptr->color_depth = 0;
1113 break;
1114 case 2:
1115 infoptr->color_depth = 1;
1116 break;
1117 case 4:
1118 infoptr->color_depth = 2;
1119 break;
1120 case 8:
1121 infoptr->color_depth = 3;
1122 break;
1123 case 16:
1124 infoptr->color_depth = 4;
1125 break;
1126 default:
1127 infoptr->color_depth = 0;
1128 }
1129
1130 if (mode == 1)
1131 return infoptr;
1132
1133
1134 drv_gpd_eco_enable(1);
1135
1136 drv_gpd_set_ocolor(ocolor);
1137
1138
1139
1140
1141 switch(infoptr->color_type)
1142 {
1143 case PNG_COLOR_TYPE_GRAY:
1144 if(infoptr->trns_en)
1145 {
1146 png_trns_r=((*infoptr->trans) << 8) + *(infoptr->trans + 1);
1147 drv_gpd_set_trans(png_trns_r, 0, 0, 1);
1148 }
1149 else
1150 {
1151 drv_gpd_set_trans(0, 0, 0, 0);
1152 }
1153 break;
1154
1155 case PNG_COLOR_TYPE_GRAY_ALPHA:
1156 drv_gpd_set_trans(0, 0, 0, 0);
1157 break;
1158
1159 case PNG_COLOR_TYPE_RGB:
1160 if(infoptr->trns_en)
1161 {
1162 png_trns_r=((*infoptr->trans)<<8)+*(infoptr->trans+1);
1163 png_trns_g=((*(infoptr->trans+2))<<8)+*(infoptr->trans+3);
1164 png_trns_b=((*(infoptr->trans+4))<<8)+*(infoptr->trans+5);
1165 drv_gpd_set_trans(png_trns_r, png_trns_g, png_trns_b, 1);
1166 }
1167 else
1168 {
1169 drv_gpd_set_trans(0, 0, 0, 0);
1170 }
1171 break;
1172
1173 case PNG_COLOR_TYPE_RGB_ALPHA:
1174 drv_gpd_set_trans(0, 0, 0, 0);
1175 break;
1176
1177 case PNG_COLOR_TYPE_PALETTE:
1178 drv_gpd_set_trans(0, 0, 0, 0);
1179 drv_gpd_set_palette(infoptr->palette,infoptr->palette_num,infoptr->trans,infoptr->num_trans);
1180 break;
1181
1182 default:
1183 console_printf("color_type(%d) not implemented.\n",infoptr->color_type);
1184 }
1185
1186 //set free count
1187 drv_gpd_set_frun_cnt(free_count);
1188
1189 if (mode == 2)
1190 {
1191 if (roi_ptr->hstart + roi_ptr->width > infoptr->png_width || roi_ptr->vstart + roi_ptr->height > infoptr->png_height)
1192 {
1193 GPD_DRV_ERROR("Error: ROI exceeds image region\n");
1194 return 0;
1195 }
1196
1197 if (infoptr->interlace)
1198 {
1199 if (roi_ptr->width < 8)
1200 {
1201 GPD_DRV_ERROR("Error: roi width < 8 for interlace PNG\n");
1202 return 0;
1203 }
1204 roi_ptr->hstart &= ~7UL;
1205 roi_ptr->vstart &= ~7UL;
1206 }
1207 interesting_width = roi_ptr->width;
1208 drv_gpd_set_ROI(1, roi_ptr->hstart, roi_ptr->vstart, roi_ptr->width, roi_ptr->height);
1209 }
1210 else
1211 {
1212 interesting_width = infoptr->png_width;
1213 drv_gpd_set_ROI(0, 64, 64, 64, 64);
1214 }
1215
1216 if ((scaling_en = drv_gpd_get_scaling_mode() & 1))
1217 {
1218 scaling_mode = drv_gpd_get_scaling_mode() >> 1;
1219
1220 if (scaling_mode == 0)
1221 interesting_width = (interesting_width + 1) >> 1;
1222 else if (scaling_mode == 1)
1223 interesting_width = (interesting_width + 3) >> 2;
1224 else if (scaling_mode == 2)
1225 interesting_width = (interesting_width + 7) >> 3;
1226 else if (scaling_mode == 3)
1227 interesting_width = (interesting_width + 15) >> 4;
1228 }
1229
1230 //set pitch
1231 #if 1
1232
1233 pitch = (interesting_width * pixelbytes + 7) >> 3;
1234
1235 #else
1236
1237 if (ocolor == ARGB8888)
1238 pitch = (infoptr->png_width + 1) >> 1;
1239 else if (ocolor == GRAY)
1240 pitch = (infoptr->png_width + 7) >> 3;
1241 else
1242 pitch = (infoptr->png_width + 3) >> 2;
1243
1244
1245
1246 #endif
1247
1248
1249 drv_gpd_set_pitch(pitch);
1250
1251 //set height and width
1252 drv_gpd_set_iwidth_height(infoptr->png_width,infoptr->png_height);
1253
1254
1255 console_printf("width = %td, height = %td\n", (ptrdiff_t)infoptr->png_width, (ptrdiff_t)infoptr->png_height);
1256
1257
1258
1259 if (iccp_en)
1260 {
1261 drv_gpd_set_iccp_dtsize(1, 32);
1262
1263 /*
1264 data = (PNG_COLOR_TYPE_RGB_ALPHA << PNG_COLOR_TYPE_SHF) +
1265 (infoptr->interlace << GPD_INTERLACE_SHF) +
1266 (infoptr->color_depth << PNG_COLOR_DEPTH_SHF) +
1267 (infoptr->trns_en << PNG_TRANS_EN_SHF) +
1268 (png_trns_b << PNG_TRANS_B_SHF);
1269 */
1270
1271
1272
1273 drv_gpd_set_type(PNG_COLOR_TYPE_RGB_ALPHA, infoptr->interlace, infoptr->color_depth);
1274
1275 }
1276 else
1277 {
1278 //set only_decom and dtbl_size;
1279 drv_gpd_set_iccp_dtsize(0,32);
1280
1281 /*
1282 data = (infoptr->color_type << PNG_COLOR_TYPE_SHF) +
1283 (infoptr->interlace << GPD_INTERLACE_SHF) +
1284 (infoptr->color_depth << PNG_COLOR_DEPTH_SHF) +
1285 (infoptr->trns_en << PNG_TRANS_EN_SHF) +
1286 (png_trns_b << PNG_TRANS_B_SHF);
1287 */
1288
1289 drv_gpd_set_type(infoptr->color_type, infoptr->interlace, infoptr->color_depth);
1290 }
1291
1292 //set interlace and scanline width and scanline height
1293 if(infoptr->interlace)
1294 {
1295 if (infoptr->png_width >= 2)
1296 png_sca |= (1 << 4);
1297 if (infoptr->png_width >= 3)
1298 png_sca |= (1 << 2);
1299 if (infoptr->png_width >= 5)
1300 png_sca |= (1);
1301 if (infoptr->png_height >= 3)
1302 png_sca |= (1 << 3);
1303 if (infoptr->png_height >= 5)
1304 png_sca |= (1 << 1);
1305
1306 drv_gpd_set_scline_width_interlace(infoptr->png_width, infoptr->bpp);
1307 drv_gpd_set_scline_height_interlace(infoptr->png_height);
1308 }
1309 else
1310 {
1311 drv_gpd_set_scline_width_progressive(infoptr->png_width, infoptr->bpp);
1312 drv_gpd_set_scline_height_progressive(infoptr->png_height);
1313 }
1314
1315 drv_gpd_set_sca_dfa(png_sca, default_alpha);
1316 drv_gpd_set_ltsize(288);
1317
1318 drv_gpd_set_pgend(gpd_pgend);
1319
1320 if (is_stb())
1321 {
1322 //for U01 ECO item
1323 drv_gpd_set_hipri(gpd_hipri);
1324 }
1325
1326 //set istart
1327 drv_gpd_set_istart(framebuf);
1328
1329 for (i = 0; i < 4; i++)
1330 read_fifo(16);
1331
1332
1333
1334 console_printf("Flush done\n");
1335
1336
1337
1338 drv_gpd_set_png_done(0);
1339
1340 #if PRINT_GPD_DECODE_TIME
1341 GPD_DRV_TIME("before set png go @ [%td]ms\n", (ptrdiff_t)MsOS_GetSystemTime());
1342 #endif
1343
1344 drv_gpd_set_png_go();
1345
1346
1347
1348 console_printf("show bits:%x\n",show_fifo(16));
1349
1350
1351 //parse zlib and block header
1352 status = gpdinflate(&infoptr->zstream, 1);
1353
1354
1355 console_printf("inflate ok\n");
1356
1357
1358 if(status == Z_STREAM_ERROR)
1359 {
1360 GPD_DRV_ERROR("block header error\n");
1361 return 0;
1362 }
1363
1364
1365 console_printf("=== block %td ===\n", (ptrdiff_t)(++nBlkNumber));
1366 #if 0
1367 PNG_Get_reg_iofifo_state();
1368 PNG_Get_reg_png_state();
1369 //PNG_Debug();
1370 //PNG_DumpRegTable();
1371 #endif
1372
1373 #if PRINT_GPD_DECODE_TIME
1374 MS_U32 u32StartTime = MsOS_GetSystemTime();
1375 MS_U32 u32TotalTime = 0;
1376 #endif
1377
1378 drv_gpd_set_blk_go();
1379
1380
1381 console_printf("blk go\n");
1382
1383
1384 while(1)
1385 {
1386
1387
1388 if(check_baddr_not_full())
1389 {
1390
1391 set_bsadr();
1392
1393 }
1394
1395 //end of block
1396 if (drv_gpd_png_eob())
1397 {
1398
1399 console_printf("end of block\n");
1400
1401 //last block
1402
1403 if (status == Z_STREAM_END)
1404 {
1405
1406 console_printf("last block\n");
1407
1408 break;
1409 }
1410
1411 if (status == Z_STREAM_ERROR)
1412 {
1413 GPD_DRV_ERROR("block header error\n");
1414 return 0;
1415 }
1416
1417 while (!drv_gpd_png_blk_done())
1418 {
1419
1420 switch (drv_gpd_check_engine())
1421 {
1422 case -1:
1423 loop++;
1424 if (loop > 15)
1425 {
1426 timeout = 1;
1427 #if 0
1428 PNG_Debug();
1429 PNG_DumpRegTable();
1430 #endif
1431 GPD_DRV_ERROR("PNG EOB, error -1\n");
1432 goto END_DECODE;
1433 }
1434 break;
1435
1436 case -2:
1437 loop++;
1438 if (loop > 15)
1439 {
1440 timeout=1;
1441 #if 0
1442 PNG_Debug();
1443 PNG_DumpRegTable();
1444 #endif
1445 GPD_DRV_ERROR("PNG EOB, error -2\n");
1446 goto END_DECODE;
1447 }
1448 break;
1449
1450 case 0:
1451 break;
1452 }
1453 MsOS_DelayTaskUs(10);
1454 }
1455
1456 #if PRINT_GPD_DECODE_TIME
1457 u32TotalTime+=MsOS_GetSystemTime()-u32StartTime;
1458 #endif
1459
1460 console_printf("block done\n");
1461
1462 #if 0
1463 PNG_Debug();
1464 #endif
1465
1466 loop = 0;
1467
1468 gpdinflateReset(&infoptr->zstream);
1469 status = gpdinflate(&infoptr->zstream, 0);
1470
1471
1472 console_printf("inflate ok\n");
1473
1474
1475 //set block_go
1476 console_printf("=== block %td ===\n", (ptrdiff_t)(++nBlkNumber));
1477 #if 0
1478 PNG_Get_reg_iofifo_state();
1479 PNG_Get_reg_png_state();
1480 //PNG_Debug();
1481 //PNG_DumpRegTable();
1482 #endif
1483 drv_gpd_set_blk_go();
1484
1485 #if PRINT_GPD_DECODE_TIME
1486 u32StartTime = MsOS_GetSystemTime();
1487 #endif
1488 console_printf("blk go\n");
1489
1490 }
1491 else
1492 {
1493
1494 switch (drv_gpd_check_engine())
1495 {
1496 case -1:
1497 loop++;
1498 if (loop > 15)
1499 {
1500 timeout = 1;
1501 #if 0
1502 PNG_Debug();
1503 PNG_DumpRegTable();
1504 #endif
1505 GPD_DRV_ERROR("not PNG EOB, error -1\n");
1506 goto END_DECODE;
1507 }
1508 break;
1509
1510 case -2:
1511 loop++;
1512 if (loop > 15)
1513 {
1514 timeout = 1;
1515 #if 0
1516 PNG_Debug();
1517 PNG_DumpRegTable();
1518 #endif
1519 GPD_DRV_ERROR("not PNG EOB, error -2\n");
1520 goto END_DECODE;
1521 }
1522 break;
1523
1524 case 0:
1525 break;
1526 }
1527 MsOS_DelayTaskUs(10);
1528 }
1529 }
1530
1531 END_DECODE:
1532
1533 if (!timeout)
1534 {
1535 while (!drv_gpd_png_blk_done()) MsOS_DelayTaskUs(10);
1536
1537 drv_gpd_set_png_done(1);
1538
1539 #if PRINT_GPD_DECODE_TIME
1540 u32TotalTime+=MsOS_GetSystemTime()-u32StartTime;
1541 GPD_DRV_TIME("end decode @ [%td]ms\n", (ptrdiff_t)MsOS_GetSystemTime());
1542 GPD_DRV_TIME("u32TotalTime=%td\n", (ptrdiff_t)u32TotalTime);
1543 #endif
1544
1545 console_printf("png done\n");
1546
1547
1548 }
1549 else
1550 {
1551
1552 console_printf("Unusual Decode End\n");
1553 drv_gpd_dbg_dump();
1554 return 0;
1555 }
1556
1557 return infoptr;
1558 }
1559
1560