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

📄 gspi_bus_2440.c

📁 murata wifi 模块源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
        g_pHwInfo->dmaRxBuf[19]
        ));
    //*/

    prepare_for_spibus(data, g_pHwInfo->dmaRxBuf + 2, size);

    GspiBusReleaseIO();

	return GSPI_OK;
}

int gspi_read_data(UINT16 *data, UINT16 size)
{
   
	GspiBusAcquireIO();
	GspiHostSetSCSHigh();
	GspiHostSetSCSLow();
	GspiBusSetTransmitter_nodma();

	gspi_write_for_read(data[0], 1 + g_spi_dummy_clk_reg); 
	

	GspiBusResetTransmitter();
	GspiBusSetReceiver();
	GspiBusStartRxDMA(0, size * 2 + 2);
	GspiBusWaitForRxDMA();
	GSPI_WAIT_FOR_BUS_RDY();

//	GspiHostSetSCSHigh();
	GspiBusResetReceiver();

//	if (((volatile)(g_pHwInfo->pSPIRegs->rSPSTA0) & BIT0))
    { // read the last byte
        g_pHwInfo->dmaRxBuf[size * 2] = g_pHwInfo->pSPIRegs->rSPRDAT0 & 0xff;
    }

    /*
    DBG_PRINT(gDbgInfo,("rbuffer: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", 
        g_pHwInfo->dmaRxBuf[0], 
        g_pHwInfo->dmaRxBuf[1], 
        g_pHwInfo->dmaRxBuf[2], 
        g_pHwInfo->dmaRxBuf[3],
        g_pHwInfo->dmaRxBuf[4],
        g_pHwInfo->dmaRxBuf[5],
        g_pHwInfo->dmaRxBuf[6],
        g_pHwInfo->dmaRxBuf[7],
        g_pHwInfo->dmaRxBuf[8],
        g_pHwInfo->dmaRxBuf[9],
        g_pHwInfo->dmaRxBuf[10],
        g_pHwInfo->dmaRxBuf[11],
        g_pHwInfo->dmaRxBuf[12],
        g_pHwInfo->dmaRxBuf[13],
        g_pHwInfo->dmaRxBuf[14],
        g_pHwInfo->dmaRxBuf[15],
        g_pHwInfo->dmaRxBuf[16],
        g_pHwInfo->dmaRxBuf[17],
        g_pHwInfo->dmaRxBuf[18],
        g_pHwInfo->dmaRxBuf[19]
        ));
    //*/

	
    // endian swap
    prepare_for_spibus((UINT8 *)data, g_pHwInfo->dmaRxBuf + 2, size);

    GspiBusReleaseIO();

	return GSPI_OK;
}


int gspi_bus_write_data(UINT16 *data, UINT16 size)
{

    UINT16 sizeInBytes = size << 1;
		
    GspiBusAcquireIO();
	GspiHostSetSCSHigh();
	GspiHostSetSCSLow();
	GspiBusSetTransmitter();

    data[0] |= BYTE_STREAM(GSPI_WRITE);
    //DBG_PRINT(gDbgInfo,("buffer: %02x %02x %02x %02x\n", pData[0], pData[1], pData[2], pData[3]));


 
    prepare_for_spibus((unsigned char *)g_pHwInfo->dmaTxBuf, (UCHAR*)data, size);
    // endian swap
    /*
    DBG_PRINT(gDbgInfo,("%02x %02x %02x %02x %02x %02x %02x %02x\n", 
        g_pHwInfo->dmaTxBuf[0],
        g_pHwInfo->dmaTxBuf[1],
        g_pHwInfo->dmaTxBuf[2],
        g_pHwInfo->dmaTxBuf[3],
        g_pHwInfo->dmaTxBuf[4],
        g_pHwInfo->dmaTxBuf[5],
        g_pHwInfo->dmaTxBuf[6],
        g_pHwInfo->dmaTxBuf[7]
        ));
    //*/
	GspiBusStartTxDMA(0, size * 2);	
	GspiBusWaitForTxDMA();
	GSPI_WAIT_FOR_BUS_RDY();
//	while (!((volatile)(g_pHwInfo->pSPIRegs->rSPSTA0) & BIT0));
//	GSPI_WAIT_FOR_BUS_RDY(); 
//	gspi_delay(10);	

	GspiBusResetTransmitter();
//	GspiHostSetSCSHigh();
    GspiBusReleaseIO();
	
	return GSPI_OK;
}

int gspi_bus_write_data_direct(UCHAR *data, UINT16 reg, UINT16 size)
{

    GspiBusAcquireIO();
	GspiHostSetSCSHigh();
	GspiHostSetSCSLow();
	GspiBusSetTransmitter();

	reg |= BYTE_STREAM(GSPI_WRITE);

   // endian swap
	prepare_for_spibus(g_pHwInfo->dmaTxBuf, (UCHAR*)&reg,  1);
    prepare_for_spibus(g_pHwInfo->dmaTxBuf + 2, data,  (size-1));
    /*
    DBG_PRINT(gDbgInfo,("%02x %02x %02x %02x %02x %02x %02x %02x\n", 
        g_pHwInfo->dmaTxBuf[0],
        g_pHwInfo->dmaTxBuf[1],
        g_pHwInfo->dmaTxBuf[2],
        g_pHwInfo->dmaTxBuf[3],
        g_pHwInfo->dmaTxBuf[4],
        g_pHwInfo->dmaTxBuf[5],
        g_pHwInfo->dmaTxBuf[6],
        g_pHwInfo->dmaTxBuf[7]
        ));
    //*/
	GspiBusStartTxDMA(0, size * 2);

	GspiBusWaitForTxDMA();
	GSPI_WAIT_FOR_BUS_RDY();
	//gspi_delay(20);	

	GspiBusResetTransmitter();
//	GspiHostSetSCSHigh();
    GspiBusReleaseIO();
	return GSPI_OK;
}
/*--------------------------------------------------*/

int gspi_read_data_direct_nodma(UCHAR *data, UINT16 reg, UINT16 size)
{
  
	UINT8 dummy = 0xff;

 	GspiBusAcquireIO();
	GspiHostSetSCSHigh();
	GspiHostSetSCSLow();
    GspiBusSetTransmitter_nodma();

	gspi_write_for_read(reg, 1 + g_spi_dummy_clk_data); 
    gspi_recv_data((UINT16*)data,size);
//	gspi_delay(500);
//	GspiHostSetSCSHigh();
	GspiBusResetReceiver();

    GspiBusReleaseIO();

	return GSPI_OK;
}

int gspi_read_data_nodma(UINT16 *data, UINT16 size)
{
   	GspiBusAcquireIO();
	GspiHostSetSCSHigh();
	GspiHostSetSCSLow();
	GspiBusSetTransmitter_nodma();

	gspi_write_for_read(data[0], 1 + g_spi_dummy_clk_reg); 	
    gspi_recv_data((UINT16*)data,size);
//	gspi_delay(500);   
//	GspiHostSetSCSHigh();
	GspiBusResetReceiver();
    GspiBusReleaseIO();

    return GSPI_OK;
}


int gspi_write_data_nodma(UINT16 *data, UINT16 size)
{

  	GspiBusAcquireIO();
	GspiHostSetSCSHigh();
	GspiHostSetSCSLow();
	GspiBusSetTransmitter_nodma();

    data[0] |= BYTE_STREAM(GSPI_WRITE);
    //DBG_PRINT(gDbgInfo,("buffer: %02x %02x %02x %02x\n", pData[0], pData[1], pData[2], pData[3]));

	gspi_xmt_data(data,size);
//	gspi_delay(500);	
	//GSPI_WAIT_FOR_BUS_RDY();

	GspiBusResetTransmitter();
//	GspiHostSetSCSHigh();
    GspiBusReleaseIO();
   	
	return GSPI_OK;
}

int gspi_write_data_direct_nodma(UCHAR *data, UINT16 reg, UINT16 size)
{
	
    GspiBusAcquireIO();
	GspiHostSetSCSHigh();
	GspiHostSetSCSLow();
	GspiBusSetTransmitter_nodma();

	reg |= BYTE_STREAM(GSPI_WRITE);

  	gspi_xmt_data((UINT16*)&reg,1);   
	gspi_xmt_data((UINT16*)data, size);
//	gspi_delay(500);	
//	GSPI_WAIT_FOR_BUS_RDY();

 	GspiBusResetTransmitter();
//	GspiHostSetSCSHigh();

    GspiBusReleaseIO();
	
	return GSPI_OK;
}
/*-------------------------*/

BOOL VirtualCopy( 
  LPVOID lpvDest, 
  LPVOID lpvSrc, 
  DWORD cbSize, 
  DWORD fdwProtect 
);

unsigned long GspiBusGetBSPIntID()
{
    return SYSINTR_WLAN;
}
unsigned long GspiBusGetBSPDMAIntID()
{
    return SYSINTR_DMA1;
}

//
// Map a physical region of memory to a virtual region of memory
//
void* MapIOSpace(void* pPhysAddr,
                 DWORD dwSize,
                 DWORD dwFlags) // PAGE_READONLY, PAGE_READWRITE, PAGE_NOCACHE
{

  void*       pPhysBase;
  DWORD       dwOffset;
  void*       pVirtBase;
  void*       pVirtAddr = NULL;

  /*** Everything must be aligned on page boundaries ***/

  // Determine the system page size (only once)
  if(!si.dwPageSize)
  {
    GetSystemInfo(&si);
  }

  // Determine how much beyond a page boundary the requested memory is
  dwOffset = (DWORD)pPhysAddr % si.dwPageSize;

  // Get the nearest page boundary
  pPhysBase = (void*)((DWORD)pPhysAddr - dwOffset);
  
  // If the requested address is not page aligned, adjust the size
  dwSize += dwOffset;
  
  // Adjust the size to a multiple of pages
  dwSize = dwSize + si.dwPageSize - 1;
  dwSize -= dwSize % si.dwPageSize;

  // Allocate some virtual memory
  pVirtBase = VirtualAlloc(NULL,
                           dwSize,
                           MEM_RESERVE,
                           PAGE_NOACCESS);
  if(pVirtBase)
  {
    // If the starting physical address is <= 512MB, we must divide it by
    //  256 and set the PAGE_PHYSICAL bit to make VirtualCopy() happy.  This
    //  is exactly the opposite of the documentation...
//#ifndef BUILT_FOR_WCE500
//    if((DWORD)pPhysBase < 0x20000000)
//#endif
    {
      pPhysBase = (void*)((DWORD)pPhysBase / 256);
      dwFlags |= PAGE_PHYSICAL;
    }

    // Map the physical memory into the virtual memory
    if(!VirtualCopy(pVirtBase,
                    pPhysBase,
                    dwSize,
                    dwFlags))
    {
      VirtualFree(pVirtBase, 0, MEM_RELEASE);
    }
    else
    {
      pVirtAddr = (void*)((DWORD)pVirtBase + dwOffset);
    }
  }

  return(pVirtAddr);
}

void UnmapIOSpace(void* pVirtAddr)
{
  DWORD       dwOffset;
  void*       pVirtBase;

  // Determine how much beyond a page boundary the requested memory is
  dwOffset = (DWORD)pVirtAddr % si.dwPageSize;

  // Get the nearest page boundary
  pVirtBase = (void*)((DWORD)pVirtAddr - dwOffset);

  // Release the virtual pointer
  VirtualFree(pVirtBase, 0, MEM_RELEASE);

}
int gspi_delay_loop; 
void gspi_delay(int loop)
{	
	int i;
	for (i = 0; i < loop; i++)
			gspi_delay_loop=loop;
}
//gli wake up config  这个函数主要是用来把中断的pin配置成wakeupsource功能用
VOID gspx_config_wakeup(PVOID pHD)
{
	DWORD ttt;

	GSPIMSG(1, (TEXT("GSPI: gspx_config_wakeup\r\n")));
#if 0

	// Configure the interrupt pin
    g_pHwInfo->pGPIORegs->rGPGCON &= ~(3<<8);
    g_pHwInfo->pGPIORegs->rGPGCON |= (2<<8);
    g_pHwInfo->pGPIORegs->rGPGUP  |= (1<<4);

	ttt = (g_pHwInfo->pGPIORegs->rEXTINT1 & (~(0xf<<16))) | (0x2<<16);
	g_pHwInfo->pGPIORegs->rEXTINT1 = ttt;
#endif 
	return GSPI_OK;	
}

// gli this function will be called  for wake up so need not power up and reset module
//这个函数主要实现当cpu被wakeup起来后要重新对gpio口进行配置特别是被配置成wakeup source功能的pin 重新配置成中断功能,和初始化配置一样。千万不要进行powerdown的超作
VOID gspx_reinit_hw(PVOID pHC)
{
	DWORD ttt;

	GSPIMSG(1, (TEXT("GSPI: gspx_reinit_hw\r\n")));

	g_pHwInfo->pGPIORegs->rGPGCON &= ~((0x03 << 10) | (0x03 << 12) | (0x03 << 14)); // clear
    g_pHwInfo->pGPIORegs->rGPGCON |= (0x03 << 10) | (0x03 << 12) | (0x03 << 14);	// set
	g_pHwInfo->pGPIORegs->rGPGUP |= (0x01 << 5)|(0x01 << 6);

	// to config SPI_CS:GPE11 as general io pin
	g_pHwInfo->pGPIORegs->rGPECON &= ~(0x03 << 22); // clear 
	g_pHwInfo->pGPIORegs->rGPECON |= 0x01 << 22;	// set
	g_pHwInfo->pGPIORegs->rGPEUP |= (0x01 << 11);

	//Reset:GPG12 as output
	//g_pHwInfo->pGPIORegs->rGPGCON &= ~(0x03 << 24); // clear 
	//g_pHwInfo->pGPIORegs->rGPGCON |= 0x01 << 24;	// set
	//g_pHwInfo->pGPIORegs->rGPGUP |= (0x01 << 12);
	
	//PowerDown:GPA12 as output
	g_pHwInfo->pGPIORegs->rGPACON &= ~(0x01 << 12); // set GPA12 to 0 

	// Configure the interrupt pin
    g_pHwInfo->pGPIORegs->rGPGCON &= ~(3<<8);
    g_pHwInfo->pGPIORegs->rGPGCON |= (2<<8);
    g_pHwInfo->pGPIORegs->rGPGUP  |= (1<<4);

	ttt = (g_pHwInfo->pGPIORegs->rEXTINT1 & (~(0xf<<16))) | (0x2<<16);
	g_pHwInfo->pGPIORegs->rEXTINT1 = ttt;

	//GspiHostSetRSTHigh();
	//GspiHostSetPDHigh();
	//GspiHostSetSCSHigh();

}

//这个函数主要是对gpio重新进行初始化,不过你可以需要对模块进行一个powerdown and reset module的动作,就在你昨天那个问题点击power按钮系统再次起来 scan不到ap的愿意可能是你们需要对gpio口在次进行一次初始化动作
VOID gspx_reinit(PVOID pHC)
{
	DWORD ttt;

	GSPIMSG(1, (TEXT("GSPI: gspx_reinit\r\n")));

	g_pHwInfo->pGPIORegs->rGPGCON &= ~((0x03 << 10) | (0x03 << 12) | (0x03 << 14)); // clear
    g_pHwInfo->pGPIORegs->rGPGCON |= (0x03 << 10) | (0x03 << 12) | (0x03 << 14);	// set
	g_pHwInfo->pGPIORegs->rGPGUP |= (0x01 << 5)|(0x01 << 6);

	// to config SPI_CS:GPE11 as general io pin
	g_pHwInfo->pGPIORegs->rGPECON &= ~(0x03 << 22); // clear 
	g_pHwInfo->pGPIORegs->rGPECON |= 0x01 << 22;	// set
	g_pHwInfo->pGPIORegs->rGPEUP |= (0x01 << 11);

	//Reset:GPG12 as output
	//g_pHwInfo->pGPIORegs->rGPGCON &= ~(0x03 << 24); // clear 
	//g_pHwInfo->pGPIORegs->rGPGCON |= 0x01 << 24;	// set
	//g_pHwInfo->pGPIORegs->rGPGUP |= (0x01 << 12);
	
	//PowerDown:GPA12 as output
	g_pHwInfo->pGPIORegs->rGPACON &= ~(0x01 << 12); // set GPA12 to 0 

	// Configure the interrupt pin
    g_pHwInfo->pGPIORegs->rGPGCON &= ~(3<<8);
    g_pHwInfo->pGPIORegs->rGPGCON |= (2<<8);
    g_pHwInfo->pGPIORegs->rGPGUP  |= (1<<4);

	ttt = (g_pHwInfo->pGPIORegs->rEXTINT1 & (~(0xf<<16))) | (0x2<<16);
	g_pHwInfo->pGPIORegs->rEXTINT1 = ttt;

    // take the card out of reset
	GspiHostSetRSTHigh();
	//NdisMSleep(1000);
	Sleep(1);
	GspiHostSetRSTLow();

	Sleep(10);
   	GspiHostSetRSTHigh();
	GspiHostSetPDHigh();
	GspiHostSetSCSHigh();

	Sleep(1);

}

#endif 

#endif

⌨️ 快捷键说明

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