int BlockCopy( long destblock, long soublock ) { long destAddr = GetBlockAddr( destblock, 0 ); long souAddr = GetBlockAddr( soublock, 0 ); UINT8 *pBuf, count; int index, copySize = BLOCKSIZE << 1; do { copySize = copySize >> 1; pBuf = MALLOC(copySize); }while((pBuf == NULL) && copySize); if(copySize == 0) { return 1; } count = BLOCKSIZE / copySize; GsnFlashIf_PioReq(); GsnFlashIf_FlashSectorErase(destAddr, TRUE); GsnFlashIf_PioRelease(); for(index = 0; index < count; index++) { GsnFlashCache_BlkFetch(souAddr, (UINT32)pBuf, copySize, NULL); GsnFlashIf_PioReq(); GsnFlashIf_FlashProgram(destAddr, copySize, pBuf, TRUE); GsnFlashIf_PioRelease(); souAddr += copySize; destAddr += copySize; } FREE(pBuf); return 0; }
void Flash_Write(uint8_t addr, uint32_t value) { uint32_t block_addr = GetBlockAddr(); if(addr < BLOCK_SIZE / 4 - 1) { if(FirstUse) { FMC_Write(block_addr + 4 * (addr + 1), value); FirstUse = FALSE; } else { uint32_t i, write_addr; for(i = block_addr; i < block_addr + BLOCK_SIZE; i += 4) { write_addr = (i - (block_addr + 4)) / 4; if(write_addr != addr) { FMC_Write(i + BLOCK_SIZE, FMC_Read(i)); } } FMC_Write(block_addr, BLOCK_STAT_DISABLED); block_addr += BLOCK_SIZE; Block_Init(block_addr); FMC_Write(block_addr + (4 * (addr + 1)), value); } } }
static int VerifyFlash ( void * data, long block, long relsector, long size, long relpos ) { long addr = GetBlockAddr( block, relsector ) + relpos; UINT8 *pBuf, *pScr, *pDst; UINT32 index/*, sectors, rem*/; pBuf = gsn_malloc(size); if(NULL == pBuf) { while(1); } /*GsnFlashIf_PioReq();*/ /*GsnFlashIf_FlashRead(addr, size, pBuf);*/ GsnFlashCache_BlkFetch(addr, (UINT32)pBuf, size, NULL); /*GsnFlashIf_PioRelease(); */ pScr = data; pDst = pBuf; for(index = 0; index < size; index++) { if( *pScr++ != *pDst++) { GsnOsal_ByteRelease(pBuf); return 1; } } GsnOsal_ByteRelease(pBuf); return 0; }
static int WriteFlash ( void * data, long block, long relsector, long size, long relpos ) { long addr = GetBlockAddr( block, relsector ) + relpos; GsnFlashIf_PioReq(); if((addr & 0xff)) { /* work around for bug */ int remBytes = 0x100 - (addr & 0xff); if(remBytes < size) { GsnFlashIf_FlashProgram(addr, remBytes, data, TRUE); size -= remBytes; addr = addr + remBytes; data = (char*)data + remBytes; } } GsnFlashIf_FlashProgram(addr, size, data, TRUE); GsnFlashIf_PioRelease(); if(size & 3) { return 0; } if((int)data & 0x3) { return 0; } return 0; }
static int EraseFlash ( long block ) { long addr = GetBlockAddr( block, 0 ); GsnFlashIf_PioReq(); GsnFlashIf_FlashErase(addr, BLOCKSIZE, TRUE); GsnFlashIf_PioRelease(); return 0; }
// d2 d6 d5 d4 a3 a4 void DrawTiles_LR_2(int patternBase, int numTiles, int x, int y, int* layerCoords, ubyte** layout) { auto addr = Calc_VRAM_Pos(x, y, layerCoords); uint* tileAddr; for(int i = 0; i < numTiles; i++) { auto block = GetBlockAddr(x, y, layerCoords, layout, tileAddr); DrawTiles(addr, patternBase, tileAddr, block); addr = (addr + 4) & 0x7F; x += 16; } }
uint32_t Flash_Read(uint8_t addr) { uint32_t block_addr = GetBlockAddr(); if(addr < BLOCK_SIZE / 4 - 1) { if(FirstUse) { return 0xff; } else { return FMC_Read(block_addr + 4 * addr); } } return 0; }
static int ReadFlash ( void * data, long block, long blockrel, long datalen ) { long addr = GetBlockAddr( block, 0 ) + blockrel; #if 1 void *pActData; int remBytes/*, index*/; pActData = data; /*long actDLen = datalen; GSN_DMA_T GsnDma; GSN_DMA_CHANNEL_CONFIG_T ptChannelConfig; */ if((int)data & 0x3) { remBytes = (4 - (int)data &0x3); data = (char *)data + remBytes; datalen -= remBytes; } GsnFlashCache_BlkFetch(addr, (UINT32)data, datalen, NULL); #if 0 if(data != pActData) { unsigned int lastData; char *pTmp; GsnDma_Open (&GsnDma, NULL, 1); ptChannelConfig.channelBitField.dmaCycleType = GSN_DMACYCLE_MSG_ALTERNATE ; ptChannelConfig.channelBitField.nextUserBurst = 1; ptChannelConfig.channelBitField.nMinusOne = 0; ptChannelConfig.channelBitField.rPower = GSN_ARBITRATION_1024_DMATRANSFER; ptChannelConfig.channelBitField.srcPrtCntl = 7; ptChannelConfig.channelBitField.destPrtCntl = 7; ptChannelConfig.channelBitField.srcSize = GSN_DMA_BYTE_SRC_SIZE; ptChannelConfig.channelBitField.srcInc = GSN_DMA_BYTE_SRC_INC; ptChannelConfig.channelBitField.destSize = GSN_DMA_BYTE_DEST_SIZE; ptChannelConfig.channelBitField.destInc = GSN_DMA_BYTE_DEST_INC; GsnDma_CallBackRegister((GSN_DMA_T *)(&GsnDma), (DMACALLBACK_FP)dmaDoneCb,NULL , 0); GsnDma_CycleControl(&GsnDma,&ptChannelConfig, 0, datalen, data, pActData); GsnDma_ChannelEnable(&GsnDma, 0); GsnDma_Enable(&GsnDma); while (!dmaDoneFlag) { GsnDma_ChannelSoftwareRequest(&GsnDma,0); } dmaDoneFlag = 0; addr = addr + datalen; data = (char *)pActData + datalen; GsnFlashCache_BlkFetch(addr, (UINT32)&lastData, 4, NULL); index = (int)pActData & 0x3; pTmp = (char *)&lastData; while (remBytes >= index) { *(char *) data = *(pTmp + index); index++; data = (char *)data + 1; } //GsnDma_Disable(&GsnDma); DMA_CPAC_SET(GsnDma.pReg,1); GsnDma_Close(&GsnDma); } #else if(data != pActData) { char lastData[4]; char *pTmp; memcpy(pActData, data, datalen); addr = addr + datalen; data = (char *)pActData + datalen; GsnFlashCache_BlkFetch(addr, (UINT32)lastData, 4, NULL); pTmp = (char *)lastData; while (remBytes) { *(char *) data = *pTmp++; remBytes--; data = (char *)data + 1; } } #endif #else GsnFlashIf_PioReq(); GsnFlashIf_FlashRead(addr, datalen, data); GsnFlashIf_PioRelease(); #endif return 0; }