// -------------------------------------------------------------------- // Copyright (c) 2007 by Terasic Technologies Inc. // -------------------------------------------------------------------- // // Permission: // // Terasic grants permission to use and modify this code for use // in synthesis for all Terasic Development Boards and Altera Development // Kits made by Terasic. Other use of this code, including the selling // ,duplication, or modification of any portion is strictly prohibited. // // Disclaimer: // // This VHDL/Verilog or C/C++ source code is intended as a design reference // which illustrates how these types of functions can be implemented. // It is the user's responsibility to verify their design for // consistency and functionality through the use of formal // verification methods. Terasic provides no warranty regarding the use // or functionality of this code. // // -------------------------------------------------------------------- // // Terasic Technologies Inc // 356 Fu-Shin E. Rd Sec. 1. JhuBei City, // HsinChu County, Taiwan // 302 // // web: http://www.terasic.com/ // email: support@terasic.com // // -------------------------------------------------------------------- // Author: Richard Chang // 0626_2008, richard // remove delay in HAL1761_RegWrite32 & HAL1761_RegRead32 #include #include #include #include #include #include "system.h" #include "isp1761_hal_nios2.h" #include "isp1761_register.h" #ifdef DEBUG_USB_HAL #define DEBUG_OUT(x) {printf("[USBHAL]"); printf x;} #define DEBUG_ERR(x) {printf("[USBHAL_ERR]"); printf x;} #else #define DEBUG_OUT(x) #define DEBUG_ERR(x) #endif #define IO_DELAY(x) OS_udelay(x) #define WRITE_DELAY 2 #define READ_DELAY 1 //======== Fundametal USB Register Access Function ======= void HAL1761_RegWrite32(alt_u32 Addr, alt_u32 data32){ #ifdef DATA_BUS_16BIT_WIDTH IOWR_16DIRECT(ISP1761_BASE, Addr, data32 & 0xFFFF); IO_DELAY(WRITE_DELAY); IOWR_16DIRECT(ISP1761_BASE, Addr + 1, (data32 >> 16 )& 0xFFFF); IO_DELAY(WRITE_DELAY); #else // 32-bits // 0626_2008, richard IO_DELAY(WRITE_DELAY); IOWR(ISP1761_SLAVE_BASE, Addr, data32); #endif } alt_u32 HAL1761_RegRead32(alt_u32 Addr){ alt_u32 data32; #ifdef DATA_BUS_16BIT_WIDTH alt_u16 high_word, low_word; low_word = IORD_16DIRECT(ISP1761_BASE, Addr ); IO_DELAY(READ_DELAY); high_word = IORD_16DIRECT(ISP1761_BASE, (Addr+1) ); IO_DELAY(READ_DELAY); data32 = (high_word << 16) | low_word; #else // 32-bits // 0626_2008, richard IO_DELAY(READ_DELAY); data32 = IORD(ISP1761_SLAVE_BASE, Addr); #endif //DATA_BUS_16BIT_WIDTH return data32; } #ifdef HCD_CONFIG_DMA // Memory Access by DMA void HAL1761_MemWrite(alt_u32 Addr, alt_u32 szData[], alt_u32 ByteLen){ int i; alt_u32 MemAddr = Addr & 0xFFFF; IO_DELAY(WRITE_DELAY); for(i=0;i alt_ticks_per_second()){ bDone = TRUE; // timeout DEBUG_ERR(("DMA Read fail\n")); } }else{ bDone = TRUE; } }while(!bDone); // disable dma HAL1761_RegWrite32(0x0330, 0); } #else // memory access by Programming IO (use CPU) void HAL1761_MemWrite(alt_u32 Addr, alt_u32 szData[], alt_u32 ByteLen){ int i; alt_u32 MemAddr = Addr & 0xFFFF; IO_DELAY(WRITE_DELAY); #if 0 memcpy((void *)ISP1761_SLAVE_BASE+MemAddr, szData, ByteLen); // data cached enabled #else for(i=0;i