コード例 #1
0
ファイル: main.cpp プロジェクト: m-liu/bluedbm
int main(int argc, const char **argv)
{
	FlashRequestProxy *device = 0;
	DmaConfigProxy *dmap = 0;

	FlashIndication *deviceIndication = 0;
	DmaIndication *dmaIndication = 0;

	if(sem_init(&done_sem, 1, 0)){
		fprintf(stderr, "failed to init done_sem\n");
		exit(1);
	}

	fprintf(stderr, "%s %s\n", __DATE__, __TIME__);

	device = new FlashRequestProxy(IfcNames_FlashRequest);
	dmap = new DmaConfigProxy(IfcNames_DmaConfig);
	DmaManager *dma = new DmaManager(dmap);

	deviceIndication = new FlashIndication(IfcNames_FlashIndication);
	dmaIndication = new DmaIndication(dma, IfcNames_DmaIndication);

	fprintf(stderr, "Main::allocating memory...\n");

	for ( int i = 0; i < DMA_BUFFER_COUNT; i++ ) {
		srcAllocs[i] = portalAlloc(walloc_sz);
		dstAllocs[i] = portalAlloc(ralloc_sz);
		srcBuffers[i] = (unsigned int *)portalMmap(srcAllocs[i], walloc_sz);
		dstBuffers[i] = (unsigned int *)portalMmap(dstAllocs[i], ralloc_sz);
	}
	portalExec_start();
	for ( int i = 0; i < DMA_BUFFER_COUNT; i++ ) {
		portalDCacheFlushInval(srcAllocs[i], walloc_sz, srcBuffers[i]);
		portalDCacheFlushInval(dstAllocs[i], ralloc_sz, dstBuffers[i]);
		ref_srcAllocs[i] = dma->reference(srcAllocs[i]);
		ref_dstAllocs[i] = dma->reference(dstAllocs[i]);
	}

	// Storage system init /////////////////////////////////
	curWritesInFlight = 0;
	curCmdCountBudget = 0;
	pthread_mutex_init(&freeListMutex, NULL);
	pthread_cond_init(&freeListCond, NULL);
	pthread_mutex_init(&flashReqMutex, NULL);
	pthread_mutex_init(&cmdReqMutex, NULL);
	pthread_cond_init(&flashReqCond, NULL);
	pthread_cond_init(&cmdReqCond, NULL);

	for ( int i = 0; i < DMA_BUFFER_COUNT; i++ ) {
		for ( int j = 0; j < WRITE_BUFFER_WAYS; j++ ) {
			int idx = i*WRITE_BUFFER_WAYS+j;
			srcBufferBusy[idx] = false;

			int offset = j*1024*16;
			device->addWriteHostBuffer(ref_srcAllocs[i], offset, idx);
			writeBuffers[idx] = srcBuffers[i] + (offset/sizeof(unsigned int));
		}
	}
	for ( int i = 0; i < DMA_BUFFER_COUNT; i++ ) {
		for ( int j = 0; j < READ_BUFFER_WAYS; j++ ) {
			int idx = i*READ_BUFFER_WAYS+j;

			int offset = j*1024*16;
			device->addReadHostBuffer(ref_dstAllocs[i], offset, idx);
			readBuffers[idx] = dstBuffers[i] + (offset/sizeof(unsigned int));
		}
	}
	for ( int i = 0; i > TAG_COUNT; i++ ) {
		readTagBusy[i] = false;
	}

	pthread_t ftid;
	pthread_create(&ftid, NULL, return_finished_readbuffer, (void*)device);
	/////////////////////////////////////////////////////////

	fprintf(stderr, "Main::flush and invalidate complete\n");
  
	clock_gettime(CLOCK_REALTIME, & deviceIndication->aurorastart);
	device->sendTest(LARGE_NUMBER*1024);

	for ( int j = 0; j < WRITE_BUFFER_COUNT; j++ ) {
		for ( int i = 0; i < (8192+64)/4; i++ ) {
			writeBuffers[j][i] = i;
		}
	}
	for ( int j = 0; j < READ_BUFFER_COUNT; j++ ) {
		for ( int i = 0; i < (8192+64)/4; i++ ) {
			readBuffers[j][i] = 8192/4-i;
		}
	}
	device->start(0);

	timespec start, now;


	printf( "writing pages to flash!\n" );
	clock_gettime(CLOCK_REALTIME, & start);
	for ( int i = 0; i < LARGE_NUMBER/4; i++ ) {
		for ( int j = 0; j < 4; j++ ) {
			if ( i % 1024 == 0 ) 
				printf( "writing page %d\n", i );
			writePage(device, j,0,0,i,waitIdleWriteBuffer());
		}
	}
	printf( "waiting for writing pages to flash!\n" );
	while ( getNumWritesInFlight() > 0 ) usleep(1000);
	clock_gettime(CLOCK_REALTIME, & now);
	printf( "finished writing to page! %f\n", timespec_diff_sec(start, now) );

	printf( "wrote pages to flash!\n" );
  

	clock_gettime(CLOCK_REALTIME, & start);
	for ( int i = 0; i < LARGE_NUMBER/4; i++ ) {
		for ( int j = 0; j < 4; j++ ) {

			readPage(device, j,0,0,i);
			if ( i % 1024 == 0 ) 
				printf( "reading page %d\n", i );
		}
	}
	
	printf( "trying reading from page!\n" );

	while (true) {
	/*
		pthread_mutex_lock(&freeListMutex);
		bufferId bid = popReadyReadBuffer();
		int rrb = bid.bufidx;
		while (rrb >= 0 ) {
			setFinishedReadBuffer(rrb);
			rrb = popReadyReadBuffer().bufidx;
		}

		flushFinishedReadBuffers(device);
		pthread_cond_wait(&freeListCond, &freeListMutex);
		pthread_mutex_unlock(&freeListMutex);
		*/

		usleep(100);
		if ( getNumReadsInFlight() == 0 ) break;
	}
	clock_gettime(CLOCK_REALTIME, & now);
	printf( "finished reading from page! %f\n", timespec_diff_sec(start, now) );

	for ( int i = 0; i < (8192+64)/4; i++ ) {
		for ( int j = 0; j < READ_BUFFER_COUNT; j++ ) {
			if ( i > (8192+64)/4 - 2 )
			printf( "%d %d %d\n", j, i, readBuffers[j][i] );
		}
	}
	for ( int i = 0; i < 2048; i++ ) {
		printf( "%d: %f\n", i, timecheck[i] );
	}
	printf( "Command buget was gone:%d \nTag was busy:%d\n", noCmdBudgetCount, noTagCount );

	exit(0);
}
コード例 #2
0
ファイル: main.cpp プロジェクト: hoangt/bluedbm
int main(int argc, const char **argv)
{

	MemServerRequestProxy *hostMemServerRequest = new MemServerRequestProxy(IfcNames_HostMemServerRequest);
	MMURequestProxy *dmap = new MMURequestProxy(IfcNames_HostMMURequest);
	DmaManager *dma = new DmaManager(dmap);
	MemServerIndication *hostMemServerIndication = new MemServerIndication(hostMemServerRequest, IfcNames_HostMemServerIndication);
	MMUIndication *hostMMUIndication = new MMUIndication(dma, IfcNames_HostMMUIndication);

	fprintf(stderr, "Main::allocating memory...\n");

	device = new FlashRequestProxy(IfcNames_FlashRequest);
	FlashIndication *deviceIndication = new FlashIndication(IfcNames_FlashIndication);
	
	srcAlloc = portalAlloc(srcAlloc_sz);
	dstAlloc = portalAlloc(dstAlloc_sz);
	srcBuffer = (unsigned int *)portalMmap(srcAlloc, srcAlloc_sz);
	dstBuffer = (unsigned int *)portalMmap(dstAlloc, dstAlloc_sz);

	fprintf(stderr, "dstAlloc = %x\n", dstAlloc); 
	fprintf(stderr, "srcAlloc = %x\n", srcAlloc); 
	
	pthread_mutex_init(&flashReqMutex, NULL);
	pthread_cond_init(&flashFreeTagCond, NULL);

	printf( "Done initializing hw interfaces\n" ); fflush(stdout);

	portalExec_start();
	printf( "Done portalExec_start\n" ); fflush(stdout);

	portalDCacheFlushInval(dstAlloc, dstAlloc_sz, dstBuffer);
	portalDCacheFlushInval(srcAlloc, srcAlloc_sz, srcBuffer);
	ref_dstAlloc = dma->reference(dstAlloc);
	ref_srcAlloc = dma->reference(srcAlloc);

	for (int t = 0; t < NUM_TAGS; t++) {
		readTagTable[t].busy = false;
		writeTagTable[t].busy = false;
		int byteOffset = t * PAGE_SIZE;
		device->addDmaWriteRefs(ref_dstAlloc, byteOffset, t);
		device->addDmaReadRefs(ref_srcAlloc, byteOffset, t);
		readBuffers[t] = dstBuffer + byteOffset/sizeof(unsigned int);
		writeBuffers[t] = srcBuffer + byteOffset/sizeof(unsigned int);
	}
	
	for (int blk=0; blk<BLOCKS_PER_CHIP; blk++) {
		for (int c=0; c<CHIPS_PER_BUS; c++) {
			for (int bus=0; bus< CHIPS_PER_BUS; bus++) {
				flashStatus[bus][c][blk] = UNINIT;
			}
		}
	}


	for (int t = 0; t < NUM_TAGS; t++) {
		for ( int i = 0; i < PAGE_SIZE/sizeof(unsigned int); i++ ) {
			readBuffers[t][i] = 0;
			writeBuffers[t][i] = 0;
		}
	}

	device->start(0);
	device->setDebugVals(0,0); //flag, delay

	device->debugDumpReq(0);
	sleep(1);
	device->debugDumpReq(0);
	sleep(1);
	//TODO: test writes and erases
	

	
	//test erases
	for (int blk = 0; blk < BLOCKS_PER_CHIP; blk++){
		for (int chip = 0; chip < CHIPS_PER_BUS; chip++){
			for (int bus = 0; bus < NUM_BUSES; bus++){
				eraseBlock(bus, chip, blk, waitIdleEraseTag());
			}
		}
	}

	while (true) {
		usleep(100);
		if ( getNumErasesInFlight() == 0 ) break;
	}
	
	
	//read back erased pages
	for (int blk = 0; blk < BLOCKS_PER_CHIP; blk++){
		for (int chip = 0; chip < CHIPS_PER_BUS; chip++){
			for (int bus = 0; bus < NUM_BUSES; bus++){
				int page = 0;
				readPage(bus, chip, blk, page, waitIdleReadBuffer());
			}
		}
	}
	while (true) {
		usleep(100);
		if ( getNumReadsInFlight() == 0 ) break;
	}


	//write pages
	//FIXME: in old xbsv, simulatneous DMA reads using multiple readers cause kernel panic
	//Issue each bus separately for now
	for (int blk = 0; blk < BLOCKS_PER_CHIP; blk++){
		for (int chip = 0; chip < CHIPS_PER_BUS; chip++){
			for (int bus = 0; bus < NUM_BUSES; bus++){
				int page = 0;
				//get free tag
				int freeTag = waitIdleWriteBuffer();
				//fill write memory
				for (int w=0; w<PAGE_SIZE/sizeof(unsigned int); w++) {
					writeBuffers[freeTag][w] = hashAddrToData(bus, chip, blk, w);
				}
				//send request
				writePage(bus, chip, blk, page, freeTag);
			}
		}
		
	}
	while (true) {
		usleep(100);
		if ( getNumWritesInFlight() == 0 ) break;
	}
		
	

	timespec start, now;
	clock_gettime(CLOCK_REALTIME, & start);

	for (int repeat = 0; repeat < 1; repeat++){
		for (int blk = 0; blk < BLOCKS_PER_CHIP; blk++){
			for (int chip = 0; chip < CHIPS_PER_BUS; chip++){
				for (int bus = 0; bus < NUM_BUSES; bus++){

				//int blk = rand() % 1024;
				//int chip = rand() % 8;
				//int bus = rand() % 8;
					int page = 0;
					readPage(bus, chip, blk, page, waitIdleReadBuffer());
				}
			}
		}
	}
	
	int elapsed = 0;
	while (true) {
		usleep(100);
		if (elapsed == 0) {
			elapsed=10000;
			device->debugDumpReq(0);
		}
		else {
			elapsed--;
		}
		if ( getNumReadsInFlight() == 0 ) break;
	}
	device->debugDumpReq(0);

	clock_gettime(CLOCK_REALTIME, & now);
	fprintf(stderr, "LOG: finished reading from page! %f\n", timespec_diff_sec(start, now) );

	for ( int t = 0; t < NUM_TAGS; t++ ) {
		for ( int i = 0; i < PAGE_SIZE/sizeof(unsigned int); i++ ) {
			fprintf(stderr,  "%x %x %x\n", t, i, readBuffers[t][i] );
		}
	}
	if (testPass==1) {
		fprintf(stderr, "LOG: TEST PASSED!\n");
	}
	else {
		fprintf(stderr, "LOG: **ERROR: TEST FAILED!\n");
	}


}
コード例 #3
0
ファイル: encodervorbis.cpp プロジェクト: Shunty/mixxx
// call sendPackages() or write() after 'flush()' as outlined in engineshoutcast.cpp
void EncoderVorbis::flush() {
    vorbis_analysis_wrote(&m_vdsp, 0);
    writePage();
}
コード例 #4
0
void parse_note ( Creature *ch, const char *argument, int type )
{
	BUFFER *buffer;
	char buf[MAX_STRING_LENGTH];
	char arg[MAX_INPUT_LENGTH];
	NOTE_DATA *pnote;
	NOTE_DATA **list;
	const char *list_name;
	int vnum;
	int anum;

	if ( IS_NPC ( ch ) )
	{ return; }

	switch ( type ) {
		default:
			return;
		case NOTE_NOTE:
			list = &note_list;
			list_name = "notes";
			break;
		case NOTE_IDEA:
			list = &idea_list;
			list_name = "ideas";
			break;
		case NOTE_PENALTY:
			list = &penalty_list;
			list_name = "penalties";
			break;
		case NOTE_NEWS:
			list = &news_list;
			list_name = "news";
			break;
		case NOTE_CHANGES:
			list = &changes_list;
			list_name = "changes";
			break;
	}

	argument = ChopC ( argument, arg );
	smash_tilde ( argument );

	if ( arg[0] == '\0' || !str_prefix ( arg, "read" ) ) {
		bool fAll;

		if ( SameString ( argument, "all" ) ) {
			fAll = TRUE;
			anum = 0;
		}

		else if ( argument[0] == '\0' || !str_prefix ( argument, "next" ) )
			/* read next unread note */
		{
			vnum = 0;
			for ( pnote = *list; pnote != NULL; pnote = pnote->next ) {
				if ( !hide_note ( ch, pnote ) ) {
					sprintf ( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r",
							  vnum,
							  pnote->sender,
							  pnote->subject,
							  pnote->date,
							  pnote->to_list );
					writeBuffer ( buf, ch );
					writePage ( pnote->text, ch );
					update_read ( ch, pnote );
					return;
				} else if ( is_note_to ( ch, pnote ) )
				{ vnum++; }
			}
			snprintf ( buf, sizeof ( buf ), "You have no unread %s.\n\r", list_name );
			writeBuffer ( buf, ch );
			return;
		}

		else if ( is_number ( argument ) ) {
			fAll = FALSE;
			anum = atoi ( argument );
		} else {
			writeBuffer ( "Read which number?\n\r", ch );
			return;
		}

		vnum = 0;
		for ( pnote = *list; pnote != NULL; pnote = pnote->next ) {
			if ( is_note_to ( ch, pnote ) && ( vnum++ == anum || fAll ) ) {
				sprintf ( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r",
						  vnum - 1,
						  pnote->sender,
						  pnote->subject,
						  pnote->date,
						  pnote->to_list
						);
				writeBuffer ( buf, ch );
				writePage ( pnote->text, ch );
				update_read ( ch, pnote );
				return;
			}
		}

		snprintf ( buf, sizeof ( buf ), "There aren't that many %s.\n\r", list_name );
		writeBuffer ( buf, ch );
		return;
	}

	if ( !str_prefix ( arg, "list" ) ) {
		vnum = 0;
		for ( pnote = *list; pnote != NULL; pnote = pnote->next ) {
			if ( is_note_to ( ch, pnote ) ) {
				sprintf ( buf, "[%3d%s] %s: %s\n\r",
						  vnum, hide_note ( ch, pnote ) ? " " : "N",
						  pnote->sender, pnote->subject );
				writeBuffer ( buf, ch );
				vnum++;
			}
		}
		if ( !vnum ) {
			switch ( type ) {
				case NOTE_NOTE:
					writeBuffer ( "There are no notes for you.\n\r", ch );
					break;
				case NOTE_IDEA:
					writeBuffer ( "There are no ideas for you.\n\r", ch );
					break;
				case NOTE_PENALTY:
					writeBuffer ( "There are no penalties for you.\n\r", ch );
					break;
				case NOTE_NEWS:
					writeBuffer ( "There is no news for you.\n\r", ch );
					break;
				case NOTE_CHANGES:
					writeBuffer ( "There are no changes for you.\n\r", ch );
					break;
			}
		}
		return;
	}

	if ( !str_prefix ( arg, "remove" ) ) {
		if ( !is_number ( argument ) ) {
			writeBuffer ( "Note remove which number?\n\r", ch );
			return;
		}

		anum = atoi ( argument );
		vnum = 0;
		for ( pnote = *list; pnote != NULL; pnote = pnote->next ) {
			if ( is_note_to ( ch, pnote ) && vnum++ == anum ) {
				note_remove ( ch, pnote, FALSE );
				writeBuffer ( "Ok.\n\r", ch );
				return;
			}
		}

		snprintf ( buf, sizeof ( buf ), "There aren't that many %s.", list_name );
		writeBuffer ( buf, ch );
		return;
	}

	if ( !str_prefix ( arg, "delete" ) && get_trust ( ch ) >= MAX_LEVEL - 1 ) {
		if ( !is_number ( argument ) ) {
			writeBuffer ( "Note delete which number?\n\r", ch );
			return;
		}

		anum = atoi ( argument );
		vnum = 0;
		for ( pnote = *list; pnote != NULL; pnote = pnote->next ) {
			if ( is_note_to ( ch, pnote ) && vnum++ == anum ) {
				note_remove ( ch, pnote, TRUE );
				writeBuffer ( "Ok.\n\r", ch );
				return;
			}
		}

		snprintf ( buf, sizeof ( buf ), "There aren't that many %s.", list_name );
		writeBuffer ( buf, ch );
		return;
	}

	if ( !str_prefix ( arg, "catchup" ) ) {
		switch ( type ) {
			case NOTE_NOTE:
				ch->pcdata->last_note = current_time;
				break;
			case NOTE_IDEA:
				ch->pcdata->last_idea = current_time;
				break;
			case NOTE_PENALTY:
				ch->pcdata->last_penalty = current_time;
				break;
			case NOTE_NEWS:
				ch->pcdata->last_news = current_time;
				break;
			case NOTE_CHANGES:
				ch->pcdata->last_changes = current_time;
				break;
		}
		return;
	}

	/* below this point only certain people can edit notes */
	if ( ( type == NOTE_NEWS && !IS_TRUSTED ( ch, ANGEL ) )
			||  ( type == NOTE_CHANGES && !IS_TRUSTED ( ch, CREATOR ) ) ) {
		snprintf ( buf, sizeof ( buf ), "You aren't high enough level to write %s.", list_name );
		writeBuffer ( buf, ch );
		return;
	}

	if ( SameString ( arg, "+" ) ) {
		note_attach ( ch, type );
		if ( ch->pnote->type != type ) {
			writeBuffer (
				"You already have a different note in progress.\n\r", ch );
			return;
		}

		if ( strlen ( ch->pnote->text ) + strlen ( argument ) >= 4096 ) {
			writeBuffer ( "Note too long.\n\r", ch );
			return;
		}

		buffer = new_buf();

		add_buf ( buffer, ch->pnote->text );
		add_buf ( buffer, argument );
		add_buf ( buffer, "\n\r" );
		PURGE_DATA ( ch->pnote->text );
		ch->pnote->text = assign_string ( buf_string ( buffer ) );
		recycle_buf ( buffer );
		writeBuffer ( "Ok.\n\r", ch );
		return;
	}

	if ( SameString ( arg, "-" ) ) {
		int len;
		bool found = FALSE;

		note_attach ( ch, type );
		if ( ch->pnote->type != type ) {
			writeBuffer (
				"You already have a different note in progress.\n\r", ch );
			return;
		}

		if ( ch->pnote->text == NULL || ch->pnote->text[0] == '\0' ) {
			writeBuffer ( "No lines left to remove.\n\r", ch );
			return;
		}

		strcpy ( buf, ch->pnote->text );

		for ( len = strlen ( buf ); len > 0; len-- ) {
			if ( buf[len] == '\r' ) {
				if ( !found ) { /* back it up */
					if ( len > 0 )
					{ len--; }
					found = TRUE;
				} else { /* found the second one */
					buf[len + 1] = '\0';
					PURGE_DATA ( ch->pnote->text );
					ch->pnote->text = assign_string ( buf );
					return;
				}
			}
		}
		buf[0] = '\0';
		PURGE_DATA ( ch->pnote->text );
		ch->pnote->text = assign_string ( buf );
		return;
	}

	if ( !str_prefix ( arg, "subject" ) ) {
		note_attach ( ch, type );
		if ( ch->pnote->type != type ) {
			writeBuffer (
				"You already have a different note in progress.\n\r", ch );
			return;
		}

		PURGE_DATA ( ch->pnote->subject );
		ch->pnote->subject = assign_string ( argument );
		writeBuffer ( "Ok.\n\r", ch );
		return;
	}

	if ( !str_prefix ( arg, "to" ) ) {
		note_attach ( ch, type );
		if ( ch->pnote->type != type ) {
			writeBuffer (
				"You already have a different note in progress.\n\r", ch );
			return;
		}
		PURGE_DATA ( ch->pnote->to_list );
		ch->pnote->to_list = assign_string ( argument );
		writeBuffer ( "Ok.\n\r", ch );
		return;
	}

	if ( !str_prefix ( arg, "clear" ) ) {
		if ( ch->pnote != NULL ) {
			recycle_note ( ch->pnote );
			ch->pnote = NULL;
		}

		writeBuffer ( "Ok.\n\r", ch );
		return;
	}

	if ( !str_prefix ( arg, "show" ) ) {
		if ( ch->pnote == NULL ) {
			writeBuffer ( "You have no note in progress.\n\r", ch );
			return;
		}

		if ( ch->pnote->type != type ) {
			writeBuffer ( "You aren't working on that kind of note.\n\r", ch );
			return;
		}

		sprintf ( buf, "%s: %s\n\rTo: %s\n\r",
				  ch->pnote->sender,
				  ch->pnote->subject,
				  ch->pnote->to_list
				);
		writeBuffer ( buf, ch );
		writeBuffer ( ch->pnote->text, ch );
		return;
	}

	if ( !str_prefix ( arg, "post" ) || !str_prefix ( arg, "send" ) ) {
		char *strtime;

		if ( ch->pnote == NULL ) {
			writeBuffer ( "You have no note in progress.\n\r", ch );
			return;
		}

		if ( ch->pnote->type != type ) {
			writeBuffer ( "You aren't working on that kind of note.\n\r", ch );
			return;
		}

		if ( SameString ( ch->pnote->to_list, "" ) ) {
			writeBuffer (
				"You need to provide a recipient (name, all, or immortal).\n\r",
				ch );
			return;
		}

		if ( SameString ( ch->pnote->subject, "" ) ) {
			writeBuffer ( "You need to provide a subject.\n\r", ch );
			return;
		}

		ch->pnote->next			= NULL;
		strtime				= ctime ( &current_time );
		strtime[strlen ( strtime ) - 1]	= '\0';
		ch->pnote->date			= assign_string ( strtime );
		ch->pnote->date_stamp		= current_time;

		append_note ( ch->pnote );
		ch->pnote = NULL;
		return;
	}

	writeBuffer ( "You can't do that.\n\r", ch );
	return;
}
コード例 #5
0
ファイル: test-buffer.c プロジェクト: tcyyky/jikkenA
/*
 * test2 -- 読み書きのテスト
 */
void test2()
{
    File *file[2];
    char page[PAGE_SIZE];
    int i;
    int fileNum, pageNum;
    
    printf("---------- test2 start ----------\n");
    
    /* ファイルをープンする */
    if ((file[0] = openFile(TEST_FILE1)) == NULL) {
        fprintf(stderr, "Cannot open file.\n");
        exit(1);
    }
    
    if ((file[1] = openFile(TEST_FILE2)) == NULL) {
        fprintf(stderr, "Cannot open file.\n");
        exit(1);
    }
    printf("  -------- files opened -------  \n");
    
    /*
     * (TEST_SIZE)回に渡ってページの読み書きを交互に行い、
     * 正しく稼働するかどうかを確認する
     */
    for (i = 0; i < TEST_SIZE; i++) {
        /* アクセスするファイルをランダムに決定 */
        fileNum = getRandomInteger(0, 1);
        
        /* アクセスするページをランダムに決定 */
        pageNum = getRandomInteger(0, FILE_SIZE - 1);
        
        /* ページの読み出し */
        printf("\nread file %d page %d\n", fileNum, pageNum);
        if (readPage(file[fileNum], pageNum, page) != OK) {
            fprintf(stderr, "Cannot read page (fileNum = %d, pageNum = %d).\n", fileNum, pageNum);
            exit(1);
        }
        
        /* バッファのリストの内容を出力 */
        printBufferList();
        
        /* アクセスするファイルをランダムに決定 */
        fileNum = getRandomInteger(0, 1);
        
        /* アクセスするページをランダムに決定 */
        pageNum = getRandomInteger(0, FILE_SIZE - 1);
        
        /* ページに書き込む内容を作成 */
        sprintf(page, "%c%c%c", '0' + fileNum, 'A' + i, '0' + pageNum);
        
        /* ページの書き込み */
        printf("\nwrite file %d page %d -> %s\n", fileNum, pageNum, page);
        if (writePage(file[fileNum], pageNum, page) != OK) {
            fprintf(stderr, "Cannot write page (fileNum = %d, pageNum = %d).\n", fileNum, pageNum);
            exit(1);
        }
        
        /* バッファのリストの内容を出力 */
        printBufferList();
    }
    
    /* いったんファイルをクローズする */
    if (closeFile(file[0]) != OK) {
        fprintf(stderr, "Cannot close file.\n");
        exit(1);
    }
    
    if (closeFile(file[1]) != OK) {
        fprintf(stderr, "Cannot close file.\n");
        exit(1);
    }
    printf("  -------- files closed -------  \n");
    
    /* クローズした直後のバッファリストの状態を出力 */
    printBufferList();
    
    /* もう一度ファイルをオープンする */
    if ((file[0] = openFile(TEST_FILE1)) == NULL) {
        fprintf(stderr, "Cannot open file.\n");
        exit(1);
    }
    
    if ((file[1] = openFile(TEST_FILE2)) == NULL) {
        fprintf(stderr, "Cannot open file.\n");
        exit(1);
    }
    printf("  -------- files opened -------  \n");
    
    /*
     * もう一度、(TEST_SIZE)回に渡ってページの読み書きを交互に行い、
     * 正しく稼働するかどうかを確認する
     */
    for (i = 0; i < TEST_SIZE; i++) {
        /* アクセスするファイルをランダムに決定 */
        fileNum = getRandomInteger(0, 1);
        
        /* アクセスするページをランダムに決定 */
        pageNum = getRandomInteger(0, FILE_SIZE - 1);
        
        /* ページの読み出し */
        printf("\nread file %d page %d\n", fileNum, pageNum);
        if (readPage(file[fileNum], pageNum, page) != OK) {
            fprintf(stderr, "Cannot read page (fileNum = %d, pageNum = %d).\n", fileNum, pageNum);
            exit(1);
        }
        
        /* バッファのリストの内容を出力 */
        printBufferList();
        
        /* アクセスするファイルをランダムに決定 */
        fileNum = getRandomInteger(0, 1);
        
        /* アクセスするページをランダムに決定 */
        pageNum = getRandomInteger(0, FILE_SIZE - 1);
        
        /* ページに書き込む内容を作成 */
        sprintf(page, "%c%c%c", '0' + fileNum, 'A' + i, '0' + pageNum);
        
        /* ページの書き込み */
        printf("\nwrite file %d page %d -> %s\n", fileNum, pageNum, page);
        if (writePage(file[fileNum], pageNum, page) != OK) {
            fprintf(stderr, "Cannot write page (fileNum = %d, pageNum = %d).\n", fileNum, pageNum);
            exit(1);
        }
        
        /* バッファのリストの内容を出力 */
        printBufferList();
    }
    
    /* ファイルのクローズ */
    if (closeFile(file[0]) != OK) {
        fprintf(stderr, "Cannot close file.\n");
        exit(1);
    }
    
    if (closeFile(file[1]) != OK) {
        fprintf(stderr, "Cannot close file.\n");
        exit(1);
    }
    printf("  -------- files closed -------  \n");
    
    /* クローズした直後のバッファリストの状態を出力 */
    printBufferList();
    
    printf("---------- test2 end ----------\n\n");
}
コード例 #6
0
ファイル: test-buffer.c プロジェクト: tcyyky/jikkenA
/*
 * main -- バッファ管理モジュールのテスト
 */
int main(int argc, char **argv)
{
    File *file[2];
    char page1[PAGE_SIZE], page2[PAGE_SIZE];
    int i;
    
    /* 乱数用関数の初期化 */
    initializeRandomGenerator();
    
    /*
     * ファイルアクセスモジュールの初期化
     */
    if (initializeFileModule() != OK) {
        fprintf(stderr, "%s: initialization failed.\n", TEST_NAME);
    }
    
    /*
     * 前回このプログラムを実行したときのテストファイルが
     * 残っている可能性があるので、まず消去する
     */
    deleteFile(TEST_FILE1);
    deleteFile(TEST_FILE2);
    
    /* 空のファイルを2つ作り、オープンする */
    if (createFile(TEST_FILE1) != OK) {
        fprintf(stderr, "Cannot create file.\n");
        exit(1);
    }
    
    if (createFile(TEST_FILE2) != OK) {
        fprintf(stderr, "Cannot create file.\n");
        exit(1);
    }
    
    if ((file[0] = openFile(TEST_FILE1)) == NULL) {
        fprintf(stderr, "Cannot open file.\n");
        exit(1);
    }
    
    if ((file[1] = openFile(TEST_FILE2)) == NULL) {
        fprintf(stderr, "Cannot open file.\n");
        exit(1);
    }
    
    /*
     * ファイルの先頭から順に、(FILE_SIZE)ページ分のダミーデータを書く
     *
     * それぞれのページの先頭3バイトに、以下のように文字を書く
     * file1:
     *   0ページ目: 000
     *   1ページ目: 001
     *   2ページ目: 002
     *   (以下同様)
     * file2:
     *   0ページ目: 100
     *   1ページ目: 101
     *   2ページ目: 102
     *   (以下同様)
     */
    for (i = 0; i < FILE_SIZE; i++) {
        /* ページに書く内容を用意する */
        memset(page1, 0, PAGE_SIZE);
        memset(page2, 0, PAGE_SIZE);
        sprintf(page1, "00%c", '0' + i);
        sprintf(page2, "10%c", '0' + i);
        
        /* ファイルに書き込む */
        if (writePage(file[0], i, page1) != OK) {
            fprintf(stderr, "Cannot write page.\n");
            exit(1);
        }
        
        if (writePage(file[1], i, page2) != OK) {
            fprintf(stderr, "Cannot write page.\n");
            exit(1);
        }
    }
    
    /* いったんファイルをクローズする */
    closeFile(file[0]);
    closeFile(file[1]);
    
    /*
     * ここまでが下準備。ここからバッファリング機能をテストする
     */
    test1();
    test2();
    
    /*
     * ファイルアクセスモジュールの終了処理
     */
    if (finalizeFileModule() != OK) {
        fprintf(stderr, "%s: finalization failed.\n", TEST_NAME);
    }
    
    /* ファイルを削除する */
    deleteFile(TEST_FILE1);
    deleteFile(TEST_FILE2);
}
コード例 #7
0
ファイル: PdfExport.cpp プロジェクト: cass00/xournalpp
bool PdfExport::createPdf(String uri)
{
    XOJ_CHECK_TYPE(PdfExport);

    if (doc->getPageCount() < 1)
    {
        lastError = "No pages to export!";
        return false;
    }

    if (!this->writer->openFile(uri.c_str()))
    {
        return false;
    }

    this->writer->write("%PDF-1.4\n");

    if (this->progressListener)
    {
        this->progressListener->setMaximumState(doc->getPageCount() * 2);
    }

    int count = doc->getPageCount();

    for (int i = 0; i < count; i++)
    {
        PageRef page = doc->getPage(i);
        cPdf.drawPage(page);

        if (this->progressListener)
        {
            this->progressListener->setCurrentState(i);
        }
    }
    cPdf.finalize();
    addPopplerDocument(cPdf.getDocument());

    for (int i = 0; i < count; i++)
    {
        if (!writePage(i))
        {
            g_warning("error writing page %i", i + 1);
            return false;
        }

        if (this->progressListener)
        {
            this->progressListener->setCurrentState(i + count);
        }
    }

    // Write our own footer
    if (!writeFooter())
    {
        g_warning("error writing footer");
        return false;
    }

    this->writer->close();

    return true;
}
コード例 #8
0
ファイル: PdfExport.cpp プロジェクト: cass00/xournalpp
bool PdfExport::createPdf(String uri, GList* range)
{
    XOJ_CHECK_TYPE(PdfExport);

    if (range == NULL)
    {
        this->lastError = "No pages to export!";
        return false;
    }

    if (!this->writer->openFile(uri.c_str()))
    {
        return false;
    }
    this->writer->write("%PDF-1.4\n");

    int count = 0;
    for (GList* l = range; l != NULL; l = l->next)
    {
        PageRangeEntry* e = (PageRangeEntry*) l->data;
        count += e->getLast() - e->getFirst();
    }

    if (this->progressListener)
    {
        this->progressListener->setMaximumState(count * 2);
    }

    int c = 0;
    for (GList* l = range; l != NULL; l = l->next)
    {
        PageRangeEntry* e = (PageRangeEntry*) l->data;

        for (int i = e->getFirst(); i < e->getLast(); i++)
        {
            PageRef page = doc->getPage(i);
            cPdf.drawPage(page);
            if (this->progressListener)
            {
                this->progressListener->setCurrentState(c++);
            }
        }
    }

    cPdf.finalize();
    addPopplerDocument(cPdf.getDocument());

    for (int i = 0; i < count; i++)
    {
        if (!writePage(i))
        {
            g_warning("error writing page %i", i + 1);
            return false;
        }

        if (this->progressListener)
        {
            this->progressListener->setCurrentState(i + count);
        }
    }

    // Write our own footer
    if (!writeFooter())
    {
        g_warning("error writing footer");
        return false;
    }

    this->writer->close();

    return true;
}
コード例 #9
0
ファイル: main.c プロジェクト: A-Nesh/FSi6_updater
int main(int argc, char *argv[])
{



    // ASCII header
    printf("    [===============================================]\r\n");
    printf("    |    FLYSKY FS-i6 CUSTOM FIRMWARE UPLOADER      |\r\n");
    printf("    |    by Thom				    |\r\n");
    printf("    | 					            |\r\n");
    printf("    |    check out my blog for more:		    |\r\n");
    printf("    |    basejunction.wordpress.com	            |\r\n");
    printf("    [===============================================]\r\n\r\n");
    printf("\n!!! Please make sure the firmware file comes from basejunction.wordpress.com !!!\n\n");

    HANDLE hdlr = NULL; //port handle
    int n_com=1;
    int n_baudrate=115200;

    char arg1[256],arg2[256],arg3[256],arg4[256],arg5[256];
    char cmd[256]="";

    if(argc>=2)
        n_com=(int)strtol(argv[1],NULL,10);
    if(argc>=3)
        n_baudrate=(int)strtol(argv[2],NULL,10);

    //init
    printf("Opening COM%d at %d bauds : ",n_com,n_baudrate);
    if(openCom(n_com,n_baudrate,&hdlr))
        printf("SUCCESS");
    else
        printf("FAILED - verify your COM port number and baudrate settings");
    printf("\n\n");



    //main loop
    do
    {

        printf(">> ");
        fgets(cmd, sizeof(cmd), stdin);

        sscanf(cmd,"%s %s %s %s %s",arg1,arg2,arg3,arg4,arg5);



        if(!strcmp(arg1,"help")|| !strcmp(arg1,"h"))
        {
            printf("-- open [port] [baudrate] : open com port number [port] at [baudrate] bauds\n");
            printf("-- readb : read byte \n");
            printf("-- readf : read frame \n");
            printf("-- sendb [format] [byte] : send [byte] with [format{-b,-d,-h}]\n");
            printf("-- write [filename] [offset:h] [nbytes:d] : write [nbytes](decimal) bytes page at [offset](hex)\n");
            printf("-- flash [filename] : program [filename] firmware into TX flash memory (bootloader untouched)\n");
            printf("-- ping : send a ping request\n");
            printf("-- reset : send a reset TX request\n");
            printf("-- quit : quit the updater\n");

        }

        else if(!strcmp(arg1,"readb"))
        {
            unsigned char byte=0;
            if(readByte(&byte,&hdlr))
                printf("%x \n",byte);
            else
                printf("ERROR - reading byte from serial buffer\n");
        }
        else if(!strcmp(arg1,"readf"))
        {
            unsigned short size=0;
            unsigned short checksum=0;
            unsigned char frame[256];
            if(!readFramedbg(&size,&checksum,frame,&hdlr))
                printf("ERROR - reading frame from serial buffer\n");
            if(!sumcheck(frame,size))
                printf("ERROR - checksum mismatch\n");

        }
        else if(!strcmp(arg1,"sendb"))
        {
            unsigned char msg=0;
            if(!strcmp(arg2,"-h"))
                msg=(unsigned char)strtoul(arg3,NULL,16);
            if(!strcmp(arg2,"-d"))
                msg=(unsigned char)strtoul(arg3,NULL,10);
            if(!strcmp(arg2,"-b"))
                msg=(unsigned char)strtoul(arg3,NULL,2);
            printf("Sending byte: %d 0x%x\n",msg,msg);
            if(!sendByte(&msg,&hdlr))
                printf("ERROR - sending byte in serial buffer\n");
        }
        else if(!strcmp(arg1,"reset"))
        {
            printf("reset . . . \n");
            unsigned char msg[]={0x06,0x00,0xC1,0x00,0xFF,0xFF};//38FF
            sendFrame(msg,sizeof(msg),&hdlr);
        }
        else if(!strcmp(arg1,"ping"))
        {
            unsigned char msg[]={0x05,0x00,0xC0,0x3A,0xFF};
            unsigned short size=0;
            unsigned short checksum=0;
            unsigned char frame[256];

            printf("ping . . . \n");
            sendFrame(msg,sizeof(msg),&hdlr);

            if(!readFrame(&size,&checksum,frame,&hdlr))
                printf("ERROR - reading frame from serial buffer\n");
            if(!sumcheck(frame,size))
                printf("ERROR - checksum mismatch\n");
            printf("\nConnected : FLYSKY i6 \nFirmware version : %d.%d \n",frame[6],frame[4]);
        }
        else if(!strcmp(arg1,"write"))
        {
            unsigned int offset=strtoul(arg3,NULL,16);
            unsigned char msg[256];
            if(!readPage(msg,arg2,offset,256))
                printf("ERROR - reading file\n");
            writePage(msg,sizeof(msg),offset,&hdlr);
        }
        else if(!strcmp(arg1,"flash"))
        {
            BOOL cont = TRUE;
            unsigned char msg[256];
            int i=0x1800;
            for(i=0x1800;(i<0xF300)&&cont;i=i+0x100)
            {
                //11 00 C2 00 18 00 09 00 00 00 00 00 00 00 00 0B FF
                unsigned char msg2[17]={0x11,0x00,0xC2,0xFF,0xFF,0x00,0x09,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF};
                unsigned short reply_size=0;
                unsigned short reply_checksum=0;
                unsigned char reply[19];
                //55 13 00 C2 80 00 18 00 09 00 00 00 00 00 00 00 00 34 FE

                msg2[3]=(unsigned char)i;
                msg2[4]=(unsigned char)(i>>8);
                sendFrame(msg2,sizeof(msg2),&hdlr);

                unsigned char ok_reply[19]={0x55,0x13,0x00,0xC2,0x80,0xFF,0xFF,0x00,0x09,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF};
                ok_reply[5]=(unsigned char)i;
                ok_reply[6]=(unsigned char)(i>>8);


                unsigned int checksum=0xFFFF;
                int j=0;
                for(j=0;j<19-2;j++)
                {
                    checksum=checksum-ok_reply[j];
                }

                ok_reply[19-2]=(unsigned char)checksum;
                ok_reply[19-1]=(unsigned char)(checksum>>8);


                readFrame(&reply_size,&reply_checksum,reply,&hdlr);

                unsigned char reply_s[19];
                memcpy(reply_s,reply,reply_size);

                // compare received reply with correct one
                if(memcmp(reply_s,ok_reply,sizeof(reply_s))!=0)
                {
                    printf("ERROR - bad reply from TX\n");
                    cont=FALSE;
                }

                if(!readPage(msg,arg2,i,256))
                {
                    printf("ERROR - reading file\n");
                    cont=FALSE;
                }
                writePage(msg,sizeof(msg),i,&hdlr);
                i=i+0x100;
                if(!readPage(msg,arg2,i,256))
                {
                    printf("ERROR - reading file\n");
                    cont=FALSE;
                }
                writePage(msg,sizeof(msg),i,&hdlr);
                i=i+0x100;
                if(!readPage(msg,arg2,i,256))
                {
                    printf("ERROR - reading file\n");
                    cont=FALSE;
                }
                writePage(msg,sizeof(msg),i,&hdlr);
                i=i+0x100;
                if(!readPage(msg,arg2,i,256))
                {
                    printf("ERROR - reading file\n");
                    cont=FALSE;
                }
                writePage(msg,sizeof(msg),i,&hdlr);
            }
            //reset
            if(cont)
            {
                printf("Reset . . .\n");
                unsigned char msg3[]={0x06,0x00,0xC1,0x00,0xFF,0xFF};//38FF
                sendFrame(msg3,sizeof(msg3),&hdlr);
            }

        }

        else if(!strcmp(arg1,"open"))
        {
            closeCom(&hdlr);
            unsigned int n_com=strtoul(arg2,NULL,10);
            unsigned int n_baudrate=strtoul(arg3,NULL,10);
            printf("Opening COM%d at %d bauds : ",n_com,n_baudrate);
            if(openCom(n_com,n_baudrate,&hdlr))
                printf("SUCCESS");
            else
                printf("FAILED - verify your COM port number and baudrate settings");
            printf("\n\n");
        }

        else if(strcmp(arg1,"quit"))
        {
            printf("-- Unknown command \"%s\"\n",arg1);
            printf("-- Type \"help\" for a command list\n");
        }
    }while(strcmp(arg1,"quit"));
コード例 #10
0
ファイル: main_example.cpp プロジェクト: cwchung90/bluedbm
int main(int argc, const char **argv)
{
	testPassed=true;

	fprintf(stderr, "Initializing Connectal & DMA...\n");

	device = new FlashRequestProxy(IfcNames_FlashRequestS2H);
	FlashIndication deviceIndication(IfcNames_FlashIndicationH2S);
    DmaManager *dma = platformInit();

	fprintf(stderr, "Main::allocating memory...\n");
	
	// Memory for DMA
	srcAlloc = portalAlloc(srcAlloc_sz, 0);
	dstAlloc = portalAlloc(dstAlloc_sz, 0);
	srcBuffer = (unsigned int *)portalMmap(srcAlloc, srcAlloc_sz); // Host->Flash Write
	dstBuffer = (unsigned int *)portalMmap(dstAlloc, dstAlloc_sz); // Flash->Host Read

	// Memory for FTL
	blkmapAlloc = portalAlloc(blkmapAlloc_sz * 2, 0);
	char *ftlPtr = (char*)portalMmap(blkmapAlloc, blkmapAlloc_sz * 2);
	blkmap      = (uint16_t(*)[NUM_LOGBLKS]) (ftlPtr);  // blkmap[Seg#][LogBlk#]
	blkmgr      = (uint16_t(*)[NUM_CHIPS][NUM_BLOCKS])  (ftlPtr+blkmapAlloc_sz); // blkmgr[Bus][Chip][Block]

	fprintf(stderr, "dstAlloc = %x\n", dstAlloc); 
	fprintf(stderr, "srcAlloc = %x\n", srcAlloc); 
	fprintf(stderr, "blkmapAlloc = %x\n", blkmapAlloc); 
	
	pthread_mutex_init(&flashReqMutex, NULL);
	pthread_cond_init(&flashFreeTagCond, NULL);

	printf( "Done initializing hw interfaces\n" ); fflush(stdout);

	portalCacheFlush(dstAlloc, dstBuffer, dstAlloc_sz, 1);
	portalCacheFlush(srcAlloc, srcBuffer, srcAlloc_sz, 1);
	portalCacheFlush(blkmapAlloc, blkmap, blkmapAlloc_sz*2, 1);

	ref_dstAlloc = dma->reference(dstAlloc);
	ref_srcAlloc = dma->reference(srcAlloc);
	ref_blkmapAlloc = dma->reference(blkmapAlloc);

	device->setDmaWriteRef(ref_dstAlloc);
	device->setDmaReadRef(ref_srcAlloc);
	device->setDmaMapRef(ref_blkmapAlloc);

	for (int t = 0; t < NUM_TAGS; t++) {
		readTagTable[t].busy = false;
		writeTagTable[t].busy = false;
		eraseTagTable[t].busy = false;

		int byteOffset = t * FPAGE_SIZE;
		readBuffers[t] = dstBuffer + byteOffset/sizeof(unsigned int);
		writeBuffers[t] = srcBuffer + byteOffset/sizeof(unsigned int);
	}

	for (int lpa=0; lpa < NUM_SEGMENTS*NUM_LOGBLKS*NUM_PAGES_PER_BLK; lpa++) {
		flashStatus[lpa] = UNINIT;
	}

	for (int t = 0; t < NUM_TAGS; t++) {
		for ( unsigned int i = 0; i < FPAGE_SIZE/sizeof(unsigned int); i++ ) {
			readBuffers[t][i] = 0xDEADBEEF;
			writeBuffers[t][i] = 0xBEEFDEAD;
		}
	}

	long actualFrequency=0;
	long requestedFrequency=1e9/MainClockPeriod;
	int status = setClockFrequency(0, requestedFrequency, &actualFrequency);
	fprintf(stderr, "Requested Freq: %5.2f, Actual Freq: %5.2f, status=%d\n"
			,(double)requestedFrequency*1.0e-6
			,(double)actualFrequency*1.0e-6,status);

	printf( "Start!\n" ); fflush(stdout);
	device->start(0);
	device->setDebugVals(0,0); //flag, delay

	device->debugDumpReq(0);
	sleep(1);

	printf( "Read initial FTL table from table.dump.0\n" ); fflush(stdout);
	// Read Initial FTL table
	if (readFTLfromFile("table.dump.0", ftlPtr) != 0) {
		fprintf(stderr, "Read Failure\n");
		return -1;
	}
	printf( "Done reading table.dump.0\n" ); fflush(stdout);

	printf( "MAP Upload to HW!\n" ); fflush(stdout);
	device->uploadMap();

	timespec start, now;
	clock_gettime(CLOCK_REALTIME, & start);

	printf( "Test Write!\n" ); fflush(stdout);

	for (int logblk = 0; logblk < NUM_LOGBLKS; logblk++){
		// test only 1024 segments due to some bad blocks (cannot allocate full 4096 segments)
		for (int segnum = 0; segnum < 1024; segnum++) {
			// assuming page_ofs = 0
			int lpa = (segnum<<14) + logblk;
			int freeTag = waitIdleWriteBuffer();

			// fill write memory
			for (unsigned int w=0; w<FPAGE_SIZE_VALID/sizeof(unsigned int); w++) {
				writeBuffers[freeTag][w] = hashAddrToData(lpa, w);
			}

			writePage(freeTag, lpa);
		}
	}

	while (true) {
		usleep(100);
		if ( getNumWritesInFlight() == 0 ) break;
	}

	// read back Map and Save to table.dump.1
	device->downloadMap(); // read table from FPGA
	if(writeFTLtoFile("table.dump.1", ftlPtr) != 0) {
		fprintf(stderr, "Write Failure\n");
		return -1;
	}

	printf( "Test Read!\n" ); fflush(stdout);
	
	for (int logblk = 0; logblk < NUM_LOGBLKS; logblk++){
		// test only 1024 segments due to some bad blocks (cannot allocate full 4096 segments)
		for (int segnum = 0; segnum < 1024; segnum++) {
			// assuming page_ofs = 0
			int lpa = (segnum<<14) + logblk;
			readPage(waitIdleReadBuffer(), lpa);
		}
	}

	while (true) {
		usleep(100);
		if ( getNumReadsInFlight() == 0 ) break;
	}

	printf( "Test Erase!\n" ); fflush(stdout);
	for (int logblk = 0; logblk < NUM_LOGBLKS; logblk++){
		// test only 1024 segments due to some bad blocks (cannot allocate full 4096 segments)
		for (int segnum = 0; segnum < 1024; segnum++) {
			// assuming page_ofs = 0
			int lpa = (segnum<<14) + logblk;
			eraseBlock(waitIdleEraseTag(), lpa);
		}
	}

	while (true) {
		usleep(100);
		if ( getNumErasesInFlight() == 0 ) break;
	}

	int elapsed = 0;
	while (true) {
		usleep(100);
		if (elapsed == 0) {
			elapsed=10000;
			device->debugDumpReq(0);
		}
		else {
			elapsed--;
		}
		if ( getNumReadsInFlight() == 0 ) break;
	}
	device->debugDumpReq(0);

	clock_gettime(CLOCK_REALTIME, & now);
	fprintf(stderr, "LOG: finished reading from page! %f\n", timespec_diff_sec(start, now) );

	sleep(2);
}
コード例 #11
0
ファイル: DirPage.cpp プロジェクト: lkshminarayanan/OurSQL
void DirPage::writeToPage(){
	memcpy(p,this,sizeof(DirPage));
	writePage();
}