void dma_deinit(uint32_t dmaNdx, uint32_t chnNdx) { assert(dmaNdx == 0); HAL_ENTER_CRITICAL(); dma_idle.bmChnEn[dmaNdx] &= ~(1 << chnNdx); if (0 == dma_idle.bmChnEn[dmaNdx]) { DMA_Deinit(DMA0); CLOCK_DisableClock(kCLOCK_Dma); NVIC_DisableIRQ(DMA0_IRQn); } HAL_LEAVE_CRITICAL(); }
//------------------------------------------------------------------------------ // // Function: DMA_Init // // Called by device manager to initialize device. // DWORD DMA_Init( LPCWSTR szContext, LPCVOID pBusContext ) { DWORD rc = (DWORD)NULL; UNREFERENCED_PARAMETER(pBusContext); UNREFERENCED_PARAMETER(szContext); DEBUGMSG(ZONE_FUNCTION, ( L"+DMA_Init(%s, 0x%08x)\r\n", szContext, pBusContext )); // Create device structure Device_t *pDevice = (Device_t *)LocalAlloc(LPTR, sizeof(Device_t)); if (pDevice == NULL) { DEBUGMSG(ZONE_ERROR, (L"ERROR: DMA_Init: " L"Failed allocate DMA controller structure\r\n" )); goto cleanUp; } // initialize memory memset(pDevice, 0, sizeof(Device_t)); // Set cookie pDevice->cookie = DMA_DEVICE_COOKIE; // Initalize critical section InitializeCriticalSection(&pDevice->cs); // Read device parameters if (GetDeviceRegistryParams( szContext, pDevice, dimof(s_deviceRegParams), s_deviceRegParams ) != ERROR_SUCCESS) { DEBUGMSG(ZONE_ERROR, (L"ERROR: DMA_Init: " L"Failed read DMA driver registry parameters\r\n" )); goto cleanUp; } // Retrieve device ID pDevice->SdmaDevice = SOCGetDMADevice(pDevice->SdmaIndex); // Set hardware to full power EnableDeviceClocks(pDevice->SdmaDevice, TRUE); // DMA will be in smart idle mode so we don't need to // ever set the power state of the DMA to D4 // initialize general dma controller if (InitializeDevice(pDevice) == FALSE) { DEBUGMSG (ZONE_ERROR, (L"ERROR: DMA_Init: " L"Failed to initialize device\r\n" )); goto cleanUp; } rc = (DWORD)pDevice; cleanUp: if (rc == 0) DMA_Deinit((DWORD)pDevice); DEBUGMSG(ZONE_FUNCTION, (L"-DMA_Init(rc = %d)\r\n", rc)); return rc; }