⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 system.c

📁 An complete pmp solution for mattel juicebox player. Using crossworks for arm.
💻 C
📖 第 1 页 / 共 2 页
字号:
--------------------------------------------------------------
19-0    |  Transfer count in bytes
--------------------------------------------------------------

Req sources: 
BDMA0 01 IIS
      10 UART0
	  11 SIO
BDMA1 01 Timer
	  10 UART1
	  11 SIO
*/



xTDMAStatus wDMAInspect (xTPortHardware xDMA, u32 *uCurrSrc, u32 *uCurrDest, u32 *uCurrCnt)
{
  u32 ulShift = 3;
  if (xDMA == portZDMA0) ulShift = 0; 
  if (xDMA == portZDMA1) ulShift = 0x20>>2;
  if (xDMA == portBDMA0) ulShift = 0x100000>>2;
  if (xDMA == portBDMA1) ulShift = 0x100020>>2;
  if (ulShift == 3) return portDMAStatusUnknown;
  *uCurrSrc = *(zdcsrc0 + ulShift) & 0x0FFFFFFF;
  *uCurrDest = *(zdcdes0 + ulShift) & 0x0FFFFFFF;
  *uCurrCnt = (*(zdicnt0 + ulShift)&0x000FFFFF)-(*(zdccnt0 + ulShift)&0x000FFFFF);//*(zdccnt0 + ulShift) & 0x000FFFFF;

  switch (*(zdcon0 + ulShift))
    {
    case 0x00:
      {
      if (*(zdccnt0 + ulShift) & 0x00100000) return portDMAStatusTransfer;
        else return portDMAStatusReady;
      }
    case 0x10: return portDMAStatusTransfer;
    case 0x20: return portDMAStatusEnded;
    }
  return portDMAStatusUnknown;
}

//-----------------------------------------------------------------------
xTPortHardware wBDMA0Run (void *pvSrc, void *pvDest, u32 uxSettings, void *pvInterrupt)
{
  if ((*bdcon0 & 0x30) != 0x00) return portNoHW;
  *bdcon0 = 0x03;
  *bdicnt0 = 0x04C00000 | ((uxSettings & 0x03000000)<<6) | (uxSettings & 0x002FFFFF);
  *bdisrc0 = (uxSettings & 0xF0000000) | (u32)pvSrc;
  
  u32 ulReg = ((uxSettings & 0x0C000000) << 2) | (u32)pvDest;
  if ((uxSettings & 0x3C000000) == 0x3C000000) ulReg |= 0xC0000000;
  else if ((uxSettings & 0x30000000) == 0x30000000) ulReg |= 0x80000000;
  else ulReg |= 0x40000000;
  *bdides0 = ulReg;
    
  if (pvInterrupt)
    { 
    wInterruptHandlerInit (portIntBDMA0, pvInterrupt); 
    dwInterruptEnable (portIntBDMA0);
    }

  *bdcon0 = 0x00;
  *bdicnt0 |= 0x00100000;
  return portBDMA0;
}

//-----------------------------------------------------------------------
xTPortHardware wBDMA1Run (void *pvSrc, void *pvDest, u32 uxSettings, void *pvInterrupt)
{
  if ((*bdcon1 & 0x30) != 0x00) return portNoHW;
  
  *bdcon1 = 0x03;
  *bdicnt1 = 0x04C00000 | ((uxSettings & 0x03000000)<<6) | (uxSettings & 0x002FFFFF);
  *bdisrc1 = (uxSettings & 0xF0000000) | (u32)pvSrc;
  
  u32 ulReg = ((uxSettings & 0x0C000000) << 2) | (u32)pvDest;
  if ((uxSettings & 0x3C000000) == 0x3C000000) ulReg |= 0xC0000000;
  else if ((uxSettings & 0x30000000) == 0x30000000) ulReg |= 0x80000000;
  else ulReg |= 0x40000000;
  *bdides1 = ulReg;
    
  if (pvInterrupt)
    { 
    wInterruptHandlerInit (portIntBDMA1, pvInterrupt); 
    dwInterruptEnable (portIntBDMA1);
    }
  *bdcon0 = 0x00;
  *bdicnt1 |= 0x00100000;
  return portBDMA1;
}
//-------------------------------------------------------------
void wDMAStop (xTPortHardware xDMA)
{
  switch (xDMA)
    {
    case portZDMA0:
	  {
      *zdcon0 = 0x03;
	  break;
	  }
    case portZDMA1: 
	  {
      *zdcon1 = 0x03;
	  break;
	  }
    case portBDMA0:
	  {
      *bdcon0 = 0x03;
	  break;
	  }
    case portBDMA1:   
	  {
      *bdcon1 = 0x03;
	  break;
	  }
	}
}
/*===========================================================*/
/*-----             Inter-IC Sound (IIS)                -----*/
void wIISInit()
{
  *iisfifcon = 0x00000300;
  *iiscon = 0x00000002; /*IIS off */
  *iismod = 0x00000084; /*CODECLK = 256fs */
  *iiscon = 0x00000003; /*IIS on */
}
//--------------------------------------------------------------------
i32 wIISDMATransferInit (u32 *pvBufferAddress, u32 ulBufferSize, u32 uxSettings)
{
  *iisfifcon = 0x0E00;
  *iiscon = 0x00000022;
  *iismod = 0x00000089;
  *iispsr = 0x23;
  uxSettings <<= 21;
  uxSettings &= 0x00200000;
  uxSettings |= ulBufferSize & 0x000FFFFF;
  uxSettings |= 0x5D000000;
  if (wBDMA0Run (pvBufferAddress, (u32*)iisfif, uxSettings, NULL)!=portBDMA0) return -1;
  *iiscon = 0x00000023;
  return 0;
}
//----------------------------------------------------------

/* uxSettings:
0 | 1:auto reload
*/
u32 wIISBufferStatusInspect()
{
  static u32 ulSrc, ulDest, ulCount;
  ulCount = 0;
  wDMAInspect (portBDMA0, &ulSrc, &ulDest, &ulCount);
  return (ulCount);
}
//----------------------------------------------------------
void wIISDMATransferStop ()
{
  *iiscon = 0x00000022;
  wDMAStop(portBDMA0);
}

/*===========================================================*/
/*-----                Inter-IC Connect (IIC)           -----*/

void wIICInit(u32 uxSettings, void *pvInterrupt)
{
  *iiccon = uxSettings&0xFF;
  *iicstat = 0x00;
}
/*
uxSettings:
7     | ACK generation 0-enabled 1-disabled
6     | Closk source 0:MCLK/16, 1:MCLK/512
5     | Interrupt
4
3-0   | Prescaler
*/

void wIICWrite (u08 usAddress, u08 usData)
{
  *iicstat = 0xD0;
  *iicds = usAddress;
  *iicstat = 0xF0;
  while (*iiccon &0x08 == 0x00);
  *iicds = usData;
  *iiccon &= 0xF7;
  while (*iiccon &0x08 == 0x00);
  *iicstat = 0xD0;
  *iiccon &= 0xF7;
}
//-----------------------------------------------------------
void wIICRead (u08 usAddress, u08 *usData)
{
  *iicstat = 0x90;
  *iicds = usAddress;
  *iicstat = 0xB0;
  while (*iiccon &0x08 == 0x00);
  *usData = *iicds;
  *iiccon &= 0xF7;
  while (*iiccon &0x08 == 0x00);
  *iicstat = 0x90;
  *iiccon &= 0xF7;
}
/*===========================================================*/
/*-----                 LCD Controller                  -----*/
void *wFramebufferStart()
{
    /* Return with starting address of LCD framebuffer */
    return (void*)(((*lcdsaddr1) & 0x07ffffff) << 1);
    
}
//-------------------------------------------------------------
void wSetFramebufferStart(u32 *addr)
{
  *lcdsaddr1 &= ~((*lcdsaddr1) & 0x07ffffff);
  *lcdsaddr1 |= ((((u32)(addr)) & 0x0fffffff) >> 1);

}

//-------------------------------------------------------------
void wLCDInit()
{ 
    /* Set ENVID (bit 0 of lcdcon1) to 0 to disable panel */
   *lcdcon1=0x00C0DFC0;    /* LCDCON1  (LCD Control 1) */


   /* Configure the LCD panel, using settings borrowed from
      the built in self test code.
   */
   *lcdcon2=0x0141649F;    /* LCDCON2  (LCD Control 2) */
   *lcdcon3=0x00000000;    /* LCDCON3  (LCD Control 3) */
   *lcdsaddr1=0x16080000;  /* LCDSADDR1  (Frame Upper Buffer Start Address 1) */
   *lcdsaddr2=0x0F887080;  /* LCDSADDR2  (Frame Lower Buffer Start Address 2) */
   *lcdsaddr3=0x00000078;  /* LCDSADDR3  (Virtual Screen Address) */
   *redlut=0xFCA86420;     /* REDLUT  (RED Lookup Table) */
   *greenlut=0xFCA86420;   /* GREENLUT  (GREEN Lookup Table) */
   *bluelut=0xECA86420;    /* BLUELUT  (BLUE Lookup Table) */
   *dp1_2=0x0000A5A5;      /* DP1_2  (Dithering Pattern duty 1/2) */
   *dp4_7=0x0BA5DA65;      /* DP4_7  (Dithering Pattern duty 4/7) */
   *dp3_5=0x000A5A5F;      /* DP3_5  (Dithering Pattern duty 3/5) */
   *dp2_3=0x00000D6B;      /* DP2_3  (Dithering Pattern duty 2/3) */
   *dp5_7=0x0EB7B5ED;      /* DP5_7  (Dithering Pattern duty 5/7) */
   *dp3_4=0x00007DBE;      /* DP3_4  (Dithering Pattern duty 3/4) */
   *dp4_5=0x0007EBDF;      /* DP4_5  (Dithering Pattern duty 4/5) */
   *dp6_7=0x07FDFBFE;      /* DP6_7  (Dithering Pattern duty 6/7) */
   *dithmode=0x00000000;   /* DITHMODE  (Dithering Mode) */
   
   /* Enable the panel now that the settings are in place */
   *lcdcon1=0x00C0DF41;    /* LCDCON1  (LCD Control 1) */
   
   PORT_LCD |= (1 << LCDOFF);
   PORT_LCD |= (1 << DISPOFF);
}
//-------------------------------------------------------------
void wLCDBitmapInit(xTBitmap *pxBitmap)
{
  pxBitmap->uiSizeX = 240;
  pxBitmap->uiSizeY = 160;
  pxBitmap->pxData = wFramebufferStart();
}
//-------------------------------------------------------------
void wFontInit(xTFont *pxFont)
{
  pxFont->pxData = (void*)&xFontAscii;
  pxFont->uiSizeX = 5;
  pxFont->uiSizeY = 7;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -