// ask for a byte, wait for it arrive, and return it unsigned char HMC5843::receiveByte(void) { waitForReady(); TWCR = ((TWCR&0x0F)|(1<<TWINT)|(1<<TWEA)); waitForReady(); return(TWDR); }
int main(int argc, char *argv[]) { // kdeinit waits for kcminit to finish, but during KDE startup // only important kcm's are started very early in the login process, // the rest is delayed, so fork and make parent return after the initial phase pipe( ready ); if( fork() != 0 ) { waitForReady(); return 0; } close( ready[ 0 ] ); startup = ( strcmp( argv[ 0 ], "kcminit_startup" ) == 0 ); // started from startkde? KAboutData aboutData( "kcminit", "kcminit", ki18n("KCMInit"), "", ki18n("KCMInit - runs startup initialization for Control Modules.")); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineOptions options; options.add("list", ki18n("List modules that are run at startup")); options.add("+module", ki18n("Configuration module to run")); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KApplication app; QDBusConnection::sessionBus().interface()->registerService( "org.kde.kcminit", QDBusConnectionInterface::DontQueueService ); KLocale::setMainCatalog(0); KCMInit kcminit( KCmdLineArgs::parsedArgs()); return 0; }
usbMsgLen_t nrfTest() { if (!waitForReady()) { usbOutputBuffer[0] = ERROR_READY_WAIT; usbOutputBuffer[1] = usbOutputBuffer[2] = usbOutputBuffer[3] = readStatus(); return 4; } spiEnable(); usbOutputBuffer[1] = readStatus(); spiDisable(); spiEnable(); spiReadWriteByte(SPICMD_WREN); spiDisable(); spiEnable(); usbOutputBuffer[2] = readStatus(); spiDisable(); spiEnable(); spiReadWriteByte(SPICMD_WRDIS); spiDisable(); spiEnable(); usbOutputBuffer[3] = readStatus(); spiDisable(); if (!(usbOutputBuffer[1] & FSR_WEN) && (usbOutputBuffer[2] & FSR_WEN) && !(usbOutputBuffer[3] & FSR_WEN)) { usbOutputBuffer[0] = ERROR_OK; } else { usbOutputBuffer[0] = ERROR_WEN_TEST_FAILED; } return 4; }
/* Identify valid blocks */ bool checkBadBlock(uint32_t block) { uint8_t valid; lpc_nandflash_read_start(block, 0, K9F1G_SPARE_START_ADDR); waitForReady(); lpc_nandflash_read_data(&valid, 1); return (bool) (valid != 0xFF); }
usbMsgLen_t programPage(uint16_t page, uint16_t len) { if (page > 31) { return 0; } if (!waitForReady()) { return 0; } currentPage = page; writeBytesRemaining = len; reading = 0; return USB_NO_MSG; }
usbMsgLen_t erasePage(uint8_t page) { if (page > 31) { return 0; } if (!waitForReady()) { return 0; } if (!enableWrite()) { return 0; } spiEnable(); spiReadWriteByte(SPICMD_ERASEPAGE); spiReadWriteByte(page); spiDisable(); waitWenIsCleared(); return 0; }
/** * @brief Main routine for example_nandflash * @return Nothing */ int main(void) { K9F1G_ID_T nandId; const lpc_nandflash_size_t *flashInfo; uint32_t stSize, useBlock = BLOCK_INDEX; volatile int loop = 1, idx; /* For debug message only */ SystemCoreClockUpdate(); Board_Init(); Board_NANDFLash_Init(); lpc_nandflash_init(); /* Read flash information */ flashInfo = lpc_nandflash_get_size(); lpc_nandflash_get_id((uint8_t*)&nandId); DEBUGOUT(" Flash Information: \r\n"); DEBUGOUT(" Manufacturer ID: 0x%02x\r\n", nandId.MarkerCode); DEBUGOUT(" Device ID: 0x%02x\r\n", nandId.DeviceCode); DEBUGOUT(" Page Size: %dB\r\n", flashInfo->page_size); DEBUGOUT(" Spare Size: %dB\r\n", flashInfo->spare_size); DEBUGOUT(" Block Size: %dKB\r\n", flashInfo->pages_per_block*flashInfo->page_size/1024); DEBUGOUT(" Block count: %d\r\n", flashInfo->block_cnt); /* Show bad block list */ DEBUGOUT("Checking bad blocks...\r\n"); for (idx = 0; idx < flashInfo->block_cnt; idx++) { if (checkBadBlock(idx)) { DEBUGOUT(" Bad block at %d\r\n", idx); if (useBlock == idx) { /* Skip to next block for the example if this one is bad */ useBlock++; } } } /* Read data */ lpc_nandflash_read_start(useBlock, PAGE_INDEX, 0); waitForReady(); lpc_nandflash_read_data((uint8_t *) buffer, BUFFER_SIZE); /* Check and display string if it exists */ ShowString((char *) buffer); /* Get a string to save */ stSize = MakeString((uint8_t *) buffer); /* Erase flash */ lpc_nandflash_erase_block(useBlock); waitForReady(); /* Check the result of erasing */ if(lpc_nandflash_read_status() & NANDFLASH_STATUS_BLOCK_ERASE_FAIL) { DEBUGSTR("Erase failed!!!\r\n"); while(1){} } /* Write header + size + data to page */ DEBUGSTR("\r\nWrite to flash...\r\n"); lpc_nandflash_write_page(useBlock, PAGE_INDEX,(uint8_t *) buffer, (4 + stSize)); waitForReady(); /* Check the result of writting */ if(lpc_nandflash_read_status() & NANDFLASH_STATUS_PAGE_PROG_FAIL) { DEBUGSTR("Writing failed!!!\r\n"); while(1){} } DEBUGSTR("Reading back string...\r\n"); /* Read all data from flash */ lpc_nandflash_read_start(useBlock, PAGE_INDEX, 0); waitForReady(); lpc_nandflash_read_data((uint8_t *) buffer, BUFFER_SIZE); /* Check and display string if it exists */ ShowString((char *) buffer); /* Wait forever */ while (loop) {} return 0; }
// send a byte when the channel is ready void HMC5843::sendByte(unsigned char data) { waitForReady(); TWDR = data; TWCR = (1<<TWINT)|(1<<TWEN); }
// close i2c void HMC5843::sendStop(void) { waitForReady(); TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO); }
// get status register. the bits 0 and 1 are zeroed in init. see datasheet unsigned char HMC5843::readStatus() { waitForReady(); return(TWSR); }
/** * Calls runLoop until the _isReady flag has been set - or until 100 ms has passed. Returns the value of _isReady */ bool BMDSmartViewClient::waitForReady() { return waitForReady(100); }
/** * Calls runLoop until the isReady() flag has been set - or until 100 ms has passed. Returns the value of isReady() */ bool ClientBMDSmartView::waitForReady() { return waitForReady(100); }