Ejemplo n.º 1
0
 void ProfilerTest::test_one_timer() {
    const double TIMER_RESOLUTION = Profiler::get_resolution();
    const double DELTA = TIMER_RESOLUTION*1000;
    double total=0;
    Profiler::initialize();

    { // uninitialize can not be in the same block as the START_TIMER


    START_TIMER("test_tag");
        // test that number of calls of current timer is
        EXPECT_EQ( 1, ACC);

        // wait a TIMER_RESOLUTION time
        total += wait_sec(TIMER_RESOLUTION);
    END_TIMER("test_tag");



    START_TIMER("test_tag");
        // test that number of calls of current timer is
        EXPECT_EQ( 2, ACC);

        // test whether difference between measured time and total time is within TIMER_RESOLUTION
        EXPECT_LE( abs(ACT-total), DELTA);
        cout << "difference: " << abs(total-ACT) << ", tolerance: " << DELTA << endl;

        // wait a TIMER_RESOLUTION time
        total += wait_sec (TIMER_RESOLUTION);
        total += wait_sec (TIMER_RESOLUTION);

    END_TIMER("test_tag");

    START_TIMER("test_tag");
        EXPECT_EQ( 3, ACC);
        EXPECT_LE( abs(ACT-total), DELTA);
        cout << "difference: " << abs(total-ACT) << ", tolerance: " << DELTA << endl;
    }

    // test add_call
    {
        START_TIMER("add_call");
        ADD_CALLS(1000);
        EXPECT_EQ(1000, ACC);
    }

    // test absolute time
    {
        START_TIMER("one_second");
        wait_sec(1);
    }
    std::stringstream sout;
    PI->output(MPI_COMM_WORLD, sout);
    PI->output(MPI_COMM_WORLD, cout);

    //EXPECT_NE( sout.str().find("\"tag\": \"Whole Program\""), string::npos );

    Profiler::uninitialize();
}
Ejemplo n.º 2
0
void ProfilerTest::test_absolute_time() {
    Profiler::initialize();

    // test absolute time
    {
        START_TIMER("one_second");
        wait_sec(1);
    }
    std::stringstream sout;
    PI->output(MPI_COMM_WORLD, sout);
    PI->output(MPI_COMM_WORLD, cout);
    
    // try to transform profiler data using python
    PI->output(MPI_COMM_WORLD);
    PI->transform_profiler_data (".txt", "SimpleTableFormatter");
    
    int ierr, mpi_rank;
    ierr = MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
    EXPECT_EQ( ierr, 0 );
    
    // 0 processor will have valid profiler report
    // other processors should have empty string only
    if (mpi_rank == 0) {
        // test timer resolution, requiring atleast 2 digit places
        EXPECT_NE( sout.str().find("cumul-time-min\": \"1.00"), string::npos );
        EXPECT_NE( sout.str().find("cumul-time-max\": \"1.00"), string::npos );
    } else {
        EXPECT_TRUE( sout.str().empty() );
    }
    
    

    Profiler::uninitialize();
}
Ejemplo n.º 3
0
void start()
{
	int i = 0;
	int j;
	char c;

	//while( 1 ) {
	for(j=0; j<3*NUM_PATTERNS; j++) {
		c = patterns[i] >> 4;
		led(c);

		c = patterns[i];
		wait_sec();
		led(c);

		i = (i == NUM_PATTERNS-1) ? 0 : (i+1);
		//if( ++i >= NUM_PATTERNS )
		//	i = 0;

		wait_sec();
	}
}
Ejemplo n.º 4
0
int
biosdisk_close(struct open_file *f)
{
	struct biosdisk *d = f->f_devdata;

	/* let the floppy drive go off */
	if (d->ll.type == BIOSDISK_TYPE_FD)
		wait_sec(3);	/* 2s is enough on all PCs I found */

	dealloc(d, sizeof(*d));
	f->f_devdata = NULL;
	return 0;
}
Ejemplo n.º 5
0
void kernel_main(void)
{
	terminal_init();
	puts("This is BermudOS!");
	if(!is_apic_compatible())
		puts("Hardware is not APIC compatible");
	if(!has_MSR())
		puts("CPU has no MSR");
	if(!gdt_setup())
		puts("Error while setting up GDT");
	setup_interrupts();
	if(!keyboard_setup())
		puts("Error while setting up the keyboard");
	wait_sec(4);
	char bfr[KEYBOARD_BUFFER_SIZE+1];
	int i;
	for(i = 0; i < 4; ++i)
	{
		read_keyboard_buffer(bfr);
		printf("The buffer contained: %s", bfr);
	}
}
int main (void) 
{

	//----------变量定义-------------//
	XGpio led , push; //2个GPIO  LED 和 BUTTON
	int i ,j , psb_check;//psb_check为push的返回值
	const int BLINK_TIMES = 2;
	int n = -1;

    xil_printf("-- Start of the Program --\r\n");

   
	//初始化GPIO 及 输入输出设置
	XGpio_Initialize(&led,XPAR_DIODE_0_DEVICE_ID);
	XGpio_SetDataDirection(&led,1,0x00000000);//led  0是输出

	XGpio_Initialize(&push, XPAR_BTN_4BIT_DEVICE_ID);
	XGpio_SetDataDirection(&push, 1, 0xffffffff);//button 1是输入

    void wait_sec()
    {
    	for (i=0; i<50000000; i++);
    	{
    	psb_check = XGpio_DiscreteRead(&push,1);
    	}

    }
	while (1)
	{
        //按下button,得到按下哪个按钮
		psb_check = XGpio_DiscreteRead(&push,1);//读取btn按键的输入
		if( psb_check==1 )
		{
		  xil_printf("= = = R-E-S-E-T = = =\r\n");
		  n = 0;
		  goto L0;
		}

		psb_check = 0;

L0:
        if(n==0)//(G - R)
        {
        	XGpio_DiscreteWrite(&led, 1, 0x00080080);
        	for (j = 0 ; j < 12 ;j++)
        	{
        		wait_sec();
    		if( psb_check==1 )
    		{
    		  xil_printf("= = = R-E-S-E-T = = =\r\n");
    		  n = 0;
              goto L0;
    		}
    		if( psb_check==2 )
    		{
    		  xil_printf("= = =  S-T-O-P  = = =\r\n");
    		  XGpio_DiscreteWrite(&led, 1, 0x00000000);
    		  n = -1;
              goto L0;
    	    }
        	}
        	n = n +6;
        }
        if(n==6)
        {
           for(j=0;j<BLINK_TIMES;j++)
           {
        	wait_sec();
    		if( psb_check==1 )
    		{
    		  xil_printf("= = = R-E-S-E-T = = =\r\n");
    		  n = 0;
              goto L0;
    		}
    		if( psb_check==2 )
    		{
    		  xil_printf("= = =  S-T-O-P  = = =\r\n");
    		  XGpio_DiscreteWrite(&led, 1, 0x00000000);
    		  n = -1;
              goto L0;
    	    }
            XGpio_DiscreteWrite(&led, 1, 0x00000080);
        	wait_sec();
    		if( psb_check==1 )
    		{
    		  xil_printf("= = = R-E-S-E-T = = =\r\n");
    		  n = 0;
              goto L0;
    		}
    		if( psb_check==2 )
    		{
    		  xil_printf("= = =  S-T-O-P  = = =\r\n");
    		  XGpio_DiscreteWrite(&led, 1, 0x00000000);
    		  n = -1;
              goto L0;
    	    }
        	XGpio_DiscreteWrite(&led, 1, 0x00080080);
        	n++;
           }
        }
        if(n==8)
        {
           for(j=0;j<BLINK_TIMES;j++)
           {
            XGpio_DiscreteWrite(&led, 1, 0x00000880);
            wait_sec();
    		if( psb_check==1 )
    		{
    		  xil_printf("= = = R-E-S-E-T = = =\r\n");
    		  n = 0;
              goto L0;
    		}
    		if( psb_check==2 )
    		{
    		  xil_printf("= = =  S-T-O-P  = = =\r\n");
    		  XGpio_DiscreteWrite(&led, 1, 0x00000000);
    		  n = -1;
              goto L0;
    	    }
            XGpio_DiscreteWrite(&led, 1, 0x00000080);
            wait_sec();
    		if( psb_check==1 )
    		{
    		  xil_printf("= = = R-E-S-E-T = = =\r\n");
    		  n = 0;
              goto L0;
    		}
    		if( psb_check==2 )
    		{
    		  xil_printf("= = =  S-T-O-P  = = =\r\n");
    		  XGpio_DiscreteWrite(&led, 1, 0x00000000);
    		  n = -1;
              goto L0;
    	    }
            n++;
           }
        }
        if(n==10)
        {
        	XGpio_DiscreteWrite(&led, 1, 0x00800008);
        	for (j = 0 ; j < 12 ;j++)
        	{
        		wait_sec();
        		if( psb_check==1 )
        		{
        		  xil_printf("= = = R-E-S-E-T = = =\r\n");
        		  n = 0;
                  goto L0;
        		}
        		if( psb_check==2 )
        		{
        		  xil_printf("= = =  S-T-O-P  = = =\r\n");
        		  XGpio_DiscreteWrite(&led, 1, 0x00000000);
        		  n = -1;
                  goto L0;
        	    }
        	}
        	n = n +6;
        }
        if(n==16)
        {
           for(j=0;j<BLINK_TIMES;j++)
           {
        	wait_sec();
    		if( psb_check==1 )
    		{
    		  xil_printf("= = = R-E-S-E-T = = =\r\n");
    		  n = 0;
              goto L0;
    		}
    		if( psb_check==2 )
    		{
    		  xil_printf("= = =  S-T-O-P  = = =\r\n");
    		  XGpio_DiscreteWrite(&led, 1, 0x00000000);
    		  n = -1;
              goto L0;
    	    }
            XGpio_DiscreteWrite(&led, 1, 0x00000008);
        	wait_sec();
    		if( psb_check==1 )
    		{
    		  xil_printf("= = = R-E-S-E-T = = =\r\n");
    		  n = 0;
              goto L0;
    		}
    		if( psb_check==2 )
    		{
    		  xil_printf("= = =  S-T-O-P  = = =\r\n");
    		  XGpio_DiscreteWrite(&led, 1, 0x00000000);
    		  n = -1;
              goto L0;
    	    }
        	XGpio_DiscreteWrite(&led, 1, 0x00800008);
        	n++;
           }
        }
        if(n==18)
        {
           for(j=0;j<BLINK_TIMES;j++)
           {
         	wait_sec();
    		if( psb_check==1 )
    		{
    		  xil_printf("= = = R-E-S-E-T = = =\r\n");
    		  n = 0;
              goto L0;
    		}
    		if( psb_check==2 )
    		{
    		  xil_printf("= = =  S-T-O-P  = = =\r\n");
    		  XGpio_DiscreteWrite(&led, 1, 0x00000000);
    		  n = -1;
              goto L0;
    	    }
         	XGpio_DiscreteWrite(&led, 1, 0x00008008);
          	wait_sec();
    		if( psb_check==1 )
    		{
    		  xil_printf("= = = R-E-S-E-T = = =\r\n");
    		  n = 0;
              goto L0;
    		}
    		if( psb_check==2 )
    		{
    		  xil_printf("= = =  S-T-O-P  = = =\r\n");
    		  XGpio_DiscreteWrite(&led, 1, 0x00000000);
    		  n = -1;
              goto L0;
    	    }
        	XGpio_DiscreteWrite(&led, 1, 0x00000008);
        	wait_sec();
    		if( psb_check==1 )
    		{
    		  xil_printf("= = = R-E-S-E-T = = =\r\n");
    		  n = 0;
              goto L0;
    		}
    		if( psb_check==2 )
    		{
    		  xil_printf("= = =  S-T-O-P  = = =\r\n");
    		  XGpio_DiscreteWrite(&led, 1, 0x00000000);
    		  n = -1;
              goto L0;
    	    }
        	n++;
           }
        }
        if(n==20){n=0;}
	  }

}
Ejemplo n.º 7
0
static void
module_init(const char *kernel_path)
{
	struct bi_modulelist_entry *bi;
	struct stat st;
	const char *machine;
	char kdev[64];
	char *buf;
	boot_module_t *bm;
	size_t len;
	off_t off;
	int err, fd, nfail = 0;

	extract_device(kernel_path, kdev, sizeof(kdev));

	switch (netbsd_elf_class) {
	case ELFCLASS32:
		machine = "i386";
		break;
	case ELFCLASS64:
		machine = "amd64";
		break;
	default:
		machine = "generic";
		break;
	}
	if (netbsd_version / 1000000 % 100 == 99) {
		/* -current */
		snprintf(module_base, sizeof(module_base),
		    "/stand/%s/%d.%d.%d/modules", machine,
		    netbsd_version / 100000000,
		    netbsd_version / 1000000 % 100,
		    netbsd_version / 100 % 100);
	} else if (netbsd_version != 0) {
		/* release */
		snprintf(module_base, sizeof(module_base),
		    "/stand/%s/%d.%d/modules", machine,
		    netbsd_version / 100000000,
		    netbsd_version / 1000000 % 100);
	}

	/* First, see which modules are valid and calculate btinfo size */
	len = sizeof(struct btinfo_modulelist);
	for (bm = boot_modules; bm; bm = bm->bm_next) {
		fd = module_open(bm, 0, kdev, false);
		if (fd == -1) {
			bm->bm_len = -1;
			++nfail;
			continue;
		}
		err = fstat(fd, &st);
		if (err == -1 || st.st_size == -1) {
			printf("WARNING: couldn't stat %s\n", bm->bm_path);
			close(fd);
			bm->bm_len = -1;
			++nfail;
			continue;
		}
		bm->bm_len = st.st_size;
		close(fd);
		len += sizeof(struct bi_modulelist_entry);
	}

	/* Allocate the module list */
	btinfo_modulelist = alloc(len);
	if (btinfo_modulelist == NULL) {
		printf("WARNING: couldn't allocate module list\n");
		wait_sec(MODULE_WARNING_SEC);
		return;
	}
	memset(btinfo_modulelist, 0, len);
	btinfo_modulelist_size = len;

	/* Fill in btinfo structure */
	buf = (char *)btinfo_modulelist;
	btinfo_modulelist->num = 0;
	off = sizeof(struct btinfo_modulelist);

	for (bm = boot_modules; bm; bm = bm->bm_next) {
		if (bm->bm_len == -1)
			continue;
		fd = module_open(bm, 0, kdev, true);
		if (fd == -1)
			continue;
		image_end = (image_end + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
		len = pread(fd, (void *)image_end, SSIZE_MAX);
		if (len < bm->bm_len) {
			if ((howto & AB_SILENT) != 0)
				printf("Loading %s ", bm->bm_path);
			printf(" FAILED\n");
		} else {
			btinfo_modulelist->num++;
			bi = (struct bi_modulelist_entry *)(buf + off);
			off += sizeof(struct bi_modulelist_entry);
			strncpy(bi->path, bm->bm_path, sizeof(bi->path) - 1);
			bi->base = image_end;
			bi->len = len;
			switch (bm->bm_type) {
			    case BM_TYPE_KMOD:
				bi->type = BI_MODULE_ELF;
				break;
			    case BM_TYPE_IMAGE:
				bi->type = BI_MODULE_IMAGE;
				break;
			    case BM_TYPE_RND:
			    default:
				/* safest -- rnd checks the sha1 */
				bi->type = BI_MODULE_RND;
				break;
			}
			if ((howto & AB_SILENT) == 0)
				printf(" \n");
		}
		if (len > 0)
			image_end += len;
		close(fd);
	}
	btinfo_modulelist->endpa = image_end;

	if (nfail > 0) {
		printf("WARNING: %d module%s failed to load\n",
		    nfail, nfail == 1 ? "" : "s");
#if notyet
		wait_sec(MODULE_WARNING_SEC);
#endif
	}
}
Ejemplo n.º 8
0
int main(void)
{
	uint16_t	adcPVoltages[BUFSIZE] = {0UL};
	uint16_t	adcNVoltages[BUFSIZE] = {0UL};
	uint16_t	adcCurrents[BUFSIZE] = {0UL};
	uint16_t	adcGNDs[BUFSIZE] = {0UL};

	uint16_t	adcValue;
	int16_t	gndValue;
	int16_t	mVoltage, mCurrent;
	uint8_t	idx;
	float	fv, fa;
		
	// ポートの初期化
	DDRD = _BV(2);			 // RSTピンを出力に
	PORTC = _BV(4) | _BV(5); // SCL, SDA内蔵プルアップを有効
	
	
	// デバイスの初期化
	i2c_init();				 // AVR内蔵I2Cモジュールの初期化
	wait_ms(500);
	
	PORTD &= ~_BV(2);		 // RSTをLにします。リセット
	wait_ms(1);
	PORTD |= _BV(2);		 // RSTをHにします。リセット解除
	wait_ms(10);
	
	lcdInit();
	
	//LCD初期表示
	lcdSetPos(0, 0);	lcdPutStr("Volt + / Current");
	lcdSetPos(0, 1);	lcdPutStr("Volt - / GND");
	wait_sec(3);
	
	//消費電力削減のためADC使用ピンをデジタル入力禁止にする(ADC入力(アナログ)専用となる)
	DIDR0 |= (1 << ADC0D) | (1 << ADC1D) | (1 << ADC2D) | (1 << ADC3D);	//PC0,PC1,PC2,PC3
	
	//ADC動作設定
	ADCSRA = 0b10000110		//bit2-0: 110 = 64分周	8MHz/64=125kHz (50k〜200kHzであること)
		| (1 << ADIE);		//割り込み許可(スリープ対応)
	
	//ADCの基準電圧(AVCC)と入力ピンを設定する
	ADMUX =	(1 << REFS0) | ADC_SET_PVOLTAGE;

	
	//A/D変換ノイズ低減のスリープモードを設定する
	set_sleep_mode(SLEEP_MODE_ADC);
	sei();			//割り込み許可
	sleep_mode();	//A/Dコンバータ初期化として初回変換開始…変換中…変換完了
	adcValue = ADC;	//値の読み捨て

	idx = 0;
	
    while(1)
    {
		//===== GND電圧を測定する ===================================================
		//
		ADMUX =	ADC_SET_GND;
		wait_ms(10);	//安定待ち
		sleep_mode();	//スリープモード突入…変換中…変換完了
		
		adcGNDs[idx] = ADC;
		adcValue = total(adcGNDs);
		gndValue = (float)adcValue / BUFSIZE;
		fv = gndValue * F_VCC * 1000 / 1024;	// mV単位
		
		//電圧を表示する
		mVoltage = (int16_t)fv;
		lcdPutVoltage(mVoltage, 1, 1);
		
        //===== 正電圧を測定する ===================================================
		//
		ADMUX =	ADC_SET_PVOLTAGE;
		wait_ms(10);	//安定待ち
		sleep_mode();	//スリープモード突入…変換中…変換完了
		
		adcPVoltages[idx] = ADC;
		adcValue = total(adcPVoltages);
			
		//A/D変換値から電圧を求める
		fv = (((float)adcValue / BUFSIZE) - gndValue) * F_VCC * 1000 / (1024 * F_POSITIVE_V_RATE); // mV単位
			
		//電圧を表示する
		mVoltage = (int16_t)fv;
		lcdPutVoltage(mVoltage, 0, 0);
					
		//===== 負電圧を測定する ===================================================
		//
		ADMUX =	ADC_SET_NVOLTAGE;
		wait_ms(10);	//安定待ち
		sleep_mode();	//スリープモード突入…変換中…変換完了
			
		adcNVoltages[idx] = ADC;
		adcValue = total(adcNVoltages);
			
		//A/D変換値から電圧を求める
		fv = (((float)adcValue / BUFSIZE) - gndValue) * F_VCC * 1000 / (1024 * F_NEGATIVE_V_RATE); // mV単位
					
		//電圧を表示する
		mVoltage = (int16_t)fv;
		lcdPutVoltage(mVoltage, 0, 1);
			
		//===== 電流を測定する ====================================================
		//
		ADMUX =	ADC_SET_CURRENT;
		wait_ms(10);	//安定待ち
		sleep_mode();	//スリープモード突入…変換中…変換完了
			
		adcCurrents[idx] = ADC;
		adcValue = total(adcCurrents);

		// ADCの読み取り値が1000以上の場合測定不可とする
		if ((float)adcValue / BUFSIZE < 1000) {
	
			//A/D変換値から電圧を求め、電流を算出する
			fv = (((float)adcValue / BUFSIZE) - gndValue) * F_VCC * 1000 / (1024 * F_CURRENT_AMP); // mV単位
			fa = fv / F_SHUNT_R;	//mA単位
				
			//電流を表示する
			mCurrent = (int16_t)(fa * 10.0);	//0.1mA単位
			lcdPutCurrent(mCurrent, 1, 0);
		}
		else {		
			lcdLineClear(1, 0);
			lcdSetPos(8, 0);
			lcdPutStr("  OVER");
		}
		
		//次のループの準備
		if (++idx == BUFSIZE) idx = 0;
    }
	
	return 0;
}