int stm32_flash_erase(uint32_t offset, uint16_t len) { uint32_t StartSector, EndSector; uint32_t flash_user_start_addr, flash_user_end_addr; uint32_t addr; uint8_t i; /* Get the number of the start and end sectors */ flash_user_start_addr = ADDR_FLASH_SECTOR_0 + offset; flash_user_end_addr = flash_user_start_addr + len; StartSector = GetSector(flash_user_start_addr); EndSector = GetSector(flash_user_end_addr); /* Erase sector */ for (i = StartSector; i <= EndSector; i += 8) { /* Device voltage range supposed to be [2.7V to 3.6V], the operation will be done by word */ if (FLASH_EraseSector(i, VoltageRange_3) != FLASH_COMPLETE) { return -1; } } return 0; }
/** *@Destructor that deallocates all memory allocated by this class */ BlockEntity::~BlockEntity() { if (GetSector() != nullptr && GetSector()->As<SectorTetromino>()) { GetSector()->As<SectorTetromino>()->RemoveBlock(this); } uint32_t i = 0; //searches a static vector for this instance of BlockEntity for (i = 0; i < blocks.size(); ++i) { if (blocks[i] == this) { break; } } //remove it from the static vector. if (i < blocks.size()) { blocks.erase(blocks.begin() + i); } //Unsubscribe so that on Event Dispatch, it doesn't point to a garbage location. Event<EventMessageAttributed>::Unsubscribe(this); }
//============================================================================= // eFdd::AddFile //----------------------------------------------------------------------------- bool eFdd::AddFile(const byte* hdr, const byte* data) { eUdi::eTrack::eSector* s = GetSector(0, 0, 9); if(!s) return false; int len = hdr[13]; int pos = s->data[0xe4] * 0x10; eUdi::eTrack::eSector* dir = GetSector(0, 0, 1 + pos / 0x100); if(!dir) return false; if(SectorDataW(s, 0xe5) < len) //disk full return false; memcpy(dir->data + (pos & 0xff), hdr, 14); SectorDataW(dir, (pos & 0xff) + 14, SectorDataW(s, 0xe1)); UpdateCRC(dir); pos = s->data[0xe1] + 16 * s->data[0xe2]; s->data[0xe1] = (pos + len) & 0x0f, s->data[0xe2] = (pos + len) >> 4; s->data[0xe4]++; SectorDataW(s, 0xe5, SectorDataW(s, 0xe5) - len); UpdateCRC(s); // goto next track. s8 become invalid for(int i = 0; i < len; ++i, ++pos) { int cyl = pos / 32; int side = (pos / 16) & 1; if(!WriteSector(cyl, side, (pos & 0x0f) + 1, data + i * 0x100)) return false; } return true; }
/** *Advances our block to the next rotation state */ void BlockEntity::AdvanceState() { mState = (mState + 1) % STATES; lastDirection = "Rotate"; if (!CheckCollisions().empty()) { GetSector()->As<SectorTetromino>()->mUndoRotate = true; } else { GetSector()->As<SectorTetromino>()->mPlayRotate = true; } }
SGridLocation* CPartitionGrid::Rellocate( SGridLocation* obj,const Vec3 &newPos,CEntity* pEntity ) { FUNCTION_PROFILER(GetISystem(),PROFILE_ENTITY); if (m_bResetting) { return 0; } if (obj) { LocationInfo from,to; GetSector(obj->nSectorIndex,from); GetSector(newPos,to); if (from.sector != to.sector) { // Relink object between sectors. SectorUnlink( obj,from ); if (to.sector) { SectorLink( obj,to ); if (from.group && from.group->nLocationCount <= 0) FreeGroup(from); } else { FreeLocation(obj); obj = 0; } } } else if (fabs(newPos.x) > 0.1f || fabs(newPos.y) > 0.1f) { // Allocate a new sector location. LocationInfo to; GetSector(newPos,to); if (to.sector) { obj = AllocateLocation(); obj->pEntity = pEntity; if (pEntity) { obj->pEntityClass = pEntity->GetClass(); obj->nEntityFlags = pEntity->GetFlags(); } SectorLink( obj,to ); } } return obj; }
unsigned CFAT::AllocateCluster (void) { m_Lock.Acquire (); assert (m_pFATInfo != 0); unsigned nCluster = m_pFATInfo->GetNextFreeCluster (); while (nCluster < m_pFATInfo->GetClusterCount () + 2) { assert (nCluster >= 2); unsigned nSectorOffset; TFATBuffer *pBuffer = GetSector (nCluster, &nSectorOffset, m_pFATInfo->GetReadFAT ()); assert (pBuffer != 0); unsigned nClusterEntry = GetEntry (pBuffer, nSectorOffset); assert (m_pCache != 0); m_pCache->FreeSector (pBuffer, 1); if (nClusterEntry == 0) { for (unsigned nFAT = m_pFATInfo->GetFirstWriteFAT (); nFAT <= m_pFATInfo->GetLastWriteFAT (); nFAT++) { pBuffer = GetSector (nCluster, &nSectorOffset, nFAT); assert (pBuffer != 0); SetEntry (pBuffer, nSectorOffset, m_pFATInfo->GetFATType () == FAT16 ? 0xFFFF : 0x0FFFFFFF); m_pCache->MarkDirty (pBuffer); m_pCache->FreeSector (pBuffer, 1); } m_pFATInfo->ClusterAllocated (nCluster); m_Lock.Release (); return nCluster; } nCluster++; } m_Lock.Release (); return 0; }
void EraseFlash(uint32_t Address) { int sector = GetSector(Address); /* Device voltage range supposed to be [2.7V to 3.6V], the operation will be done by word */ FLASH_Erase_Sector(sector, FLASH_VOLTAGE_RANGE_3); }
void CD16Image::InitImage() { if (bam != NULL) delete bam; bam = GetSector(1, 1); // Bam of an HD Image seems to start at $100 bamStart = GetSectorOffset(1, 1); }
/** * @brief This function does an erase of all user flash area * @param StartSector: start of user flash area * @retval 0: user flash area successfully erased * 1: error occurred */ uint32_t FLASH_If_Erase(uint32_t StartSector) { uint32_t UserStartSector; uint32_t SectorError; FLASH_EraseInitTypeDef pEraseInit; /* Unlock the Flash to enable the flash control register access *************/ FLASH_If_Init(); /* Get the sector where start the user flash area */ UserStartSector = GetSector(APPLICATION_ADDRESS); pEraseInit.TypeErase = TYPEERASE_SECTORS; pEraseInit.Sector = UserStartSector; pEraseInit.NbSectors = 6; pEraseInit.VoltageRange = VOLTAGE_RANGE_3; if (HAL_FLASHEx_Erase(&pEraseInit, &SectorError) != HAL_OK) { /* Error occurred while page erase */ return (1); } return (0); }
//============================================================================= // eFdd::ReadScl //----------------------------------------------------------------------------- bool eFdd::ReadScl(const void* data, size_t data_size) { if(data_size < 9) return false; const byte* buf = (const byte*)data; if(memcmp(data, "SINCLAIR", 8) || int(data_size) < 9 + (0x100 + 14)*buf[8]) return false; CreateTrd(); int size = 0; for(int i = 0; i < buf[8]; ++i) { size += buf[9 + 14 * i + 13]; } if(size > 2544) { eUdi::eTrack::eSector* s = GetSector(0, 0, 9); SectorDataW(s, 0xe5, size); // free sec UpdateCRC(s); } const byte* d = buf + 9 + 14 * buf[8]; for(int i = 0; i < buf[8]; ++i) { if(!AddFile(buf + 9 + 14*i, d)) return false; d += buf[9 + 14*i + 13]*0x100; } return true; }
//컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴 //Procedure addtoworld //------------------------------------------------------------------------------ //Author Paul. //Date Wed 30 Aug 1995 //Modified // //Description Adds an item to the sector list // //Inputs // //Returns // //Externals //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void WorldStuff::AddToWorld(itemptr item) { UWord sector_number; sector_number = GetSector(item); #ifndef NDEBUG //CSB 9Aug00 #define CHECKNOTINLIST //CSB 9Aug00 #ifdef CHECKNOTINLIST //CSB 9Aug00 for(itemptr listitem = sectorlist[sector_number]; listitem; listitem = listitem->Next) //CSB 9Aug00 if(listitem == item) //CSB 9Aug00 INT3; //ITEM IS ALREADY IN THIS SECTOR LIST //CSB 9Aug00 #endif //CSB 9Aug00 #endif //CSB 9Aug00 if(sectorlist[sector_number]==(itemptr )NULL) { //First in the list sectorlist[sector_number] = item; item->Next = (itemptr )NULL; } else { //There are already some items in the list item->Next = sectorlist[sector_number]; sectorlist[sector_number] = item; } }
/** * @brief Erases sector. * @param Add: Address of sector to be erased. * @retval 0 if operation is successful, MAL_FAIL else. */ uint16_t Flash_If_Erase(uint32_t Add) { uint32_t startsector = 0, sectorerror = 0, nbofsectors = 0; /* Variable contains Flash operation status */ HAL_StatusTypeDef status; FLASH_EraseInitTypeDef eraseinitstruct; /* Get the number of sector */ startsector = GetSector(Add); /* Get the number of sector to erase from the start sector: max number of sectors - value of Initial sector */ nbofsectors = (USBD_DFU_MAX_NB_OF_SECTORS - startsector); eraseinitstruct.TypeErase = FLASH_TYPEERASE_SECTORS; eraseinitstruct.Banks = 0; eraseinitstruct.Sector = startsector; eraseinitstruct.NbSectors = nbofsectors; eraseinitstruct.VoltageRange = FLASH_VOLTAGE_RANGE_3; status = HAL_FLASHEx_Erase(&eraseinitstruct, §orerror); if (status != HAL_OK) { return 1; } return 0; }
void ClipLine( POINT &Start, POINT &End ) { INT32 ThisSector = GetSector( End ) ; switch ( CaseTable[(INT32)LastSector][(INT32)ThisSector] ) { case 01 : GenLineToBelowLeft() ; break ; case 02 : GenLineToBelowRight() ; break ; case 03 : GenLineToAboveLeft() ; break ; case 04 : GenLineToAboveRight() ; break ; case 05 : GenLine(Start) ; GenLine(End) ; break ; case 06 : if ( OFirstPoint ) GenLine(Start) ; GenLine(End) ; break ; case 07 : POINT Middle ; Middle.x = (Start.x+End.x) >> 1 ; Middle.y = (Start.y+End.y) >> 1 ; ClipLine( Start,Middle ) ; ClipLine( Middle,End ) ; return ; case 10 : GenLineToBelowLeft() ; GenLineToBelowRight() ; break ; case 11 : GenLineToBelowLeft() ; GenLineToAboveLeft() ; break ; case 12 : GenLineToBelowRight() ; GenLineToAboveRight() ; break ; case 13 : GenLineToBelowRight() ; GenLineToBelowLeft() ; break ; case 14 : GenLineToAboveLeft() ; GenLineToAboveRight() ; break ; case 15 : GenLineToAboveLeft() ; GenLineToBelowLeft() ; break ; case 16 : GenLineToAboveRight() ; GenLineToBelowRight() ; break ; case 17 : GenLineToAboveRight() ; GenLineToAboveLeft() ; break ; } LastSector = ThisSector ; }
/** * @brief Main program * @param None * @retval None */ ErrorStatus eep_erase( void ) { ErrorStatus Err = SUCCESS; /* Enable the flash control register access */ FLASH_Unlock(); /* Erase the user Flash area ************************************************/ /* area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR */ /* Clear pending flags (if any) */ FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); /* Get the number of the start and end sectors */ uwStartSector = GetSector(FLASH_USER_START_ADDR); /* Device voltage range supposed to be [2.7V to 3.6V], the operation will be done by word */ if (FLASH_EraseSector(uwStartSector, VoltageRange_3) != FLASH_COMPLETE) { /* Error occurred while sector erase. User can add here some code to deal with this error */ Err = ERROR; } FLASH_Lock(); return Err; }
void CD16Image::InitBAM(int track, int sector) { if (bam != NULL) delete bam; bam = NULL; bam = GetSector(track, sector); bamStart = GetSectorOffset(track, sector); }
void csMeshGenerator::SelfDestruct () { if (GetSector ()) { size_t c = GetSector ()->GetMeshGeneratorCount (); while (c > 0) { c--; if (GetSector ()->GetMeshGenerator (c) == (iMeshGenerator*)this) { GetSector ()->RemoveMeshGenerator (c); return; } } CS_ASSERT (false); } }
///////////////////////////////////////////////////////// // Description: // flush one sector in ram buffer (full of 0) to hardware storage // // Input: // sectorIndex // // output: // // Remarks: // // Returns: void FAT_SectorCache::EraseSector( UINT32 sectorIndex ) { BYTE* sector = GetSector( sectorIndex, TRUE ); if(sector) { memset( sector, 0, m_bytesPerSector ); } }
int flashErase(uint32_t startAddr, uint32_t len) { FLASH_Status status; unsigned int retries; int ret; uint32_t startSector, endSector; uint32_t i; if (startAddr == 0) startAddr = FLASH_START_ADDR; FLASH_Unlock(); // Clear pending flags (if any) FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR); ret = 1; startSector = GetSector(startAddr); endSector = GetSector(startAddr + len*4); i = startSector; while (i <= endSector) { retries = 0; do { // Device voltage range supposed to be [2.7V to 3.6V], the operation will be done by word status = FLASH_EraseSector(i, VoltageRange_3); retries++; } while (status != FLASH_COMPLETE && retries < FLASH_RETRIES); if (retries == FLASH_RETRIES) { ret = 0; break; } if (i == FLASH_Sector_11) i += 40; else i += 8; } FLASH_Lock(); return ret; }
//============================================================================= // eUdi::eTrack::WriteSector //----------------------------------------------------------------------------- bool eUdi::eTrack::WriteSector(int sec, const byte* data) { eUdi::eTrack::eSector* s = GetSector(sec); if(!s || !s->data) return false; int len = s->Len(); memcpy(s->data, data, len); s->UpdateCRC(); return true; }
//============================================================================= // eFdd::WriteSector //----------------------------------------------------------------------------- bool eFdd::WriteSector(int cyl, int side, int sec, const byte* data) { eUdi::eTrack::eSector* s = GetSector(cyl, side, sec); if(!s || !s->data) return false; int len = s->Len(); memcpy(s->data, data, len); UpdateCRC(s); return true; }
bool CTeleport::RealizeTeleport() { ADDTOCALLSTACK("CTeleport::RealizeTeleport"); if ( !IsValidPoint() || !m_ptDst.IsValidPoint() ) { DEBUG_ERR(("Bad teleport coords %s\n", WriteUsed())); return false; } CSector *pSector = GetSector(); return pSector ? pSector->AddTeleport(this) : false; }
size_t CPointBase::GetRegions( DWORD dwType, CRegionLinks & rlinks ) const { ADDTOCALLSTACK("CPointBase::GetRegions"); if ( !IsValidPoint() ) return 0; CSector *pSector = GetSector(); if ( pSector ) return pSector->GetRegions(*this, dwType, rlinks); return 0; }
void ClipCurve( POINT &C0, POINT &C1, POINT &C2, POINT &C3 ) { INT32 C1Sector = GetSector( C1 ) ; INT32 C2Sector = GetSector( C2 ) ; INT32 ThisSector = GetSector( C3 ) ; // if ( ( ( C1Sector==LastSector || C1Sector==ThisSector ) && // ( C2Sector==LastSector || C2Sector==ThisSector ) ) || // ( Region[LastSector] & Region[C1Sector] & Region[C2Sector] & Region[ThisSector] ) ) INT32 RegionUnion = Region[LastSector] & Region[C1Sector] & Region[C2Sector] & Region[ThisSector]; if ( ( RegionUnion & 0x0ff ) || ( (RegionUnion & 0x300) && (LastSector!=ThisSector || LastSector==12) ) || ( (C1Sector==LastSector || C1Sector==ThisSector) && (C2Sector==LastSector || C2Sector==ThisSector) ) ) { switch ( CaseTable[(INT32)LastSector][(INT32)ThisSector] ) { case 01 : GenLineToBelowLeft() ; break ; case 02 : GenLineToBelowRight() ; break ; case 03 : GenLineToAboveLeft() ; break ; case 04 : GenLineToAboveRight() ; break ; case 05 : GenLine(C0,FALSE) ; GenCurve(C1,C2,C3) ; break ; case 06 : if ( OFirstPoint ) GenLine(C0,FALSE) ; GenCurve(C1,C2,C3) ; break ; case 07 : SplitCurve(C0,C1,C2,C3) ; return ; case 10 : GenLineToBelowLeft() ; GenLineToBelowRight() ; break ; case 11 : GenLineToBelowLeft() ; GenLineToAboveLeft() ; break ; case 12 : GenLineToBelowRight() ; GenLineToAboveRight() ; break ; case 13 : GenLineToBelowRight() ; GenLineToBelowLeft() ; break ; case 14 : GenLineToAboveLeft() ; GenLineToAboveRight() ; break ; case 15 : GenLineToAboveLeft() ; GenLineToBelowLeft() ; break ; case 16 : GenLineToAboveRight() ; GenLineToBelowRight() ; break ; case 17 : GenLineToAboveRight() ; GenLineToAboveLeft() ; break ; } LastSector = ThisSector ; } else SplitCurve(C0,C1,C2,C3) ; }
void psLinearMovement::GetLastFullPosition (csVector3& pos, float& yrot, iSector*& sector) { if (!mesh) return; // Position pos = GetFullPosition (); // rotation yrot = GetYRotation (); // Sector sector = GetSector (); }
/*------------------------------------------------------------ * Function Name : SD_EraseFlashOperation * Description : 擦除flash操作 * Input : None * Output : None * Return : None *------------------------------------------------------------*/ ErrorStatus SD_EraseFlashOperation( uint16_t x, uint16_t y ) { ErrorStatus Err = SUCCESS; uint32_t addr = 0; const uint8_t ERASE_FLASH_NUM = 3; const uint32_t erase_addr[ERASE_FLASH_NUM] = {ADDR_FLASH_SECTOR_5,ADDR_FLASH_SECTOR_6,ADDR_FLASH_SECTOR_7}; uint8_t i = 0; char buff[10]; uint8_t process = 0; lcd_font24(x,y,COLOR_POINT,COLOR_BACK,"> 正在擦除flash...",UPDATE_FONT); x += 216; /* Enable the flash control register access */ FLASH_Unlock(); /* Erase the user Flash area ************************************************/ /* area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR */ /* Clear pending flags (if any) */ FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); for (i=0; i<ERASE_FLASH_NUM; ++i) { /* Get the number of the start and end sectors */ addr = GetSector(erase_addr[i]); /* Device voltage range supposed to be [2.7V to 3.6V], the operation will be done by word */ if (FLASH_EraseSector(addr, VoltageRange_3) != FLASH_COMPLETE) { /* Error occurred while sector erase. User can add here some code to deal with this error */ Err = ERROR; break; } process += 30; usprintf(buff,"%3d%%",process); lcd_font24(x,y,COLOR_POINT,COLOR_BACK,buff,UPDATE_FONT); } bsp_DelayMS(DELAY_TIME); lcd_font24(x,y,COLOR_POINT,COLOR_BACK,"100%",UPDATE_FONT); FLASH_Lock(); return Err; }
bool CTeleport::RealizeTeleport() { ADDTOCALLSTACK("CTeleport::RealizeTeleport"); if ( ! IsCharValid() || ! m_ptDst.IsCharValid()) { DEBUG_ERR(( "CTeleport bad coords %s\n", WriteUsed() )); return false; } CSector *pSector = GetSector(); if ( pSector ) return pSector->AddTeleport(this); else return false; }
CRegionBase * CPointBase::GetRegion( DWORD dwType ) const { ADDTOCALLSTACK("CPointBase::GetRegion"); // What region in the current CSector am i in ? // We only need to update this every 8 or so steps ? // REGION_TYPE_AREA if ( ! IsValidPoint()) return NULL; CSector *pSector = GetSector(); if ( pSector ) return pSector->GetRegion(*this, dwType); return NULL; }
void CPartitionGrid::FreeLocation( SGridLocation* obj ) { if (obj && !m_bResetting) { LocationInfo locInfo; GetSector(obj->nSectorIndex,locInfo); if (locInfo.sector) { SectorUnlink( obj,locInfo ); if (locInfo.group->nLocationCount <= 0) FreeGroup(locInfo); } delete obj; } }
HAL_StatusTypeDef FlashInit(void) { HAL_StatusTypeDef res; /* Unlock the Flash to enable the flash control register access *************/ res = HAL_FLASH_Unlock(); /* Clear pending flags (if any) */ __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); /* Get the number of the start and end sectors */ StartSector = GetSector(FLASH_USER_START_ADDR); EndSector = GetSector(FLASH_USER_END_ADDR); /* Lock the Flash to disable the flash control register access (recommended to protect the FLASH memory against possible unwanted operation) *********/ if(res == 0) printf("flash success!\r\n"); else printf("flash error:%d\r\n",res); return res; }
bool eFdd::BootExist() { for(int i = 0; i < 9; ++i) { const eUdi::eTrack::eSector* s = GetSector(0, 0, i); if(!s) continue; const byte* ptr = s->data; const char* b = boot_sign; for(; (ptr = (const byte*)memchr(ptr, *b, s->Len() - (ptr - s->data))) != NULL; ++b) { if(!*b) return true; } } return false; }