Guest User

458_x1000_LCD_DMA_Debug3.diff

a guest
Sep 1st, 2024
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.63 KB | Source Code | 0 0
  1. x1000_LCD_DMA_Debug3 'revisited' for cd91c238de and newer
  2.  
  3. optional Debug Timings for x1000 LCD DMA (under Debug->View HW Info->Audio)
  4.  
  5. NEW: __ost_delay vs udelay used
  6.      (Configurable before Compile <1>,2,3,6 Cyles aka <166ns>, 333ns, 500ns, or 1µS Resolution)
  7.      Fractional Display of the Timing
  8.      Moved Timing Loop Logic away from x1000_LCD_DMA_fix.diff to here.
  9.  
  10. Credit ZappBranigan2972 on forums / F. Jacobsen on the Theme Site
  11.  
  12. ---
  13.  
  14. --- a/firmware/target/mips/ingenic_x1000/debug-x1000.c.orig 2024-01-05 17:13:17.000000000 +0100
  15. +++ b/firmware/target/mips/ingenic_x1000/debug-x1000.c  2024-01-28 19:06:45.187252886 +0100
  16. @@ -30,6 +30,7 @@
  17.  
  18.  #include "clk-x1000.h"
  19.  #include "gpio-x1000.h"
  20. +#include "lcd-x1000.h"
  21.  
  22.  static bool dbg_clocks(void)
  23.  {
  24. @@ -143,6 +143,7 @@
  25.              lcd_putsf(0, 2, "(%d) SWVOL", es9018k2m_present_flag);
  26.          }
  27.  #endif
  28. +        debug_x1000_lcd();
  29.          lcd_update();
  30.      } while(get_action(CONTEXT_STD, HZ) != ACTION_STD_CANCEL);
  31.  
  32. --- a/firmware/target/mips/ingenic_x1000/lcd-x1000.h.orig   2023-07-09 09:51:56.000000000 +0200
  33. +++ b/firmware/target/mips/ingenic_x1000/lcd-x1000.h    2024-01-28 18:57:00.738666050 +0100
  34. @@ -77,6 +77,26 @@
  35.      size_t dma_wr_cmd_size;
  36.  };
  37.  
  38. +#ifndef BOOTLOADER
  39. +#define LCD_X1000_DEBUG
  40. +#endif
  41. +#if defined(LCD_X1000_DEBUG)
  42. +typedef struct {
  43. +    char str[12];
  44. +    uint32_t cnt;
  45. +    uint32_t avgbusy;
  46. +    uint32_t maxbusy;
  47. +} LCD_Dbg;
  48. +
  49. +#define LCD_X1000_DEBUG_ENTRYS 9
  50. +#endif
  51. +extern void debug_x1000_lcd(void);
  52. +
  53. +#define LCD_WAIT_MAX (65500 * 6) /* loops max. Wait */
  54. +
  55. +/* OST_WAIT: 1 166,6nS, 2 333.33nS, 3 500nS, 6 1µS Resolution */
  56. +#define OST_WAIT 1 /* (6/1 = 6MHz) 166.6nS Resolution */
  57. +
  58.  /* Static configuration for the target's LCD, must be defined by target. */
  59.  extern const struct lcd_tgt_config lcd_tgt_config;
  60.  
  61.  /* Static configuration for the target's LCD, must be defined by target. */
  62.  extern const struct lcd_tgt_config lcd_tgt_config;
  63.  
  64. --- a/firmware/target/mips/ingenic_x1000/lcd-x1000.c.orig   2024-07-10 09:00:17.175641885 +0200
  65. +++ b/firmware/target/mips/ingenic_x1000/lcd-x1000.c    2024-07-10 09:06:46.482963434 +0200
  66. @@ -75,6 +75,74 @@
  67.  #define lcd_panic_mode \
  68.      UNLIKELY((read_c0_status() & 1) == 0)
  69.  
  70. +typedef enum {
  71. +    LCD_SEND0,  LCD_SEND1,
  72. +    WAIT_FRAME, SLEEP_FRAME,
  73. +    WAIT_EOF,   SLEEP_EOF,
  74. +    WAIT_QD,
  75. +    WAIT_FBCPF, WAIT_FBCPP
  76. +} Lcd_ID;
  77. +
  78. +#if defined(LCD_X1000_DEBUG)
  79. +LCD_Dbg X1000_LCD_Dbg[LCD_X1000_DEBUG_ENTRYS] = {
  80. +   { "LCD_SEND0 ", 0, 0, 0}, { "LCD_SEND1 ", 0, 0, 0},
  81. +   { "WAIT_FRAME", 0, 0, 0}, { "SLEEP_FRM ", 0, 0, 0},
  82. +   { "WAIT_EOF  ", 0, 0, 0}, { "SLEEP_EOF ", 0, 0, 0},
  83. +   { "WAIT_QD   ", 0, 0, 0},
  84. +   { "WAIT_FBCPF", 0, 0, 0}, { "WAIT_FBCPP", 0, 0, 0}
  85. +};
  86. +
  87. +/* Two Digits for the Fractions */
  88. +#define NFRAC(n) (uint32_t) ( ((long long) (n*100) / (6ULL/OST_WAIT) ) % 100 )
  89. +void debug_x1000_lcd()
  90. +{
  91. +    lcd_putsf(0, 4, "%-10s %7s %10s %10s", "ID", "cnt", "tavg", "tmax");
  92. +    for (int i=0; i<LCD_X1000_DEBUG_ENTRYS; i++) {
  93. +        LCD_Dbg *p = &X1000_LCD_Dbg[i];
  94. +        uint32_t avgbusy = p->avgbusy / ((!p->cnt) ? 1 : p->cnt);
  95. +        uint32_t maxbusy = p->maxbusy;
  96. +        lcd_putsf(0, 5+i, "%s %7d %5d.%02dus %5d.%02dus",
  97. +                  p->str, p->cnt,
  98. +                  avgbusy / (6/OST_WAIT), NFRAC(avgbusy),
  99. +                  maxbusy / (6/OST_WAIT), NFRAC(maxbusy) );
  100. +    }
  101. +}
  102. +#undef NFRAC
  103. +#else
  104. +void debug_x1000_lcd() {}
  105. +#endif
  106. +
  107. +static void __attribute__ ((noinline)) lcd_wait(Lcd_ID id)
  108. +{
  109. +    uint32_t i, done = 0;
  110. +
  111. +    for(i=0; i<LCD_WAIT_MAX; i++) {
  112. +        if (done) break; // early exit when 'done'
  113. +        __ost_delay(OST_WAIT-1); // __ost_delay adds one automatically
  114. +        switch (id) {
  115. +          case LCD_SEND0:
  116. +          case LCD_SEND1:
  117. +          case WAIT_FRAME:
  118. +          case SLEEP_FRAME: done = !jz_readf(LCD_MSTATE, BUSY);   break;
  119. +          case WAIT_EOF:
  120. +          case SLEEP_EOF:   done = jz_readf(LCD_STATE, EOF) != 0; break;
  121. +          case WAIT_QD:     done = jz_readf(LCD_STATE, QD) != 0;  break;
  122. +          case WAIT_FBCPF:
  123. +          case WAIT_FBCPP:  done = fbcopy_done != 0; break;
  124. +        }
  125. +    }
  126. +#if defined(LCD_X1000_DEBUG)
  127. +    LCD_Dbg *p = &X1000_LCD_Dbg[id];
  128. +
  129. +    if (p->avgbusy < 0xfff00000)
  130. +        { p->cnt++; p->avgbusy += i; }
  131. +    else
  132. +        { p->cnt=1; p->avgbusy = i; }
  133. +    if (p->maxbusy < i)
  134. +        p->maxbusy = i;
  135. +#endif
  136. +}
  137. +
  138.  static void lcd_init_controller(const struct lcd_tgt_config* cfg)
  139.  {
  140.      /* Set MCFG/MCFG_NEW according to target interface settings */
  141. @@ -186,7 +254,7 @@
  142.      fbcopy_done = 1;
  143.  }
  144.  
  145. -static void lcd_fbcopy_dma_run(dma_desc* d)
  146. +static void lcd_fbcopy_dma_run(dma_desc* d, Lcd_ID id)
  147.  {
  148.      if(lcd_panic_mode) {
  149.          /* Can't use DMA if interrupts are off, so just do a memcpy().
  150. @@ -206,7 +274,7 @@
  151.      jz_set(DMA_DB, 1 << DMA_CHANNEL_FBCOPY);
  152.      jz_writef(DMA_CHN_CS(DMA_CHANNEL_FBCOPY), CTE(1));
  153.  
  154. -    while(!fbcopy_done);
  155. +    lcd_wait(id);
  156.  }
  157.  
  158.  static void lcd_fbcopy_dma_full(void)
  159. @@ -222,7 +290,7 @@
  160.      d.rt = jz_orf(DMA_CHN_RT, TYPE_V(AUTO));
  161.      d.pad0 = 0;
  162.      d.pad1 = 0;
  163. -    lcd_fbcopy_dma_run(&d);
  164. +    lcd_fbcopy_dma_run(&d, WAIT_FBCPF);
  165.  }
  166.  
  167.  /* NOTE: DMA stride mode can only transfer up to 255 blocks at once.
  168. @@ -255,7 +323,7 @@
  169.          d.tc = width * height * sizeof(fb_data);
  170.      }
  171.  
  172. -    lcd_fbcopy_dma_run(&d);
  173. +    lcd_fbcopy_dma_run(&d, WAIT_FBCPP);
  174.  }
  175.  
  176.  #if STRIDE_MAIN(LCD_HEIGHT, LCD_WIDTH) > 255
  177. @@ -309,8 +377,8 @@
  178.  static void lcd_wait_frame(void)
  179.  {
  180.      /* Usual case -- wait for EOF, wait for FIFO to drain, clear EOF */
  181. -    while(jz_readf(LCD_STATE, EOF) == 0);
  182. -    while(jz_readf(LCD_MSTATE, BUSY));
  183. +    lcd_wait(WAIT_EOF);
  184. +    lcd_wait(WAIT_FRAME);
  185.      jz_writef(LCD_STATE, EOF(0));
  186.  }
  187.  
  188. @@ -328,10 +396,11 @@
  189.          jz_writef(LCD_MCTRL, DMA_TX_EN(0));
  190.  
  191.          /* Wait for disable to take effect */
  192. -        while(jz_readf(LCD_STATE, QD) == 0);
  193. +        lcd_wait(WAIT_QD);
  194.      } else { // SLEEP: only controlled Stop DMA_TX_EN
  195.          /* Usual case -- wait for EOF, wait for FIFO to drain */
  196. -        lcd_wait_frame();
  197. +        lcd_wait(SLEEP_EOF);
  198. +        lcd_wait(SLEEP_FRAME);
  199.  
  200.          /* Stop the DMA transfer */
  201.          jz_writef(LCD_MCTRL, DMA_TX_EN(0));
  202. @@ -345,7 +414,7 @@
  203.  
  204.  static void lcd_send(uint32_t d)
  205.  {
  206. -    while(jz_readf(LCD_MSTATE, BUSY));
  207. +    lcd_wait(LCD_SEND0);
  208.      REG_LCD_MDATA = d;
  209.  }
  210.  
  211. @@ -397,7 +466,7 @@
  212.              break;
  213.          }
  214.      }
  215. -    udelay(1); // Debug-Timings: 0.1-0.5µS could it be busy, be safe....
  216. +    lcd_wait(LCD_SEND1);
  217.  }
  218.  
  219.  void lcd_init_device(void)
  220.  
Advertisement
Add Comment
Please, Sign In to add comment