nsresult DataStorage::Put(const nsCString& aKey, const nsCString& aValue, DataStorageType aType) { WaitForReady(); MutexAutoLock lock(mMutex); nsresult rv; rv = ValidateKeyAndValue(aKey, aValue); if (NS_FAILED(rv)) { return rv; } Entry entry; bool exists = GetInternal(aKey, &entry, aType, lock); if (exists) { entry.UpdateScore(); } else { MaybeEvictOneEntry(aType, lock); } entry.mValue = aValue; rv = PutInternal(aKey, entry, aType, lock); if (NS_FAILED(rv)) { return rv; } return NS_OK; }
uint32_t SPIFlash::EraseChip (void) { // Wait until the device is ready or a timeout occurs if (WaitForReady()) return 0; // Make sure the chip is write enabled WriteEnable (1); // Make sure the write enable latch is actually set uint8_t status; status = readstatus(); if (!(status & SPIFLASH_STAT_WRTEN)) { // Throw a write protection error (write enable latch not set) return 0; } // Send the erase chip command digitalWrite(_ss, LOW); spiwrite(W25Q16BV_CMD_CHIPERASE); digitalWrite(_ss, HIGH); // Wait until the busy bit is cleared before exiting // This can take up to 10 seconds according to the datasheet! while (readstatus() & SPIFLASH_STAT_BUSY); return 1; }
void CEraser::Start( TFunction aFunction ) // // Start the suspender thread executing function aFunction // { iStop = EFalse; WaitForReady(); iRequestedFunction = aFunction; iGoSignal.Signal(); }
int GetFirmwareVersion(void) { unsigned int prd_no, ver_no; WaitForReady(); vir_pMFC_SFR->RUN_CMD = GET_FW_VER; LOG_MSG(LOG_TRACE, "GetFirmwareVersion ", "GET_FW_VER command was issued.\r\n"); WaitForReady(); prd_no = vir_pMFC_SFR->param.dec_seq_init.RET_SEQ_SUCCESS >> 16; ver_no = (vir_pMFC_SFR->param.dec_seq_init.RET_SEQ_SUCCESS & 0x00FFFF); LOG_MSG(LOG_TRACE, "GetFirmwareVersion", "GET_FW_VER => 0x%X, 0x%X\n", prd_no, ver_no); LOG_MSG(LOG_TRACE, "BUSY_FLAG", "BUSY_FLAG => %d\n", vir_pMFC_SFR->BUSY_FLAG); return vir_pMFC_SFR->param.dec_seq_init.RET_SEQ_SUCCESS; }
void DataStorage::Remove(const nsCString& aKey, DataStorageType aType) { WaitForReady(); MutexAutoLock lock(mMutex); DataStorageTable& table = GetTableForType(aType, lock); table.Remove(aKey); if (aType == DataStorage_Persistent && !mPendingWrite) { unused << AsyncSetTimer(lock); } }
int MFC_Sleep() { // Wait until finish executing command. #if 1 WaitForReady(); #else while( vir_pMFC_SFR->BUSY_FLAG != 0 ) Sleep(1); #endif // Issue Sleep Command. vir_pMFC_SFR->BUSY_FLAG = 0x01; vir_pMFC_SFR->RUN_CMD = 0x0A; #if 1 WaitForReady(); #else while( vir_pMFC_SFR->BUSY_FLAG != 0 ) Sleep(1); #endif return 1; }
int MFC_Wakeup() { // Bit processor gets started. vir_pMFC_SFR->BUSY_FLAG = 0x01; vir_pMFC_SFR->CODE_RUN = 0x01; #if 1 WaitForReady(); #else while( vir_pMFC_SFR->BUSY_FLAG != 0 ) Sleep(1); #endif // Bit processor wakes up. vir_pMFC_SFR->BUSY_FLAG = 0x01; vir_pMFC_SFR->RUN_CMD = 0x0B; #if 1 WaitForReady(); #else while( vir_pMFC_SFR->BUSY_FLAG != 0 ) Sleep(1); #endif return 1; }
void CEraser::CreateL() // // Create new thread and wait for it to become ready // { iGoSignal.CreateLocal( 0 ); // initially blocked iWaitingSignal.CreateLocal( 0 ); // initially blocked iStop = EFalse; User::LeaveIfError( iThread.Create( _L("ERASER"), EraserThread, 2048, 2048, 65536, this ) ); test.Printf( _L("Eraser thread created\n") ); iThread.Resume(); test.Printf( _L("Waiting for thread to become ready\n") ); WaitForReady(); iWaitingSignal.Signal(); }
nsresult DataStorage::Clear() { WaitForReady(); MutexAutoLock lock(mMutex); mPersistentDataTable.Clear(); mTemporaryDataTable.Clear(); mPrivateDataTable.Clear(); // Asynchronously clear the file. This is similar to the permission manager // in that it doesn't wait to synchronously remove the data from its backing // storage either. nsresult rv = AsyncWriteData(lock); if (NS_FAILED(rv)) { return rv; } return NS_OK; }
nsCString DataStorage::Get(const nsCString& aKey, DataStorageType aType) { WaitForReady(); MutexAutoLock lock(mMutex); Entry entry; bool foundValue = GetInternal(aKey, &entry, aType, lock); if (!foundValue) { return EmptyCString(); } // If we're here, we found a value. Maybe update its score. if (entry.UpdateScore()) { PutInternal(aKey, entry, aType, lock); } return entry.mValue; }
uint32_t SPIFlash::EraseSector (uint32_t sectorNumber) { // Make sure the address is valid if (sectorNumber >= W25Q16BV_SECTORS) { return 0; } // Wait until the device is ready or a timeout occurs if (WaitForReady()) return 0; // Make sure the chip is write enabled WriteEnable (1); // Make sure the write enable latch is actually set uint8_t status; status = readstatus(); if (!(status & SPIFLASH_STAT_WRTEN)) { // Throw a write protection error (write enable latch not set) return 0; } // Send the erase sector command uint32_t address = sectorNumber * W25Q16BV_SECTORSIZE; digitalWrite(_ss, LOW); spiwrite(W25Q16BV_CMD_SECTERASE4); spiwrite((address >> 16) & 0xFF); // address upper 8 spiwrite((address >> 8) & 0xFF); // address mid 8 spiwrite(address & 0xFF); // address lower 8 digitalWrite(_ss, HIGH); // Wait until the busy bit is cleared before exiting // This can take up to 400ms according to the datasheet while (readstatus() & SPIFLASH_STAT_BUSY); return 1; }
uint32_t SPIFlash::ReadBuffer (uint32_t address, uint8_t *buffer, uint32_t len) { uint32_t a, i; a = i = 0; // Make sure the address is valid if (address >= W25Q16BV_MAXADDRESS) { return 0; } // Wait until the device is ready or a timeout occurs if (WaitForReady()) return 0; // Send the read data command digitalWrite(_ss, LOW); spiwrite(W25Q16BV_CMD_READDATA); // 0x03 spiwrite((address >> 16) & 0xFF); // address upper 8 spiwrite((address >> 8) & 0xFF); // address mid 8 spiwrite(address & 0xFF); // address lower 8 // Fill response buffer for (a = address; a < address + len; a++, i++) { if (a > W25Q16BV_MAXADDRESS) { // Oops ... we're at the end of the flash memory // return bytes written up until now return i; } buffer[i] = spiread(); } digitalWrite(_ss, HIGH); // Return bytes written return i; }
BOOL MfcIssueCmd(int inst_no, MFC_CODECMODE codec_mode, MFC_COMMAND mfc_cmd) { unsigned int intr_reason; vir_pMFC_SFR->RUN_INDEX = inst_no; if (codec_mode == H263_DEC) { vir_pMFC_SFR->RUN_COD_STD = MP4_DEC; } else if (codec_mode == H263_ENC) { vir_pMFC_SFR->RUN_COD_STD = MP4_ENC; } else { vir_pMFC_SFR->RUN_COD_STD = codec_mode; } switch (mfc_cmd) { case PIC_RUN: vir_pMFC_SFR->RUN_CMD = mfc_cmd; intr_reason = WaitInterruptNotification(); if (intr_reason == WAIT_INT_NOTI_TIMEOUT) { LOG_MSG(LOG_ERROR, "LOG_ERROR", "MfcIssueCmd CMD = %s, WaitInterruptNotification returns TIMEOUT.\n", GetCmdString(mfc_cmd)); return FALSE; } if (intr_reason & 0xC000) { LOG_MSG(LOG_ERROR, "LOG_ERROR", "MfcIssueCmd CMD = %s, BUFFER EMPTY interrupt was raised.\n", GetCmdString(mfc_cmd)); return FALSE; } break; case SEQ_INIT: vir_pMFC_SFR->RUN_CMD = mfc_cmd; intr_reason = WaitInterruptNotification(); if (intr_reason == WAIT_INT_NOTI_TIMEOUT) { LOG_MSG(LOG_ERROR, "LOG_ERROR", "MfcIssueCmd CMD = %s, WaitInterruptNotification returns TIMEOUT.\n", GetCmdString(mfc_cmd)); return FALSE; } if (intr_reason & 0xC000) { LOG_MSG(LOG_ERROR, "LOG_ERROR", "MfcIssueCmd CMD = %s, BUFFER EMPTY interrupt was raised.\n", GetCmdString(mfc_cmd)); return FALSE; } break; case SEQ_END: vir_pMFC_SFR->RUN_CMD = mfc_cmd; intr_reason = WaitInterruptNotification(); if (intr_reason == WAIT_INT_NOTI_TIMEOUT) { LOG_MSG(LOG_ERROR, "LOG_ERROR", "MfcIssueCmd CMD = %s, WaitInterruptNotification returns TIMEOUT.\n", GetCmdString(mfc_cmd)); return FALSE; } if (intr_reason & 0xC000) { LOG_MSG(LOG_ERROR, "LOG_ERROR", "MfcIssueCmd CMD = %s, BUFFER EMPTY interrupt was raised.\n", GetCmdString(mfc_cmd)); return FALSE; } break; default: if (WaitForReady() == FALSE) { LOG_MSG(LOG_ERROR, "LOG_ERROR", "MfcIssueCmd CMD = %s, BitProcessor is busy before issuing the command.\n", GetCmdString(mfc_cmd)); return FALSE; } vir_pMFC_SFR->RUN_CMD = mfc_cmd; WaitForReady(); } return TRUE; }
inline void WaitForDone() { WaitForReady(); iWaitingSignal.Signal(); // resignal, ready for next Start() };
int main(int argc, char* argv[]) { char str[100]; KM = new CKMotionDLL(0); // create as board 0 char response[MAX_LINE]; if(KM->CheckKMotionVersion()){ printf("Version check failed\n"); exit(1); } if(KM->SetConsoleCallback(console)){ printf("Faild to register console callback\n"); } if (KM->KMotionLock() == KMOTION_LOCKED) // see if we can get access { // Get the firmware date from the KMotion Card which // will be in PT (Pacific Time) KM->ReleaseToken(); if(KM->WriteLineReadLine("Version",response)){ printf("Version check failed\n"); exit(1); } else { printf("Version: %s\n",response); } } else { printf("Failed to get lock\n"); exit(1); } KM->ServiceConsole(); printf("Connected.\n"); while(printf(">"), fgets(str, 100, stdin), !feof(stdin)) { if(strncmp(str,"exit",4) == 0){ break; } str[strlen(str) - 1] = '\0'; if(KM->ServiceConsole()){ printf(">ServiceConsole Failed\n"); } if(strlen(str) > 1){ if (KM->KMotionLock() == KMOTION_LOCKED) // see if we can get access { // send command if(KM->WriteLineWithEcho(str)){ printf(">Command failed\n"); exit(1); } // print all responses until we receive "Ready" if (WaitForReady(5000)) { KM->ReleaseToken(); printf("Timeout waiting for Ready\n"); exit(1); } KM->ReleaseToken(); } else { printf("Failed to get lock\n"); exit(1); } } } return 0; }
uint32_t SPIFlash::WritePage (uint32_t address, uint8_t *buffer, uint32_t len) { uint8_t status; uint32_t i; // Make sure the address is valid if (address >= W25Q16BV_MAXADDRESS) { return 0; } // Make sure that the supplied data is no larger than the page size if (len > W25Q16BV_PAGESIZE) { return 0; } // Make sure that the data won't wrap around to the beginning of the sector if ((address % W25Q16BV_PAGESIZE) + len > W25Q16BV_PAGESIZE) { // If you try to write to a page beyond the last byte, it will // wrap around to the start of the page, almost certainly // messing up your data return 0; } // Wait until the device is ready or a timeout occurs if (WaitForReady()) return 0; // Make sure the chip is write enabled WriteEnable (1); // Make sure the write enable latch is actually set status = readstatus(); if (!(status & SPIFLASH_STAT_WRTEN)) { // Throw a write protection error (write enable latch not set) return 0; } // Send page write command (0x02) plus 24-bit address digitalWrite(_ss, LOW); spiwrite(W25Q16BV_CMD_PAGEPROG); // 0x02 spiwrite((address >> 16) & 0xFF); // address upper 8 spiwrite((address >> 8) & 0xFF); // address mid 8 if (len == 256) { // If len = 256 bytes, lower 8 bits must be 0 (see datasheet 11.2.17) spiwrite(0); } else { spiwrite(address & 0xFF); // address lower 8 } // Transfer data for (i = 0; i < len; i++) { spiwrite(buffer[i]); } // Write only occurs after the CS line is de-asserted digitalWrite(_ss, HIGH); // Wait at least 3ms (max page program time according to datasheet) delay(3); // Wait until the device is ready or a timeout occurs if (WaitForReady()) return 0; return len; }