Пример #1
0
void h8_sci_device::rx_done()
{
	if(!(ssr & SSR_FER)) {
		if((smr & SMR_PE) && rx_parity) {
			ssr |= SSR_PER;
			if(V>=1) logerror("Receive parity error\n");
		} else if(ssr & SSR_RDRF) {
			ssr |= SSR_ORER;
			if(V>=1) logerror("Receive overrun\n");
		} else {
			ssr |= SSR_RDRF;
			if(V>=1) logerror("Received %02x '%c'\n", rsr, rsr >= 32 && rsr < 127 ? rsr : '.');
			rdr = rsr;
		}
	}
	if(scr & SCR_RIE) {
		if(has_recv_error())
			intc->internal_interrupt(eri_int);
		else
			intc->internal_interrupt(rxi_int);
	}
	if((scr & SCR_RE) && !has_recv_error() && !is_sync_start())
		rx_start();
	else {
		clock_stop(CLK_RX);
		rx_state = ST_IDLE;
	}
}
/* PUBLIC */
void index_denial(Topform c, Indexop op, Clock clock)
{
  BOOL unit = (number_of_literals(c->literals) == 1);
  clock_start(clock);
  lindex_update(unit ? Unit_fpa_idx : Nonunit_fpa_idx, c, op);
  clock_stop(clock);
}  /* index_denial */
Пример #3
0
void clock_toggle()
{
	if(timer_counting)
		clock_stop();
	else
		clock_start();
}
Пример #4
0
void h8_sci_device::rx_done()
{
	if(!(ssr & SSR_FER)) {
		if((smr & SMR_PE) && rx_parity) {
			ssr |= SSR_PER;
			logerror("%s: Recieve parity error\n", tag());
		} else if(ssr & SSR_RDRF) {
			ssr |= SSR_ORER;
			logerror("%s: Recieve overrun\n", tag());
		} else {
			ssr |= SSR_RDRF;
			logerror("%s: Recieved %02x\n", tag(), rsr);
			rdr = rsr;
		}
	}
	if(scr & SCR_RIE) {
		if(has_recv_error())
			intc->internal_interrupt(eri_int);
		else
			intc->internal_interrupt(rxi_int);
	}
	if((scr & SCR_RE) && !has_recv_error() && !is_sync_start())
		rx_start();
	else {
		clock_stop(CLK_RX);
		rx_state = ST_IDLE;
	}
}
/* PUBLIC */
void set_semantics(Topform c)
{
  if (c->semantics == SEMANTICS_NOT_EVALUATED) {
    clock_start(Eval_clock);
    eval_in_interps(c);
    clock_stop(Eval_clock);
  }
}  /* set_semantics */
Пример #6
0
void h8_sci_device::rx_raised_edge()
{
	logerror("%s: rx_raised_edge state=%s bit=%d\n", tag(), state_names[rx_state], rx_bit);
	switch(rx_state) {
	case ST_START:
		if(rx_value) {
			clock_stop(CLK_RX);
			break;
		}
		rx_state = ST_BIT;
		rx_bit = smr & SMR_CHR ? 7 : 8;
		break;

	case ST_BIT:
		rx_parity ^= rx_value;
		rsr >>= 1;
		if(rx_value) {
			rx_parity = !rx_parity;
			rsr |= (smr & (SMR_CA|SMR_CHR)) == SMR_CHR ? 0x40 : 0x80;
		}
		rx_bit--;
		if(!rx_bit) {
			if(smr & SMR_CA)
				rx_done();
			else if(smr & SMR_PE) {
				rx_state = ST_PARITY;
				rx_bit = 1;
			} else {
				rx_state = ST_STOP;
				rx_bit = 1; // Always 1 on rx
			}
		}
		break;

	case ST_PARITY:
		rx_parity ^= rx_value;
		assert(rx_bit == 1);
		rx_state = ST_STOP;
		rx_bit = 1;
		break;

	case ST_STOP:
		assert(rx_bit == 1);
		if(!rx_value)
			ssr |= SSR_FER;
		else if((smr & SMR_PE) && rx_parity)
			ssr |= SSR_PER;
		rx_done();
		break;

	default:
		abort();
	}
	logerror("%s:             -> state=%s, bit=%d\n", tag(), state_names[rx_state], rx_bit);
}
Пример #7
0
int main(int argc, char *argv[]){
	unsigned int i;
	int sym;
	SSS_Matrix m;
	Clock clock;
	char* filename;
	double *x;
	double *y;
	
	parse_args(argc, argv);
	filename = argv[1];
	
	// Initialize matrices.
	sss_init_matrix(&m);
	
	// Load matrix from file
	//printf("Loading matrix \"%s\"\n", filename);
	sym = sss_load_matrix(filename, &m); // If matrix is non-symmetric, this call fails.
	
	//printf("Matrix is symmetric\n");
	
	// Print Matrix data
	//printf("SSS matrix data:\n");
	//sss_print_matrix(&m);
	
	// Initialize vectors for multiplication
	x = (double *)malloc(m.cols * sizeof(double));
	y = (double *)malloc(m.rows * sizeof(double));
	for(i = 0; i < m.cols; i++){
		x[i] = i+1;
	}
	//print_vector("\nx= ", x, m.cols);

	// Time matrix-vector product
	//printf("Calculating matrix-vector product for %u iterations...\n", iterations);
	clock_start(&clock);
	for(i=0; i < iterations; i++){
		sss_mvp2_sym(&m,x,y);
	}
	clock_stop(&clock);	
	//printf("SSS mvp time: %.2fus \n\n", clock.sec);
	//print_vector("y= \n", y, m.rows);
	
	// Print minimal info for testing purposes
	printf("%s\t%.2f\n", filename, clock.sec);
	
	// Free resources
	free(x);
	free(y);
	sss_free_matrix(&m);
	
	exit(EXIT_SUCCESS);
}
Пример #8
0
int main(int argc, char** argv) {

    size = 10;
    rank = 0;

    MPI_Init(&argc,&argv);
    clOptions options;
    if(getCla(argc, argv, &options)) {
        //NOTHING TO WORRY ABOUT
    } else {
        printf("command line options failure\n");

        return 1;
    }

    clock_start();
    takeTime(10);
    clock_stop(argv[0], options, "words");

    clock_start();
    takeTime(100);
    clock_stop(argv[0], options, "x1000");

    clock_start();
    takeTime(1000);
    clock_stop(argv[0], options, "E6");

    char * newtag;
    newtag = "hardcoded_string";

    clock_start();
    takeTime(100);
    clock_stop(argv[0], options, newtag);

    MPI_Finalize();

}
/* PUBLIC */
void index_literals(Topform c, Indexop op, Clock clock, BOOL no_fapl)
{
  BOOL unit = (number_of_literals(c->literals) == 1);
  clock_start(clock);
  if (!no_fapl || !positive_clause(c->literals))
    lindex_update(unit ? Unit_fpa_idx : Nonunit_fpa_idx, c, op);
  
  if (unit)
    lindex_update(Unit_discrim_idx, c, op);
  else {
    Ilist f = features(c->literals);
    if (op == INSERT)
      di_tree_insert(f, Nonunit_features_idx, c);
    else
      di_tree_delete(f, Nonunit_features_idx, c);
    zap_ilist(f);
  }
  clock_stop(clock);
}  /* index_literals */
Пример #10
0
Файл: o3.c Проект: niklasmh/ntnu
void SysTick_Handler() {
	if (state == STATE_COUNT_DOWN) {
		if (time.s <= 0) {
			if (time.m <= 0) {
				if (time.h <= 0) {
					state = STATE_ALARM;
					clock_stop();
					GPIO->ports[LED_PORT].DOUTSET = 1 << LED_PIN;
					update_time_display();
					return;
				}
				--time.h;
				time.m = 61;
			}
			--time.m;
			time.s = 61;
		}
		--time.s;
		update_time_display();
	}
}
Пример #11
0
void h8_sci_device::tx_dropped_edge()
{
	logerror("%s: tx_dropped_edge state=%s bit=%d\n", tag(), state_names[tx_state], tx_bit);
	switch(tx_state) {
	case ST_START:
		tx_cb(false);
		assert(tx_bit == 1);
		tx_state = ST_BIT;
		tx_bit = smr & SMR_CHR ? 7 : 8;
		break;

	case ST_BIT:
		tx_parity ^= (tsr & 1);
		tx_cb(tsr & 1);
		tsr >>= 1;
		tx_bit--;
		if(!tx_bit) {
			if(smr & SMR_CA) {
				if(!(ssr & SSR_TDRE))
					tx_start();
				else {
					tx_state = ST_LAST_TICK;
					tx_bit = 0;
				}
			} else if(smr & SMR_PE) {
				tx_state = ST_PARITY;
				tx_bit = 1;
			} else {
				tx_state = ST_STOP;
				tx_bit = smr & SMR_STOP ? 2 : 1;
			}
		}
		break;

	case ST_PARITY:
		tx_cb(tx_parity);
		assert(tx_bit == 1);
		tx_state = ST_STOP;
		tx_bit = smr & SMR_STOP ? 2 : 1;
		break;

	case ST_STOP:
		tx_cb(true);
		tx_bit--;
		if(!tx_bit) {
			if(!(ssr & SSR_TDRE))
					tx_start();
			else {
				tx_state = ST_LAST_TICK;
				tx_bit = 0;
			}
		}
		break;

	case ST_LAST_TICK:
		tx_state = ST_IDLE;
		tx_bit = 0;
		clock_stop(CLK_TX);
		tx_cb(1);
		ssr |= SSR_TEND;
		if(scr & SCR_TEIE)
			intc->internal_interrupt(tei_int);
		break;

	default:
		abort();
	}
	logerror("%s:             -> state=%s bit=%d\n", tag(), state_names[tx_state], tx_bit);
}
Пример #12
0
int main(int argc, char ** argv){


	//MPI Initialization
	MPI_Init(&argc,&argv);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	MPI_Comm_size(MPI_COMM_WORLD, &size);
	
	clOptions options;
	if(getCla(argc, argv, &options)){
		//NOTHING TO WORRY ABOUT
	}else{
		printf("command line options failure\n");
		
		return 1;
	}
	
	MPI_Status status_ignore;
	//MPI Particle Initialization
	//MPI_Datatype MPI_particle;
	create_MPI_struct(&MPI_particle);
	MPI_Type_commit(&MPI_particle);

	//Deprecated and dangerous as superseded by options structure
	//char * readFName =NULL;
	//char * writeFName = NULL;
	//char * defaultFName = "default.dat";
	//int writeData = 0;
	//int compareData = 0;
	
	//change to allow command line arguments
	

	//Setup
	if(options.timing >=1){
		clock_start();
	}
	char * initTypeTimingTag = "undefined_tag";
		
	int nParticles = options.nParticles;
	int nEachMax = pieceSize(nParticles, size, 0);
	double diff;
	particle * buffers[4];
	particle * spare_particle_pointer;
	buffers[0] = calloc(sizeof(particle), nEachMax);
	buffers[1] = calloc(sizeof(particle), nEachMax);
	buffers[2] = calloc(sizeof(particle), nEachMax);
	buffers[3] = calloc(sizeof(particle), nEachMax);
	
	int buf_index[3] = {rank, rank, rank};
	int nEach[3];
	nEach[0] = pieceSize(nParticles, size, rank);
	nEach[1] = pieceSize(nParticles, size, rank);
	nEach[2] = pieceSize(nParticles, size, rank);
	
	//diff =compareMultipleParticles(buffers[0], buffers[1], nEachMax);
	//Read or Randomize and print
	if(options.readInput == 1){
		if(options.verbosity>=2){
			printf("reading particles\n");
		}
		
		initTypeTimingTag = "init_read";
		readParticles(options.readFName, buffers[3], nParticles, size, rank);
	}else if(options.genFunction == 2){
		if(options.verbosity>=2){
			printf("generating particles\n");
		}
		
		initTypeTimingTag = "init_gen2";
		initialize_2(buffers[3], nEachMax);
		
		//fprintParticles(stdout, buffers[3], nEachMax);
	}else{
		//no input
		printf("error: no initial data specified\n");
		MPI_Finalize();
	}
	
	
	if(options.verbosity>=2){
		printf("should have particles now\n");
	}
	
	int i;
	for(i=0;i<nEachMax;i++){
		buffers[0][i] = buffers[3][i];
		buffers[0][i].dvx = 0;
		buffers[0][i].dvy = 0;
		buffers[0][i].dvz = 0;		
		buffers[1][i] = buffers[0][i];
		buffers[2][i] = buffers[0][i];
	}
	
	if(options.verbosity>=3){
		printf("rank %d printing particles set 0 \n", rank);
		fprintParticles(stdout, buffers[0], nEachMax);
		printf("rank %d printing particles set 1 \n", rank);
		fprintParticles(stdout, buffers[1], nEachMax);
		printf("rank %d printing particles set 2 \n", rank);
		fprintParticles(stdout, buffers[2], nEachMax);
		printf("rank %d printing particles set 3 \n", rank);
		fprintParticles(stdout, buffers[3], nEachMax);
	}
	
	//diff =compareMultipleParticles(buffers[0], buffers[3], nEachMax);

	//printf("rank %d diff = %g \t\t expected different \n", rank, diff);
	//Loop
		//Pass
		//Calculate
		//Collect
	if(options.timing == 2){
		clock_stop(argv[0], options, initTypeTimingTag);
	}
	if(options.timing >=1){
		clock_start();
	}
	
	
	int j;
	
	int passTimes;
	int passingBuffer = 0;
	for(passTimes = size; passTimes >0;passTimes -=3){
		for(i=0;i<passTimes;i++){
			MPI_pass(buffers, passingBuffer, nEachMax, 1, buf_index);
			nEach[passingBuffer] = pieceSize(nParticles, size, buf_index[passingBuffer]);
			printf("pass:%d:\t%d\t%d\t%d\n", rank, buf_index[0], buf_index[1], buf_index[2]);
			func(buffers, nEach, buf_index);
		}
		if(passTimes ==3){passTimes+=1;}
		passingBuffer == (passingBuffer+1)%3;
	}
	
	//Passing to rank that should have particle buffer
	if(options.verbosity>=0){
		printf("old:%d\t%d\t%d\t%d\n", rank, buf_index[0], buf_index[1], buf_index[2]);
	}
	int dist;
	passingBuffer =0;
	dist = (rank *2 - buf_index[passingBuffer])%size;
	MPI_pass(buffers, passingBuffer, nEachMax, dist, buf_index);
	nEach[passingBuffer] = pieceSize(nParticles, size, buf_index[passingBuffer]);

	passingBuffer =1;
	dist = (rank *2 - buf_index[passingBuffer])%size;
	MPI_pass(buffers, passingBuffer, nEachMax, dist, buf_index);
	nEach[passingBuffer] = pieceSize(nParticles, size, buf_index[passingBuffer]);

	passingBuffer =2;
	dist = (rank *2 - buf_index[passingBuffer])%size;
	MPI_pass(buffers, passingBuffer, nEachMax, dist, buf_index);
	nEach[passingBuffer] = pieceSize(nParticles, size, buf_index[passingBuffer]);

	if(options.verbosity>=0){
		printf("new:%d\t%d\t%d\t%d\n", rank, buf_index[0], buf_index[1], buf_index[2]);
	}
	
	if(options.verbosity>=3){
		printf("combining results\n");
	}
	if(options.verbosity>=3){
		printf("rank %d printing particles set 0 \n", rank);
		fprintParticles(stdout, buffers[0], nEachMax);
		printf("rank %d printing particles set 1 \n", rank);
		fprintParticles(stdout, buffers[1], nEachMax);
		printf("rank %d printing particles set 2 \n", rank);
		fprintParticles(stdout, buffers[2], nEachMax);
		printf("rank %d printing particles set 3 \n", rank);
		fprintParticles(stdout, buffers[3], nEachMax);
	}
	//Combine results

	for(i=0;i<nEach[0];i++){
		buffers[0][i].dvx += buffers[1][i].dvx+buffers[2][i].dvx;
		//buffers[0][i].dvx /= 6;
		buffers[1][i].dvx = buffers[0][i].dvx;
		buffers[2][i].dvx = buffers[0][i].dvx;
		
		buffers[0][i].dvy += buffers[1][i].dvy+buffers[2][i].dvy;
		//buffers[0][i].dvy /= 6;
		buffers[1][i].dvy = buffers[0][i].dvy;
		buffers[2][i].dvy = buffers[0][i].dvy;
		
		buffers[0][i].dvz += buffers[1][i].dvz+buffers[2][i].dvz;
		//buffers[0][i].dvz /= 6;
		buffers[1][i].dvz = buffers[0][i].dvz;
		buffers[2][i].dvz = buffers[0][i].dvz;
	}

	
	if(options.timing >= 1){
		clock_stop(argv[0], options, "no_duplicates");
	}
	if(rank == 0){
		//fprintParticles(stdout, buffers[3], nEachMax);
		//fprintParticles(stdout, buffers[0], nEachMax);

	}

	//Check results
	//use buffers[3]
	if(options.compareResults == 1){
		if(options.verbosity>=2){
			printf("comparing results");
		}	
		
		if(options.timing == 2){
			clock_start();
		}
		diff =compareMultipleParticles(buffers[0], buffers[3],  nEach[0]);
		if(options.timing == 2){
			clock_stop(argv[0], options, "comparison");
		}
		printf("rank %d diff = %g\n", rank, diff);
		
	}
	if(options.writeOutput == 1){
		if(options.timing == 2){
			clock_start();
		}
		writeParticles(options.writeFName, buffers[0], nParticles, size, rank);
		if(options.timing == 2){
			clock_stop(argv[0], options, "writing");
		}
	}
	//freeing and finalization
	free(buffers[0]);
	free(buffers[1]);
	free(buffers[2]);
	free(buffers[3]);


	//MPI Finalization
	MPI_Type_free(&MPI_particle);
	MPI_Barrier(MPI_COMM_WORLD);
	MPI_Finalize();	
}
Пример #13
0
void clock_reset()
{
	clock_stop();
	timer=0;
	clock_draw();
}
Пример #14
0
/*
 *	This function executes in signal handler context
 */
static void timerhandler(int whatever){
	// printf("timer tick\n");	

	if (clock_state == TIMER_STOPPED) return;
	long invalbuf[NUM_PAGES];
	int numinval = 0;
	int posval;
	clock_stop();

	for (int i = 0; i < NumNode; ++i){
		numinval = 0;
		for (int curr = activehead, last = curr;curr != -1; 
				 last = curr,curr = req_queues[curr].next_active){
			if (curr == activehead){
				last = curr;
			}
			if (curr_owners[curr] != i){	
				continue;
			}
			q_dta_t* the_queue = &(req_queues[curr]);
			if (the_queue->update_pending){	
				continue;
			}
			if (!the_queue->num_writers) continue;
			if (popped[curr]) continue;
			//better be true
			
			assert(the_queue->num_writers);
			qaddr = pagenum_to_addr(dsm_heaptop, curr, dsm_pagesize);
			int sessionfd = pop_queue(the_queue);
			popped[curr] = 1;
			
			if (!READ_REQ(sessionfd)){
				the_queue->num_writers--;
				//was writing; need to wait for update

				if (the_queue->listlen && !the_queue->num_writers){
					for (int i = 0;i < the_queue->listlen;i++){		
						the_queue->num_parallel_readers++;
					}
				}
				the_queue->update_pending = 1;
			}else{
				
				if (the_queue->num_parallel_readers > 0){
					//read requests granted before any writers came along
					//always at front of queue
					the_queue->num_parallel_readers --;		
				}
				
				if (the_queue->listlen && !the_queue->num_parallel_readers){
					int nextsessionfd = queue_top(the_queue);	
					dsm_send(0, dsm_pagesize, SERVER_PAGE,(char*)pagenum_to_addr(dsm_heaptop,curr,dsm_pagesize) , ABS(nextsessionfd));
				}
			}
			
			if ((!the_queue->listlen) || ABS(queue_top(the_queue)) != nid_to_sessionfd[i]){ 
				invalbuf[numinval++] = curr * dsm_pagesize + dsm_heaptop;
			}
			if (the_queue->listlen){
				//transfer ownership
				int tmp;
				posval = queue_top(the_queue);
				curr_owners[curr] = (short)(long)hash_get((void*)(long)ABS(posval),sessionfd_to_nid,&tmp);
				assert(tmp);
			}else{
				curr_owners[curr] = -1;
			}

			if (!the_queue->num_writers){
				if (the_queue->listlen){
					the_queue->q_state = QUEUE_READERS; 
				}else{
					the_queue->q_state = QUEUE_EMPTY;
				}
				//take off the active list
				if (curr == last){
					//delete from head
					activehead = req_queues[curr].next_active;

				}else{
					req_queues[last].next_active = req_queues[curr].next_active;
					curr = last;
				}
			}
		}
		//TODO: send invalidation message to client
		
		if (numinval) {
			//printf("about to send %d inv to %d\n",numinval, nid_to_sessionfd[i]);	
			dsm_send(0, sizeof(long)*numinval,SERVER_INVALIDATE, (char*)invalbuf, nid_to_sessionfd[i]);
		}	
	}
	if (activehead != -1){
		clock_start();
	}

	our_memset (popped, 0, sizeof(char)*NUM_PAGES);	

	//printf("END timer tick\n");
}
Пример #15
0
int main(void)
{
	// Initialize I/O
	DDRB  = 0x3e; // 00111110
	PORTB = 0x01; // 00000001
	DDRC  = 0x20; // 00100000
	PORTC = 0x03; // 00000011
	DDRD  = 0xff; // 11111111
	PORTD = 0xff; // 11111111

	// Load saved state, if any
	Load();

	// Setup the display timer...
	
	// prescaler 1/8; at 1MHz system clock, this gives us an overflow
	// at 488 Hz, providing a per-digit refresh rate of 97.6 Hz.
	TCCR0A = 0;
	TCCR0B = (1<<CS01); 

	// Output compare value B - controls blanking.
	// In full brightness mode, we'll make this happen immediately before the refresh,
	// In lower brightness modes, we'll make it happen sooner.
	OCR0A = pgm_read_byte(&brighttable[bright]);

	// Enable overflow and compare match interrupts
    TIMSK0 = (1<<TOIE0) | (1<<OCIE0A);


	// Setup the RTC...
	gMin = 0;
	gSec = 0;

    // select asynchronous operation of Timer2
	ASSR = (1<<AS2);        

	// select prescaler: 32.768 kHz / 128 = 1 sec between each overflow
	TCCR2A = 0;
    TCCR2B = (1<<CS22) | (1<<CS20);             
	
    // wait for TCN2UB and TCR2UB to be cleared
	while((ASSR & 0x01) | (ASSR & 0x04));      
	 
    // clear interrupt-flags
	TIFR2 = 0xFF;           
    

	// init the state machine
	enum State state = ST_TIME;
	enum State prevstate = ST_TIME;
	uint8_t remaining = 0;
	uint8_t cmode = 0;

    // Enable interrupts
	sei();

	// Do some stuff
	for(;;)
	{
		uint8_t buttons = GetButtons();

		if ((buttons & BUTTON_RIGHT) && (state < ST_BRIGHT)) {
			prevstate = state;
			remaining = count;
			cmode = 0;
			buttons = 0;
			state = ST_RUN_PRIME;
		} 

	newstate:
		switch(state)
		{
		case ST_TIME:
			DisplayNum(stime[0], HIGH_POS, 0, 3);
			display[COLON_POS] = COLON;
			DisplayNum(stime[1], LOW_POS, 0, 0);
			if (buttons & BUTTON_LEFT) {
				state = ST_DELAY;
			} else if (buttons & BUTTON_UP) {
				state = ST_TIME_SET_MINS;
			}
			break;
		case ST_DELAY:
			DisplayNum(delay[0], HIGH_POS, 0, 3);
			display[COLON_POS] = LOWDOT;
			DisplayNum(delay[1], LOW_POS, 0, 0);
			if (buttons & BUTTON_LEFT) {
				state = ST_COUNT;
			} else if (buttons & BUTTON_UP) {
				state = ST_DELAY_SET_MINS;
			}
			break;
		case ST_COUNT:
			DisplayAlnum('\xC6', count, 0);
			if (buttons & BUTTON_LEFT) {
				state = ST_MLU;
			} else if (buttons & BUTTON_UP) {
				state = ST_COUNT_SET;
			}
			break;
		case ST_MLU:
			DisplayAlnum('\xC7', mlu, 0);
			if (buttons & BUTTON_LEFT) {
				state = ST_BRIGHT;
			} else if (buttons & BUTTON_UP) {
				state = ST_MLU_SET;
			}
			break;
/* I'll put this in once there's more than one option ;)
		case ST_OPTIONS:
			display[0] = '\xC0';	// 00111111 = 'O'
			display[1] = '\x8C';	// 01110011 = 'P'
			display[2] = EMPTY;
			display[3] = '0x87';	// 01111000 = 't'
			display[4] = '0x92';	// 01101101 = 'S'
			if (buttons & BUTTON_LEFT) {
				state = ST_TIME;
			} else if (buttons & BUTTON_UP) {
				state = ST_BRIGHT;
			}
			break;
*/
		case ST_BRIGHT:
			DisplayAlnum('\x83', 4 - bright, 0); // 10000011 = 'b'
			if (buttons & BUTTON_LEFT) {
				state = ST_TIME;
			} else if (buttons & BUTTON_UP) {
				bright = (bright - 1) & 3;
				OCR0A = pgm_read_byte(&brighttable[bright]);
			} else if (buttons & BUTTON_RIGHT) {
				Save();
				state = ST_SAVED;
				remaining = 15;
			}
			break;
		case ST_SAVED:
			display[0] = '\x92'; // 01101101 = 'S'
			display[1] = '\x88'; // 01110111 = 'A'
			display[2] = EMPTY;
			display[3] = '\xc1'; // 00111110 = 'V'
			display[4] = '\x86'; // 01111001 = 'E'
			if (--remaining == 0)
				state = ST_BRIGHT;
			break;
		case ST_TIME_SET_MINS:
			DisplayNum(stime[0], HIGH_POS, 0x40, 0);
			display[COLON_POS] = COLON;
			DisplayNum(stime[1], LOW_POS, 0, 0);
			if (EditNum(&stime[0], buttons, 100)) {
				state = ST_TIME_SET_SECS;
			}
			break;
		case ST_TIME_SET_SECS:
			DisplayNum(stime[0], HIGH_POS, 0, 0);
			display[COLON_POS] = COLON;
			DisplayNum(stime[1], LOW_POS, 0x40, 0);
			if (EditNum(&stime[1], buttons, 60)) {
				state = ST_TIME;
			}
			break;
		case ST_DELAY_SET_MINS:
			DisplayNum(delay[0], HIGH_POS, 0x40, 0);
			display[COLON_POS] = LOWDOT;
			DisplayNum(delay[1], LOW_POS, 0, 0);
			if (EditNum(&delay[0], buttons, 100)) {
				state = ST_DELAY_SET_SECS;
			}
			break;
		case ST_DELAY_SET_SECS:
			DisplayNum(delay[0], HIGH_POS, 0, 0);
			display[COLON_POS] = LOWDOT;
			DisplayNum(delay[1], LOW_POS, 0x40, 0);
			if (EditNum(&delay[1], buttons, 60)) {
				state = ST_DELAY;
			}
			break;
		case ST_COUNT_SET:
			DisplayAlnum('\xC6', count, 0x40);
			if (EditNum(&count, buttons, 100)) {
				state = ST_COUNT;
			}
			break;
		case ST_MLU_SET:
			DisplayAlnum('\xC7', mlu, 0x40);
			if (EditNum(&mlu, buttons, 60)) {
				state = ST_MLU;
			}
			break;
		case ST_RUN_PRIME:
			if (mlu > 0) {
				state = ST_MLU_PRIME;
				SHUTTER_ON();
				DisplayAlnum('\xC7', mlu, 0);
			} else {
				InitRun(&state);
				goto newstate;
			}
			break;
		case ST_RUN_AUTO:
			if (gDirection == 0) {
				// time has elapsed.  close the shutter and stop the timer.
				SHUTTER_OFF();
				clock_stop();
	
				if (remaining > 0)
				{
					if (--remaining == 0)
					{
						// we're done.
						state = prevstate;
						break;
					}
				}

				gMin = delay[0];
				gSec = delay[1];
				gDirection = -1;
				state = ST_WAIT;
				clock_start();			
				goto newstate;
			}
			// fall through
		case ST_RUN_MANUAL:
			if (cmode == 0) {
				// time left in this exposure
				DisplayNum(gMin, HIGH_POS, 0, 3);
				DisplayNum(gSec, LOW_POS, 0, 0);
			} else {
				// remaining exposures
				DisplayAlnum('\xC6', remaining, 0);
			}
			display[COLON_POS] = (TCNT2 & 0x80) ? EMPTY : COLON;
			break;
		case ST_MLU_PRIME:
			SHUTTER_OFF();
			gMin = 0;
			gSec = mlu;
			gDirection = -1;
			state = ST_MLU_WAIT;
			clock_start();
			// fall-through
		case ST_MLU_WAIT:
			DisplayAlnum('\xC7', gSec, 0);
			if (gDirection == 0)
			{
				// MLU wait period has elapsed
				clock_stop();
				InitRun(&state);
				goto newstate;
			}
			break;
		case ST_WAIT:
			if (cmode == 0) {
				// wait time
				DisplayNum(gMin, HIGH_POS, 0, 3);
				DisplayNum(gSec, LOW_POS, 0, 0);
			} else {
				// remaining exposures
				DisplayAlnum('\xC6', remaining, 0);
			}
			display[COLON_POS] = (TCNT2 & 0x80) ? EMPTY : LOWDOT;
			if (gDirection == 0)
			{
				// wait period has timed out;
				// stop the timer and start a new cycle
				clock_stop();
				state = ST_RUN_PRIME;
				goto newstate;
			}
			break;
		}

		if (state >= ST_RUN_PRIME) {
			// check keys
			if (buttons & BUTTON_RIGHT) {
				// canceled.
				clock_stop();
				SHUTTER_OFF();

				// if counting up, freeze the count here
				if (state == ST_RUN_MANUAL) {
					stime[0] = gMin;
					stime[1] = gSec;
				}
		
				state = prevstate;
			} else if ((buttons & BUTTON_LEFT) && (count > 1)) {
				// toggle display, time left vs. count left
				cmode = (cmode + 1) & 1;
			} else if (buttons & BUTTON_UP) {
				// adjust brightness
				bright = (bright - 1) & 3;
				OCR0A = pgm_read_byte(&brighttable[bright]);
			}
		}
	
		Sleep(48);	// approx 50ms at 1MHz
 	}
}
Пример #16
0
int main(int argc, char *argv[]){
	unsigned int i;
	int sym;
	CSR_Matrix csr;
	Clock clock;
	char* filename;
	double *x;
	double *y;
	
	parse_args(argc, argv);
	filename = argv[1];
	
	// Initialize matrices.
	csr_init_matrix(&csr);
	
	// Load matrix from file into COO.
	printf("Loading matrix \"%s\"\n", filename);
	sym = csr_load_matrix(filename, &csr);
	
	if(sym) printf("Matrix is symmetric\n");
	else	printf("Matrix is general (non-symmetric)\n");
	
	// Print Matrix data
	//printf("CSR matrix data:\n");
	//csr_print_matrix(&csr);
	
	// Initialize vectors for multiplication
	x = (double *)malloc(csr.cols * sizeof(double));
	y = (double *)malloc(csr.rows * sizeof(double));
	for(i = 0; i < csr.cols; i++){
		x[i] = i+1;
	}
	//print_vector("\nx= ", x, coo.cols);

	printf("Calculating matrix-vector product for %u iterations...\n", iterations);

	if(sym){
		// Time CSR matrix-vector product
		// clock_start(&clock);
		// for(i=0; i < iterations; i++){
			// csr_mvp_sym(&csr,x,y);
		// }
		// clock_stop(&clock);
		// printf("CSR mvp time: %.2fus \n", clock.sec);
				
		// Time CSR matrix-vector product
		clock_start(&clock);
		for(i=0; i < iterations; i++){
			csr_mvp_sym2(&csr,x,y);
		}
		clock_stop(&clock);
		printf("CSR mvp2 time: %.2fus \n\n", clock.sec);
				
		// Time CSR matrix-vector product
		// clock_start(&clock);
		// for(i=0; i < iterations; i++){
			// csr_mvp_sym_oski_lo(&csr,x,y);
		// }
		// clock_stop(&clock);
		// printf("CSR mvp oski time: %.2fus \n\n", clock.sec);
		
		// Time CSR matrix-vector product
		// clock_start(&clock);
		// for(i=0; i < iterations; i++){
			// csr_mvp_sym_oski2(&csr,x,y);
		// }
		// clock_stop(&clock);
		// printf("CSR mvp oski2 time: %.2gs \n", clock.sec);
		
		//print_vector("y= ", y, csr.rows);
	}else{
		// Time CSR matrix-vector product
		// clock_start(&clock);
		// for(i=0; i < iterations; i++){
			// csr_mvp(&csr,x,y);
		// }
		// clock_stop(&clock);
		// printf("CSR mvp time: %.2gs \n", clock.sec);
		//print_vector("y= ", y, csr.cols);
		
		// Time CSR matrix-vector product
		// clock_start(&clock);
		// for(i=0; i < iterations; i++){
			// csr_mvp2(&csr,x,y);
		// }
		// clock_stop(&clock);
		// printf("CSR mvp2 time: %.2gs \n", clock.sec);
		//print_vector("y= ", y, csr.cols);
		
		// Time CSR matrix-vector product
		// clock_start(&clock);
		// for(i=0; i < iterations; i++){
			// csr_mvp_oski(&csr,x,y);
		// }
		// clock_stop(&clock);
		// printf("CSR mvp oski time: %.2gs \n", clock.sec);
		//print_vector("y= ", y, csr.cols);
		
		// Time CSR matrix-vector product
		clock_start(&clock);
		for(i=0; i < iterations; i++){
			csr_mvp_oski2(&csr,x,y);
		}
		clock_stop(&clock);
		printf("CSR mvp oski2 time: %.2gs \n\n", clock.sec);
		//print_vector("y= ", y, csr.cols);
	}
	
	// Free resources
	free(x);
	free(y);
	csr_free_matrix(&csr);
	
	exit(EXIT_SUCCESS);
}
Пример #17
0
static void clock_destroy(GtkObject *object){
	g_return_if_fail(object != NULL);
	clock_stop(CLOCK(object));
	GTK_OBJECT_CLASS(parent_class)->destroy(object);
}