Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x1000_LCD_DMA_Debug3 'revisited' for cd91c238de and newer
- optional Debug Timings for x1000 LCD DMA (under Debug->View HW Info->Audio)
- NEW: __ost_delay vs udelay used
- (Configurable before Compile <1>,2,3,6 Cyles aka <166ns>, 333ns, 500ns, or 1µS Resolution)
- Fractional Display of the Timing
- Moved Timing Loop Logic away from x1000_LCD_DMA_fix.diff to here.
- Credit ZappBranigan2972 on forums / F. Jacobsen on the Theme Site
- ---
- --- a/firmware/target/mips/ingenic_x1000/debug-x1000.c.orig 2024-01-05 17:13:17.000000000 +0100
- +++ b/firmware/target/mips/ingenic_x1000/debug-x1000.c 2024-01-28 19:06:45.187252886 +0100
- @@ -30,6 +30,7 @@
- #include "clk-x1000.h"
- #include "gpio-x1000.h"
- +#include "lcd-x1000.h"
- static bool dbg_clocks(void)
- {
- @@ -143,6 +143,7 @@
- lcd_putsf(0, 2, "(%d) SWVOL", es9018k2m_present_flag);
- }
- #endif
- + debug_x1000_lcd();
- lcd_update();
- } while(get_action(CONTEXT_STD, HZ) != ACTION_STD_CANCEL);
- --- a/firmware/target/mips/ingenic_x1000/lcd-x1000.h.orig 2023-07-09 09:51:56.000000000 +0200
- +++ b/firmware/target/mips/ingenic_x1000/lcd-x1000.h 2024-01-28 18:57:00.738666050 +0100
- @@ -77,6 +77,26 @@
- size_t dma_wr_cmd_size;
- };
- +#ifndef BOOTLOADER
- +#define LCD_X1000_DEBUG
- +#endif
- +#if defined(LCD_X1000_DEBUG)
- +typedef struct {
- + char str[12];
- + uint32_t cnt;
- + uint32_t avgbusy;
- + uint32_t maxbusy;
- +} LCD_Dbg;
- +
- +#define LCD_X1000_DEBUG_ENTRYS 9
- +#endif
- +extern void debug_x1000_lcd(void);
- +
- +#define LCD_WAIT_MAX (65500 * 6) /* loops max. Wait */
- +
- +/* OST_WAIT: 1 166,6nS, 2 333.33nS, 3 500nS, 6 1µS Resolution */
- +#define OST_WAIT 1 /* (6/1 = 6MHz) 166.6nS Resolution */
- +
- /* Static configuration for the target's LCD, must be defined by target. */
- extern const struct lcd_tgt_config lcd_tgt_config;
- /* Static configuration for the target's LCD, must be defined by target. */
- extern const struct lcd_tgt_config lcd_tgt_config;
- --- a/firmware/target/mips/ingenic_x1000/lcd-x1000.c.orig 2024-07-10 09:00:17.175641885 +0200
- +++ b/firmware/target/mips/ingenic_x1000/lcd-x1000.c 2024-07-10 09:06:46.482963434 +0200
- @@ -75,6 +75,74 @@
- #define lcd_panic_mode \
- UNLIKELY((read_c0_status() & 1) == 0)
- +typedef enum {
- + LCD_SEND0, LCD_SEND1,
- + WAIT_FRAME, SLEEP_FRAME,
- + WAIT_EOF, SLEEP_EOF,
- + WAIT_QD,
- + WAIT_FBCPF, WAIT_FBCPP
- +} Lcd_ID;
- +
- +#if defined(LCD_X1000_DEBUG)
- +LCD_Dbg X1000_LCD_Dbg[LCD_X1000_DEBUG_ENTRYS] = {
- + { "LCD_SEND0 ", 0, 0, 0}, { "LCD_SEND1 ", 0, 0, 0},
- + { "WAIT_FRAME", 0, 0, 0}, { "SLEEP_FRM ", 0, 0, 0},
- + { "WAIT_EOF ", 0, 0, 0}, { "SLEEP_EOF ", 0, 0, 0},
- + { "WAIT_QD ", 0, 0, 0},
- + { "WAIT_FBCPF", 0, 0, 0}, { "WAIT_FBCPP", 0, 0, 0}
- +};
- +
- +/* Two Digits for the Fractions */
- +#define NFRAC(n) (uint32_t) ( ((long long) (n*100) / (6ULL/OST_WAIT) ) % 100 )
- +void debug_x1000_lcd()
- +{
- + lcd_putsf(0, 4, "%-10s %7s %10s %10s", "ID", "cnt", "tavg", "tmax");
- + for (int i=0; i<LCD_X1000_DEBUG_ENTRYS; i++) {
- + LCD_Dbg *p = &X1000_LCD_Dbg[i];
- + uint32_t avgbusy = p->avgbusy / ((!p->cnt) ? 1 : p->cnt);
- + uint32_t maxbusy = p->maxbusy;
- + lcd_putsf(0, 5+i, "%s %7d %5d.%02dus %5d.%02dus",
- + p->str, p->cnt,
- + avgbusy / (6/OST_WAIT), NFRAC(avgbusy),
- + maxbusy / (6/OST_WAIT), NFRAC(maxbusy) );
- + }
- +}
- +#undef NFRAC
- +#else
- +void debug_x1000_lcd() {}
- +#endif
- +
- +static void __attribute__ ((noinline)) lcd_wait(Lcd_ID id)
- +{
- + uint32_t i, done = 0;
- +
- + for(i=0; i<LCD_WAIT_MAX; i++) {
- + if (done) break; // early exit when 'done'
- + __ost_delay(OST_WAIT-1); // __ost_delay adds one automatically
- + switch (id) {
- + case LCD_SEND0:
- + case LCD_SEND1:
- + case WAIT_FRAME:
- + case SLEEP_FRAME: done = !jz_readf(LCD_MSTATE, BUSY); break;
- + case WAIT_EOF:
- + case SLEEP_EOF: done = jz_readf(LCD_STATE, EOF) != 0; break;
- + case WAIT_QD: done = jz_readf(LCD_STATE, QD) != 0; break;
- + case WAIT_FBCPF:
- + case WAIT_FBCPP: done = fbcopy_done != 0; break;
- + }
- + }
- +#if defined(LCD_X1000_DEBUG)
- + LCD_Dbg *p = &X1000_LCD_Dbg[id];
- +
- + if (p->avgbusy < 0xfff00000)
- + { p->cnt++; p->avgbusy += i; }
- + else
- + { p->cnt=1; p->avgbusy = i; }
- + if (p->maxbusy < i)
- + p->maxbusy = i;
- +#endif
- +}
- +
- static void lcd_init_controller(const struct lcd_tgt_config* cfg)
- {
- /* Set MCFG/MCFG_NEW according to target interface settings */
- @@ -186,7 +254,7 @@
- fbcopy_done = 1;
- }
- -static void lcd_fbcopy_dma_run(dma_desc* d)
- +static void lcd_fbcopy_dma_run(dma_desc* d, Lcd_ID id)
- {
- if(lcd_panic_mode) {
- /* Can't use DMA if interrupts are off, so just do a memcpy().
- @@ -206,7 +274,7 @@
- jz_set(DMA_DB, 1 << DMA_CHANNEL_FBCOPY);
- jz_writef(DMA_CHN_CS(DMA_CHANNEL_FBCOPY), CTE(1));
- - while(!fbcopy_done);
- + lcd_wait(id);
- }
- static void lcd_fbcopy_dma_full(void)
- @@ -222,7 +290,7 @@
- d.rt = jz_orf(DMA_CHN_RT, TYPE_V(AUTO));
- d.pad0 = 0;
- d.pad1 = 0;
- - lcd_fbcopy_dma_run(&d);
- + lcd_fbcopy_dma_run(&d, WAIT_FBCPF);
- }
- /* NOTE: DMA stride mode can only transfer up to 255 blocks at once.
- @@ -255,7 +323,7 @@
- d.tc = width * height * sizeof(fb_data);
- }
- - lcd_fbcopy_dma_run(&d);
- + lcd_fbcopy_dma_run(&d, WAIT_FBCPP);
- }
- #if STRIDE_MAIN(LCD_HEIGHT, LCD_WIDTH) > 255
- @@ -309,8 +377,8 @@
- static void lcd_wait_frame(void)
- {
- /* Usual case -- wait for EOF, wait for FIFO to drain, clear EOF */
- - while(jz_readf(LCD_STATE, EOF) == 0);
- - while(jz_readf(LCD_MSTATE, BUSY));
- + lcd_wait(WAIT_EOF);
- + lcd_wait(WAIT_FRAME);
- jz_writef(LCD_STATE, EOF(0));
- }
- @@ -328,10 +396,11 @@
- jz_writef(LCD_MCTRL, DMA_TX_EN(0));
- /* Wait for disable to take effect */
- - while(jz_readf(LCD_STATE, QD) == 0);
- + lcd_wait(WAIT_QD);
- } else { // SLEEP: only controlled Stop DMA_TX_EN
- /* Usual case -- wait for EOF, wait for FIFO to drain */
- - lcd_wait_frame();
- + lcd_wait(SLEEP_EOF);
- + lcd_wait(SLEEP_FRAME);
- /* Stop the DMA transfer */
- jz_writef(LCD_MCTRL, DMA_TX_EN(0));
- @@ -345,7 +414,7 @@
- static void lcd_send(uint32_t d)
- {
- - while(jz_readf(LCD_MSTATE, BUSY));
- + lcd_wait(LCD_SEND0);
- REG_LCD_MDATA = d;
- }
- @@ -397,7 +466,7 @@
- break;
- }
- }
- - udelay(1); // Debug-Timings: 0.1-0.5µS could it be busy, be safe....
- + lcd_wait(LCD_SEND1);
- }
- void lcd_init_device(void)
Advertisement
Add Comment
Please, Sign In to add comment