示例#1
0
文件: simple.c 项目: GamerSource/qemu
static gpointer writeout_thread(gpointer opaque)
{
    TraceRecord *recordptr;
    union {
        TraceRecord rec;
        uint8_t bytes[sizeof(TraceRecord) + sizeof(uint64_t)];
    } dropped;
    unsigned int idx = 0;
    int dropped_count;
    size_t unused __attribute__ ((unused));

    for (;;) {
        wait_for_trace_records_available();

        if (g_atomic_int_get(&dropped_events)) {
            dropped.rec.event = DROPPED_EVENT_ID,
            dropped.rec.timestamp_ns = get_clock();
            dropped.rec.length = sizeof(TraceRecord) + sizeof(uint64_t),
            dropped.rec.pid = trace_pid;
            do {
                dropped_count = g_atomic_int_get(&dropped_events);
            } while (!g_atomic_int_compare_and_exchange(&dropped_events,
                                                        dropped_count, 0));
            dropped.rec.arguments[0] = dropped_count;
            unused = fwrite(&dropped.rec, dropped.rec.length, 1, trace_fp);
        }

        while (get_trace_record(idx, &recordptr)) {
            unused = fwrite(recordptr, recordptr->length, 1, trace_fp);
            writeout_idx += recordptr->length;
            free(recordptr); /* don't use g_free, can deadlock when traced */
            idx = writeout_idx % TRACE_BUF_LEN;
        }

        fflush(trace_fp);
    }
    return NULL;
}
示例#2
0
文件: netfind.c 项目: sli92/netcon
void netfind_app_call(void)
{
        if(uip_poll()) {
                switch(netfind_s.state) {
                        case NETFIND_STATE_WAIT:
                                if(get_clock() > netfind_s.send_answer_time)
                                        netfind_s.state = NETFIND_STATE_SEND_ANSWER;
                                break;

                        case NETFIND_STATE_SEND_ANSWER:
                                netfind_send_answer();
                                break;
                }
        }

        if(uip_newdata()) {
                switch(netfind_s.state) {
                        case NETFIND_STATE_IDLE:
                                netfind_handle_request();
                                break;
                }
        }
}
示例#3
0
文件: netfind.c 项目: sli92/netcon
void netfind_handle_request(void)
{
        char *appdata = (char *)uip_appdata;

        // Check if device has a valid IP-Address
        if((uip_hostaddr[0] | uip_hostaddr[1]) == 0)
                return;

        if(strcmp_P(appdata, PSTR("netfind")) != 0)
                return;

        // Check version
        if(appdata[7] > NETFIND_VERSION)
                return;

        if(filter_ethaddr(uip_ethaddr.addr, appdata + 8) == 0)
                return;

        netfind_s.send_answer_time = get_clock() + (random() %
                                 (2 * CLOCK_TICKS_PER_SECOND));

        netfind_s.state = NETFIND_STATE_WAIT;
}
示例#4
0
    // virtual function derived from class DBSCAN
    void DBSCAN_Grid::fit(){
        prepare_labels(cl_d.size1());

        float begin;
        begin = get_clock();
        hash_construct_grid();
        cout<<get_clock() - begin<<endl;

        begin = get_clock();
        determine_core_point_grid();        
        cout<<get_clock() - begin<<endl;

        begin = get_clock();
        merge_clusters();
        cout<<get_clock() - begin<<endl;
        
        determine_boarder_point();
    }
示例#5
0
文件: netfind.c 项目: sli92/netcon
void netfind_send_answer(void)
{
        uint32_t uptime = ntohl(get_clock());
        char *appdata = (char *)uip_appdata;

        strcpy_P(appdata, PSTR("netdiscover"));
        appdata += 11;

        memcpy(appdata, uip_ethaddr.addr, 6);
        appdata += 6;

        memcpy(appdata, &uptime, 4);
        appdata += 4;

        netfind_add_string(appdata, hostname, 32);
        appdata += 32;

        netfind_add_string(appdata, place, 32);
        appdata += 32;

        uip_send(uip_appdata, appdata - (char *)uip_appdata);

        netfind_s.state = NETFIND_STATE_IDLE;
}
示例#6
0
int64_t qemu_get_clock_ns(QEMUClock *clock)
{
    int64_t now, last;

    switch(clock->type) {
    case QEMU_CLOCK_REALTIME:
        return get_clock();
    default:
    case QEMU_CLOCK_VIRTUAL:
        if (use_icount) {
            return cpu_get_icount();
        } else {
            return cpu_get_clock();
        }
    case QEMU_CLOCK_HOST:
        now = get_clock_realtime();
        last = clock->last;
        clock->last = now;
        if (now < last) {
            notifier_list_notify(&clock->reset_notifiers, &now);
        }
        return now;
    }
}
示例#7
0
文件: time.c 项目: 710leo/LVS
static cycle_t read_tod_clock(struct clocksource *cs)
{
	return get_clock();
}
示例#8
0
文件: time.c 项目: 710leo/LVS
void read_persistent_clock(struct timespec *ts)
{
	tod_to_timeval(get_clock() - TOD_UNIX_EPOCH, ts);
}
int main(int argc, char *argv[]) {
	//SETUP CODE
	int i,j,k;
	double **A,**B,**C,sum;
	double t1,t2;
	int numthreads,tid;
	
	#pragma omp parallel
        {
                numthreads = omp_get_num_threads();
                tid = omp_get_thread_num();
                if(tid==0)
                        printf("Running multiply with %d threads\n",numthreads);
        }

	A = create_matrix();
	B = create_matrix();
	C = (double**) malloc(sizeof(double*)*n);
	for (i=0;i<n;i++) {
		C[i] = (double*) malloc(sizeof(double)*n);
	}
	//END SETUP CODE

	t1 = get_clock();

	//BEGIN MAIN ROUTINE
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) {
	 			sum = 0;
	                        #pragma omp parallel shared(A,B,C) private(k) reduction(+:sum)
	                        {
		                    #pragma omp for 
				    for(k=0;k<n;k++) {
				        sum += A[i][k] * B[k][j];
				    }
	                        }
				C[i][j] = sum;
			}
		}
	//END MAIN ROUTINE

	t2 = get_clock();
	printf("Time: %lf\n",(t2-t1));

        if(SAVE) {
                // Output Result
                char outfile[100];
                sprintf(outfile,"multiply_out_%d.txt",numthreads);
                printf("Outputting solution to %s\n",outfile);
                FILE *fp = fopen(outfile,"w");
                for(i=0; i<n; i++) {
			for(j=0; j<n; j++) {
                       		fprintf(fp,"%lf\n",C[i][j]);
			}
		}
                fclose(fp);
        }

	//CLEANUP CODE
	free_matrix(A);
	free_matrix(B);
	free_matrix(C);
	return 0;

}
int main(int argc, char *argv[]) {
	//SETUP CODE
        int i,j,ii,jj, istart,iend,jstart, jend;
	double **A;
	double t1,t2;
	int numthreads,tid;

        #pragma omp parallel
        {
                numthreads = omp_get_num_threads();
                tid = omp_get_thread_num();
                if(tid==0)
                        printf("Running transpose with %d threads\n",numthreads);
        }

	A = create_matrix();

        /* Creating matrix B which will contained the transposed version of A */
	double** B = (double**) malloc(sizeof(double*)*n);
	for (i=0;i<n;i++) {
		B[i] = (double*) malloc(sizeof(double)*n);
	}
       
        int bsize = 32, r; 
        int loop_unroll_limit = 6;

        printf("Working with bsize = %d\t", bsize);

        for(loop_unroll_limit = 1 ; loop_unroll_limit < 100 ; loop_unroll_limit ++) {
            printf("Working with loop_unroll_limit = %d\t",loop_unroll_limit);

	    t1 = get_clock();

	    //BEGIN MAIN ROUTINE
            for (ii = 0; ii<n; ii+=bsize) {
              istart = ii ; iend = MIN(ii+bsize, n);
              for (jj = 0; jj<n; jj+=bsize) {
                jstart = jj ; jend = MIN(jj+bsize, n);

                /* For each block, execute the remainder loop sequentially
                ** without using loop unroll
                */
                int remainder = MIN(bsize, n - istart)%loop_unroll_limit;
                for (r = istart ; r < istart + remainder ; r ++) {
                  for(j = jstart ; j < jend; j ++) {
                    B[r][j] = A[j][r];
                  }
                } 
	        for(i = r;i < iend; i = i + loop_unroll_limit) {
		  for(j=jstart ;j < jend;j++) {
                        int h;
                        for(h = 0 ; h < loop_unroll_limit; h++) {
			B[i  + h][j] = A[j][i  +  h];
                        }
	          }
                }
	      }
            }
	//END MAIN ROUTINE

	    t2 = get_clock();
	    printf("Time: %lf\n",(t2-t1));
}

	if(SAVE) {
                // Output Result
                char outfile[100];
                sprintf(outfile,"transpose_out_%d.txt",numthreads);
                printf("Outputting solution to %s\n",outfile);
                FILE *fp = fopen(outfile,"w");
                for(i=0; i<n; i++) {
			for(j=0; j<n; j++) {
                        	fprintf(fp,"%lf\n",B[i][j]);
			}
		}
                fclose(fp);
        }

	//CLEANUP CODE
	free_matrix(A);
	return 0;

}
示例#11
0
static void daemon_thread(void)
{
	static INT32 thread_run = 1;
	struct mp_node_t *p_node_it = NULL;
	struct mp_mem_head_t *p_mem_head = NULL;
	M_CC_MSG_t msg = {0, 0, 0};
	UINT64 curr_time = 0;
	HRESULT ret = E_FAIL;
	INT32 timeout_occured = 0;

	p_mem_head = (struct mp_mem_head_t *)h_mem;
	notify_watchdog(M_SM_WD_APP_START);

	while (thread_run) {
		if (M_OSAL_Task_MsgQ_GetTry(&h_daemon, &msg) == S_OK) {
			if (msg.m_MsgID == MSG_CMD_EXIT) {
				M_DAEMON_PRINT(LOG_INFO,
						"daemon_thread is to exit.\n");
				thread_run = 0;
			}
			else
				M_DAEMON_PRINT(LOG_INFO,
						"msg id undefined: 0x%X\n",
						msg.m_MsgID);
		}
#ifndef __BIONIC__
		ret = mp_sem_acquire(semid);
		M_DAEMON_ASSERT(ret == 0);
#endif
		mp_update_pool(h_mem);

		/* iterate each module node */
		curr_time = get_clock();
		timeout_occured = 0;
		/*
		 * FIXME
		 * We do need a lock here to avoid some maybe
		 * concurrency issue. In RegisterModule, before the
		 * whole register flow finish, daemon should not access
		 * the data of the module which is being registered.
		 */
		for (p_node_it = p_mem_head->p_node_first;
				(p_node_it != NULL) && (p_node_it->data.ready == 1);
				p_node_it = p_node_it->p_next) {
			if (p_node_it->data.callback_fn != NULL) {
				ret = p_node_it->data.callback_fn();
				if (ret == S_OK)
					p_node_it->data.time = curr_time;
				else
					M_DAEMON_PRINT(LOG_WARN,
							"#%d %s return fail!\n",
							p_node_it->data.mid,
							p_node_it->data.attr.name);
			}
			if (curr_time - p_node_it->data.time >
					(UINT64)p_node_it->data.attr.timeout) {
				M_DAEMON_PRINT(LOG_ERROR, "#%d %s timeout (%llu)\n",
						p_node_it->data.mid,
						p_node_it->data.attr.name,
						curr_time - p_node_it->data.time);
				timeout_occured = 1;
			}
			if (p_node_it->data.critical_error == 1) {
				M_DAEMON_PRINT(LOG_ERROR, "#%d %s critical error occured\n",
						p_node_it->data.mid,
						p_node_it->data.attr.name);
				timeout_occured = 1;
				break;
			}
			M_DAEMON_PRINT(LOG_DEBUG, "#%d last: %llu -> curr: %llu\n",
					p_node_it->data.mid, p_node_it->data.time, curr_time);
		}
#ifndef __BIONIC__
		ret = mp_sem_release(semid);
		M_DAEMON_ASSERT(ret == 0);
#endif
		if (timeout_occured == 0) {
			M_DAEMON_PRINT(LOG_DEBUG, "kick off watchdog\n");
			notify_watchdog(M_SM_WD_Kickoff);
		} else {
			M_DAEMON_PRINT(LOG_ERROR, "daemon_thread exit\n");
			thread_run = 0;
		}
		M_OSAL_Task_Sleep(500);
	}
	monitor_exit();
	return;
}
int main(int argc, char *argv[]) {
	//SETUP CODE
        int i,j,ii,jj;
	double **A;
	double t1,t2;
	int numthreads,tid;

        #pragma omp parallel
        {
                numthreads = omp_get_num_threads();
                tid = omp_get_thread_num();
                if(tid==0)
                        printf("Running transpose with %d threads\n",numthreads);
        }

	A = create_matrix();

        /* Creating matrix B which will contained the transposed version of A */
	double** B = (double**) malloc(sizeof(double*)*n);
	for (i=0;i<n;i++) {
		B[i] = (double*) malloc(sizeof(double)*n);
	}
       
        int bsize; 
        for(bsize = 1 ; bsize < 5000 ; bsize = bsize * 2) {
            printf("Working with bsize = %d\t", bsize);
	    t1 = get_clock();

	    //BEGIN MAIN ROUTINE
            for (ii = 0; ii<n; ii+=bsize) {
              for (jj = 0; jj<n; jj+=bsize) {
	        for(i=ii;i < MIN(ii+bsize, n); i++) {
		  for(j=jj ;j<MIN(jj+bsize,n);j++) {
			B[i][j] = A[j][i];
	          }
                }
	      }
            }
	//END MAIN ROUTINE

	    t2 = get_clock();
	    printf("Time: %lf\n",(t2-t1));
        }

	if(SAVE) {
                // Output Result
                char outfile[100];
                sprintf(outfile,"transpose_out_%d.txt",numthreads);
                printf("Outputting solution to %s\n",outfile);
                FILE *fp = fopen(outfile,"w");
                for(i=0; i<n; i++) {
			for(j=0; j<n; j++) {
                        	fprintf(fp,"%lf\n",B[i][j]);
			}
		}
                fclose(fp);
        }

	//CLEANUP CODE
	free_matrix(A);
	return 0;

}
示例#13
0
    void radar::inc_theta()
    {
        theta += scan_rate * get_clock();
	if (theta > 360)
	    theta -= 360;
    }
示例#14
0
/* We obtain the current time, but we don't store it in the last read time */
UINT64 Clock_getCurrentTime_nstore (void)
{
	return (UINT64)get_clock();
}
int main(int argc, char *argv[]) {
    int i,j,k,size,nbuckets,count;
    double t1,t2;
    long long *splitters,*elmnts,*sample,**buckets,*nsplitters;
    long long tol, error, maxval, minval, check;
    int *bucket_sizes,*hist,*cumulative,*ideal;
    bool repeat,checkMax;

    if (argc != 2) {
        fprintf(stderr,
            "Wrong number of arguments.\nUsage: %s N \n",argv[0]);
        return -1;
    }

    size = atoi(argv[1]);
    nbuckets = 12;
    tol = .3*((long long)size)/nbuckets;

    splitters = (long long*)malloc(sizeof(long long)*nbuckets);
    nsplitters = (long long*)malloc(sizeof(long long)*nbuckets);
    elmnts = (long long*)malloc(sizeof(long long)*size);
    sample = (long long*)malloc(sizeof(long long)*size);
    buckets = (long long**)malloc(sizeof(long long*)*nbuckets);
    for(i=0;i<nbuckets;i++) {
        buckets[i] = (long long*)malloc(sizeof(long long)*size);
    }
    bucket_sizes = (int*)malloc(sizeof(int)*nbuckets);
    hist = (int*)malloc(sizeof(int)*nbuckets);
    cumulative = (int*)malloc(sizeof(int)*nbuckets);
    ideal = (int*)malloc(sizeof(int)*nbuckets);

    //Fill elmnts with random numbers
    srand(SEED);
    for(i=0;i<size;i++) {
        elmnts[i] = rand()%100;
    }

    #if CHECK
    check = 0;
    for(i=0;i<size;i++) {
        check ^= elmnts[i];
    }
    #endif

    t1 = get_clock();

    //sort each bucket individually
    for(i=0;i<nbuckets;i++) {
        qsort(&elmnts[i*size/nbuckets],size/nbuckets,sizeof(long long),
            compare);
    }

    //select the initial splitters
    for(i=0;i<nbuckets-1;i++) {  
        splitters[i] = elmnts[size/nbuckets/nbuckets*(i+1)];
    }
    maxval = elmnts[0];
    minval = elmnts[0];
    for(i=0;i<size;i++) {
        if(elmnts[i] > maxval) {
            maxval = elmnts[i];
        }
        if(elmnts[i] < minval) {
            minval = elmnts[i];
        }
    }
    maxval+=1;
    splitters[nbuckets-1] = maxval;

    for(i=0;i<nbuckets;i++) {
        ideal[i] = size/nbuckets*(i+1);
    }

    //Create histogram
    repeat = true;
    while(repeat) {
        repeat = false;
        for(i=0;i<nbuckets;i++) {
            hist[i] = 0;
        }
        for(i=0;i<nbuckets;i++) { 
            k = 0;
            for(j=i*size/nbuckets;j<(i+1)*size/nbuckets;j++) {
                if(elmnts[j] < splitters[k]) {
                    hist[k]++;
                }
                else {
                    while(elmnts[j] > splitters[k]) {
                        k++;
                    }
                    hist[k]++;
                }
            }
        }
        
        cumulative[0] = hist[0];
        for(i=1;i<nbuckets;i++) {
            cumulative[i] = cumulative[i-1]+hist[i];
        }

        //Check the global histogram for goodness of split
        for(i=0;i<nbuckets-1;i++) {
            nsplitters[i] = splitters[i];
            error = cumulative[i]-ideal[i]; 
            if(abs(error) > tol) {
                repeat = true;
                //update probe by scaled linear interpolation
                if(error > tol) {
                    k = i-1;
                    while(k > -1 && cumulative[k] > ideal[i]) {
                        k--;
                    }
                } else {
                    k = i+1;
                    while(cumulative[k] < ideal[i]) {
                        k++;
                    }
                }

                if(k > -1) {
                    nsplitters[i] += (splitters[k]-splitters[i])*
                        (double)abs(ideal[i]-cumulative[i])/
                        (double)abs(cumulative[k]-cumulative[i]);
                } else {
                    nsplitters[i] += (minval-splitters[i])*
                        (double)ideal[i]/(double)cumulative[i];
                }
            }
        }
        nsplitters[nbuckets-1] = splitters[nbuckets-1];

        for(i=0;i<nbuckets;i++) {
            splitters[i] = nsplitters[i];
        }
    }

    //put into buckets based on splitters
    for(i=0;i<nbuckets;i++) {
        bucket_sizes[i] = 0;
    }
    for(i=0;i<size;i++) {
        j = 0;
        while(j < nbuckets) {
            if(elmnts[i]<splitters[j]) {
                buckets[j][bucket_sizes[j]] = elmnts[i];
                bucket_sizes[j]++;
                j = nbuckets;
            }
            j++;
        }
    }

    //sort the buckets
    for(i=0;i<nbuckets;i++) {
        qsort(buckets[i],bucket_sizes[i],sizeof(long long),compare);
    }

    t2 = get_clock();
    printf("Time: %lf\n",(t2-t1));
    #if CHECK
    count = 0;
    for(i=0;i<nbuckets;i++) {
        for(j=0;j<bucket_sizes[i];j++) {
            check ^= buckets[i][j];
        }
        count += bucket_sizes[i];
    }
    printf("The bitwise xor is %llu\n",check);
    checkMax = true;
    for(i=0;i<nbuckets-1;i++) {
        if(buckets[i][bucket_sizes[i]-1] > buckets[i+1][0]) {
            checkMax = false;
        }
    }
    printf("The max of each bucket is not greater than the min of the next:    %s\n",
        checkMax ? "true" : "false");
    #endif
    #if OUTPUT
    count = 0;
    for(i=0;i<nbuckets;i++) {
        for(j=0;j<bucket_sizes[i];j++) {
            elmnts[count+j] = buckets[i][j];
        }
        count += bucket_sizes[i];
    }
    for(i=0;i<size;i++) {
        printf("%llu\n",elmnts[i]);
    }
    #endif

    free(splitters);
    free(elmnts);
    free(sample);
    free(bucket_sizes);
    free(hist);
    for(i=0;i<nbuckets;i++) {
        free(buckets[i]);
    }
    free(buckets);
    
    return 0;
}
示例#16
0
文件: main.c 项目: sli92/netcon
/*
 * Wartet zwischen 10ms und 20ms.
 *
 */
void delay_20ms(void)
{
    uint32_t start = get_clock();

    while((get_clock() - start) < 2);
}
示例#17
0
void Timer::start()
   {
   stop();
   timer_start = get_clock();
   }
示例#18
0
int main(int argc, char **argv) {

	size_t shm_size = 1024;
	(void) shm_size;
	char tmp[17];

	unsigned my_row;
	unsigned my_col;
	e_coreid_t coreid;

	coreid = e_get_coreid();
	e_coords_from_coreid(coreid, &my_row, &my_col);

	/* <BARELOG_OVERLOAD> */
	barelog_mem_space_t mem_space =
		{ .phy_base = (void *) 0x8f000000, .length = 0x01000000,
			.alignment = 1, .word_size = 4, .data = 0 };

	barelog_platform_t platform = { .name = "PARALLELLA", .mem_space =
		mem_space, };

	barelog_policy_t policy = REPLACE;

	barelog_init_logger(my_row * 4 + my_col, platform, policy, policy, my_read,
		my_write, get_clock, init_clock, start_clock);
	/* </BARELOG_OVERLOAD> */

	sync();
	barelog_start();

	uint32_t clock00 = get_clock();
	barelog_log(BARELOG_CRITICAL_LVL, "Program starts at %u.", clock00);

	uint32_t clock01 = get_clock();
	(void) clock01;

	char buff[50] = {0};
	barelog_log(BARELOG_INFO_LVL, "e_read begins.");
	barelog_flush(2);
	barelog_clean(2);
	e_read(&e_emem_config, tmp, 0, 0, (void *)(0x8f000000+BARELOG_SHARED_MEM_MAX), 17);
	barelog_log(BARELOG_INFO_LVL, "e_read ends.%u", get_clock());

	uint32_t clock1 = get_clock();
	(void) clock1;

	// Uncomment to test the fulfillment of the events buffer.
	/*for (uint8_t k = 0; k < 1; ++k) {
		for (uint8_t i = 0; i < 200;  ++i) {
			barelog_log("Test %u %u %u", get_clock(), k, i);
			barelog_flush_buffer();
			barelog_clean_buffer();
			__asm__ __volatile__ ("nop");
		}
		__asm__ __volatile__ ("nop");
	}*/

	uint32_t clock2 = get_clock();
	(void) clock2;

	// Uncomment to access various clocks data.
	/*
	barelog_log("Results %u %u %u %u", clock00, clock01, clock1, clock2);
	if (barelog_flush_buffer() != BARELOG_SUCCESS) {
		exit(EXIT_FAILURE);
	}
	barelog_clean_buffer();
	 */

	snprintf(buff, 50, "%s from core %u", tmp, (my_row*4 + my_col));

	barelog_log(BARELOG_DEBUG_LVL, "e_write begins.");
	barelog_flush(1);
	barelog_clean(1);
	e_write((void*) &e_emem_config, buff, 0, 0, (void *)(0x8f000000+BARELOG_SHARED_MEM_MAX + (my_row*4+my_col)*50), 50);

	barelog_immediate_log(BARELOG_DEBUG_LVL, "e_write ends.");
	barelog_log(BARELOG_CRITICAL_LVL, "Program ends at %u", get_clock());
	barelog_flush(6); // Voluntary flushing too many events to check everything went well.


	exit(EXIT_SUCCESS);
}
示例#19
0
文件: netcon.c 项目: sli92/netcon
void parse_request(void)
{
        uint8_t temp;
        char *bufptr;

        ((char *)uip_appdata)[uip_len] = '\0';

        bufptr = strtok(uip_appdata, " \r\n");

        if(device_list == NULL)
                return;

        if(strcasecmp_P(bufptr, PSTR("GET")) == 0) {
                bufptr = strtok(NULL, " \r\n");

                if(strcasecmp_P(bufptr, PSTR("VALUE")) == 0) {
                        bufptr = strtok(NULL, " \r\n");

                        if(bufptr[0] >= '0' && bufptr[0] <= '8' && (bufptr[0] - '0') < device_count) {
                                temp = bufptr[0] - '0';

                                sprintf_P(uip_appdata, PSTR("OK\r\n%s\r\n"), device_list[temp].value);
                                uip_send(uip_appdata, strlen(uip_appdata));
                                return;
                        }

                } else if(strcasecmp_P(bufptr, PSTR("UPTIME")) == 0) {
                        sprintf_P(uip_appdata, PSTR("OK\r\n%lu\r\n"), get_clock());

                        uip_send(uip_appdata, strlen(uip_appdata));
                        return;
                } else if(strcasecmp_P(bufptr, PSTR("NAME")) == 0) {
                        char buffer[32];
                        strcpy_P(buffer, hostname);
                        sprintf_P(uip_appdata, PSTR("OK\r\n%s\r\n"), buffer);
                        uip_send(uip_appdata, strlen(uip_appdata));
                        return;
                } else if(strcasecmp_P(bufptr, PSTR("PLACE")) == 0) {
                        char buffer[32];
                        strcpy_P(buffer, place);
                        sprintf_P(uip_appdata, PSTR("OK\r\n%s\r\n"), buffer);
                        uip_send(uip_appdata, strlen(uip_appdata));
                        return;
                } else if(strcasecmp_P(bufptr, PSTR("DEVICECOUNT")) == 0) {
                        sprintf_P(uip_appdata, PSTR("OK\r\n%d\r\n"), device_count);
                        uip_send(uip_appdata, strlen(uip_appdata));
                        return;
                } else if(strcasecmp_P(bufptr, PSTR("TYPE")) == 0) {
                        bufptr = strtok(NULL, " \r\n");

                        if(bufptr[0] >= '0' && bufptr[0] <= '8' && (bufptr[0] - '0') < device_count) {
                                temp = bufptr[0] - '0';
                                sprintf_P(uip_appdata, PSTR("OK\r\n%d\r\n"), device_list[temp].type);
                                uip_send(uip_appdata, strlen(uip_appdata));
                                return;
                        }

                } else if(strcasecmp_P(bufptr, PSTR("DTYPE")) == 0) {
                        bufptr = strtok(NULL, " \r\n");

                        if(bufptr[0] >= '0' && bufptr[0] <= '8' && (bufptr[0] - '0') < device_count) {
                                temp = bufptr[0] - '0';
                                sprintf_P(uip_appdata, PSTR("OK\r\n%c\r\n"), device_list[temp].dtype);
                                uip_send(uip_appdata, strlen(uip_appdata));
                                return;
                        }

                } else if(strcasecmp_P(bufptr, PSTR("MIN")) == 0) {
                        bufptr = strtok(NULL, " \r\n");

                        if(bufptr[0] >= '0' && bufptr[0] <= '8' && (bufptr[0] - '0') < device_count) {
                                temp = bufptr[0] - '0';
                                sprintf_P(uip_appdata, PSTR("OK\r\n%s\r\n"), device_list[temp].min);
                                uip_send(uip_appdata, strlen(uip_appdata));
                                return;
                        }

                } else if(strcasecmp_P(bufptr, PSTR("MAX")) == 0) {
                        bufptr = strtok(NULL, " \r\n");

                        if(bufptr[0] >= '0' && bufptr[0] <= '8' && (bufptr[0] - '0') < device_count) {
                                temp = bufptr[0] - '0';
                                sprintf_P(uip_appdata, PSTR("OK\r\n%s\r\n"), device_list[temp].max);
                                uip_send(uip_appdata, strlen(uip_appdata));
                                return;
                        }

                } else if(strcasecmp_P(bufptr, PSTR("MAC")) == 0) {
                        sprintf_P(uip_appdata, PSTR("OK\r\n%02X:%02X:%02X:%02X:%02X:%02X\r\n"), uip_ethaddr.addr[5], uip_ethaddr.addr[4],
                                                                                                uip_ethaddr.addr[3], uip_ethaddr.addr[2],
                                                                                                uip_ethaddr.addr[1], uip_ethaddr.addr[0]);
                        uip_send(uip_appdata, strlen(uip_appdata));
                        return;
                }

        } else if(strcasecmp_P(bufptr, PSTR("SET")) == 0) {

        }

        strcpy_P(uip_appdata, PSTR("ERROR\r\n"));
        uip_send(uip_appdata, 7);
}
void *listen_messages(void *x_void_ptr)
{

    int sockfd, newsockfd, clilen;
    char buffer[256];
    struct sockaddr_in serv_addr, cli_addr;
    int  n;

    /* First call to socket() function */
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0) 
    {
		fprintf( stderr, "[%d]RM _STARTING SERVER SOCKET_ ERROR opening socket\n", get_clock() );
        exit(1);
    }
    /* Initialize socket structure */
    bzero((char *) &serv_addr, sizeof(serv_addr));

    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = INADDR_ANY;
    serv_addr.sin_port = htons(global_port);	//port defined in main.h
 
    /* Now bind the host address using bind() call.*/
    if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
    {
		fprintf( stderr, "[%d]RM _STARTING SERVER SOCKET_ ERROR on binding\n", get_clock() );
         exit(1);
    }
    
    /* Now start listening for the clients, here 
     * process will go in sleep mode and will wait 
     * for the incoming connection
     */
    listen(sockfd,5);
    clilen = sizeof(cli_addr);

    int test=0;
    while (1) 
    {

    	test = doSelect(sockfd);
    	if( test < 0 )
    	{
    		fprintf( stderr, "[%d]RM[%d] BIG ERROR on accept\n", get_clock , newsockfd );
			exit(1);
    	}
    	if( test == 0 )
		{
    		sleep(1);
    		continue;
		}

        newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
	
		printf("[%d]RM[%d] Connection started port: %d \n", get_clock(), newsockfd, global_port);

        if (newsockfd < 0 || test < 0)
        {
            fprintf( stderr, "[%d]RM[%d] ERROR on accept\n", get_clock , newsockfd );
            exit(1);
        }

		/* this variable is our reference to the second thread */
		pthread_t process_thread;

		/* create a receive data struct to sent to thread. Thread frees this data */
		receive_thread_data * rd = malloc(sizeof(receive_thread_data));
		rd->sockfd = newsockfd;
		rd->ip = cli_addr.sin_addr.s_addr;
		rd->port = ntohs(cli_addr.sin_port);
			
		/* execute in separate thread */
		if(pthread_create(& process_thread, NULL, receive_message, rd)) {
			fprintf(stderr, "[%d]RM[%d] Error creating thread\n", get_clock(), newsockfd );
			exit(1);
		}

    } /* end of while */

    return NULL;

}
示例#21
0
文件: clock.c 项目: CyberjujuM/tacos
SYSCALL_HANDLER1(sys_getclock, clock_t* clock)
{
	*clock = get_clock();
}
示例#22
0
static cycle_t read_tod_clock(void)
{
	return get_clock();
}
示例#23
0
int
main(int argc, char** argv)
{
    double s[nalgs];

    int c, n, lenf, leng, len, ext, reps = 0;
    fmpz_t p, temp;
    TEMPLATE(T, poly_t) f, g, h;
    TEMPLATE(T, ctx_t) ctx;
    
    FLINT_TEST_INIT(state);
    
    fmpz_init(p);
    fmpz_set_str(p, argv[1], 10);

    fmpz_init(temp);
       
    fmpz_set_str(temp, argv[2], 10);
    ext = fmpz_get_si(temp);

    lenf = atol(argv[3]);
    leng = atol(argv[4]);
    len = atol(argv[5]);

    TEMPLATE(T, ctx_init)(ctx, p, ext, "a");

    TEMPLATE(T, poly_init)(f, ctx);
    TEMPLATE(T, poly_init)(g, ctx);
    TEMPLATE(T, poly_init)(h, ctx);

    for (c = 0; c < nalgs; c++)
    {
        s[c] = 0.0;
    }
       
    for (n = 0; n < ncases; n++)
    {
        double t[nalgs];
        int l, loops = 1;

        /*
           Construct random elements of fq
        */
        {
            TEMPLATE(T, poly_randtest_monic)(f, state, lenf, ctx);
            TEMPLATE(T, poly_randtest_monic)(g, state, leng, ctx);
        }
        
    loop:
        t[0] = 0.0;
        init_clock(0);
        prof_start();
        for (l = 0; l < loops; l++)
        {
            TEMPLATE(T, poly_mullow_classical)(h, f, g, len, ctx);
        }
        prof_stop();
        t[0] += get_clock(0);

        t[1] = 0.0;
        init_clock(0);
        prof_start();
        for (l = 0; l < loops; l++)
        {
            TEMPLATE(T, poly_mullow_KS)(h, f, g, len, ctx);
        }
        prof_stop();
        t[1] += get_clock(0);

        for (c = 0; c < nalgs; c++)
            if (t[c] * FLINT_CLOCK_SCALE_FACTOR <= cpumin)
            {
                loops *= 10;
                goto loop;
            }
        
        for (c = 0; c < nalgs; c++)
            s[c] += t[c];
        reps += loops;
    }
        
    for (c = 0; c < nalgs; c++)
    {
        flint_printf("%20f ", s[c] / (double) reps);
        fflush(stdout);
    }
    printf("\n");
        
    TEMPLATE(T, poly_clear)(h, ctx);
    TEMPLATE(T, poly_clear)(f, ctx);
    TEMPLATE(T, poly_clear)(g, ctx);
    TEMPLATE(T, ctx_clear)(ctx);
    fmpz_clear(p);
    fmpz_clear(temp);

    FLINT_TEST_CLEANUP(state);
    
    return 0;
}
示例#24
0
文件: main.c 项目: koeart/lun1k
int main(int argc, char *argv[]) {
	int x, y;

	for(x = 0; x < LED_WIDTH; x++) {
		for(y = 0; y < LED_HEIGHT; y++) {
			leds[y][x][0]=0;
			leds[y][x][1]=0;
			leds[y][x][2]=0;
			leds[y][x][3]=1;
		}
	}


	char nick[] = "hello World";

	srand(time(NULL));

	
	screen = SDL_SetVideoMode(287,606,32, SDL_SWSURFACE | SDL_DOUBLEBUF);

	IMG_Init(IMG_INIT_PNG);
	SDL_Surface *image;
	image=IMG_Load("lun1k.png");

	SDL_BlitSurface(image,0,screen,0);
	SDL_Flip(screen);

	int running = 1;
	unsigned long long int startTime = get_clock();
	while(running) {
		SDL_Event ev;
		while(SDL_PollEvent(&ev)) {
			switch(ev.type) {
				case SDL_QUIT:
					running = 0;
					break;
				case SDL_KEYUP:
					break;
				case SDL_KEYDOWN:
					switch(ev.key.keysym.sym) {
						case SDLK_ESCAPE:
							running = 0;
							break;
						case SDLK_SPACE:
							if(sdlpause == 0)
							{
								sdlpause = 1;
							}
							else{
								sdlpause = 0;
							}
							break;
						case SDLK_1:
							key_fp(1);
							break;
						case SDLK_2:
							key_fp(2);
							break;
						case SDLK_3:
							key_fp(3);
							break;
						case SDLK_4:
							key_fp(4);
							break;
						case SDLK_5:
							key_fp(5);
							break;
						case SDLK_6:
							key_fp(6);
							break;
						case SDLK_7:
							key_fp(7);
							break;
						case SDLK_8:
							key_fp(8);
							break;
						case SDLK_9:
							key_fp(9);
							break;
						case SDLK_0:
							key_fp(0);
							break;
							
						default: break;
					}
				default: break;
			}
		}

		running &= !tick_fp(nick);

		
		
		for(x = 0; x < LED_WIDTH; x++) {
			for(y = 0; y < LED_HEIGHT; y++) {

				if(leds[y][x][3] == 1)
				{

					SDL_Rect rect = { x+80, y+130, 1,1 };
					SDL_FillRect(
						screen, 
						&rect, 
						SDL_MapRGB(screen->format, leds[y][x][0],leds[y][x][1],leds[y][x][2])
					);
					leds[y][x][3] = 0;

				}

			}
		}

		startTime+=interval;
		int delay = startTime-get_clock();
//		if(delay > 0)
//			usleep(delay);
		
		SDL_Flip(screen);
	}

	SDL_Quit();
	return 0;
}
static void ccw_timeout_log(struct ccw_device *cdev)
{
	struct schib schib;
	struct subchannel *sch;
	struct io_subchannel_private *private;
	union orb *orb;
	int cc;

	sch = to_subchannel(cdev->dev.parent);
	private = to_io_private(sch);
	orb = &private->orb;
	cc = stsch(sch->schid, &schib);

	printk(KERN_WARNING "cio: ccw device timeout occurred at %llx, "
	       "device information:\n", get_clock());
	printk(KERN_WARNING "cio: orb:\n");
	print_hex_dump(KERN_WARNING, "cio:  ", DUMP_PREFIX_NONE, 16, 1,
		       orb, sizeof(*orb), 0);
	printk(KERN_WARNING "cio: ccw device bus id: %s\n", cdev->dev.bus_id);
	printk(KERN_WARNING "cio: subchannel bus id: %s\n", sch->dev.bus_id);
	printk(KERN_WARNING "cio: subchannel lpm: %02x, opm: %02x, "
	       "vpm: %02x\n", sch->lpm, sch->opm, sch->vpm);

	if (orb->tm.b) {
		printk(KERN_WARNING "cio: orb indicates transport mode\n");
		printk(KERN_WARNING "cio: last tcw:\n");
		print_hex_dump(KERN_WARNING, "cio:  ", DUMP_PREFIX_NONE, 16, 1,
			       (void *)(addr_t)orb->tm.tcw,
			       sizeof(struct tcw), 0);
	} else {
示例#26
0
int main ()
{
  get_clock();

  return 0;
}
示例#27
0
long read_ALOS_data_SS (FILE *imagefile, FILE *outfile, struct PRM *prm, long *byte_offset, 
                        int *nsub, int *burst_skip, int *num_burst) {

	char *data, *shift_data, *gap_data;
	int	header_size;		/* file header size          720 bytes */
	int	line_prefix_size; 	/* line header size           412 bytes*/
	int     record_length0;		/* data record size start  10788 bytes */
	int	totrecl;		/* total record length	   11200 bytes = line_prefix_size + record_length */
	int	record_length1;		/* data record size curr.  10788 bytes */
	int	line_suffix_size;	/* number of bytes after data 36 bytes */
	int	kswath0=0;		/* subswath at start of file */
	int	skip_swath;             /* number of subswaths to skip to get to desired subswath */
	int	skiprecl;               /* number of lines to skip to get to desired subswath */
	int	data_length;		/* bytes of data			*/
	int     n = 1, ishift, shift, shift0;
	int	k, kburst = 0, totburst = 0;
	int	j, ngap, nlines = 0, ntot;
	int	nprfchange, nburstchange;

	double 	tbias = 0.0, get_clock();
	double  ttot=0.,dt=0.,tgap=0.;		/* total time, burst interval, burst gap, fractional gap */
	settable(12345);

	if (debug) fprintf(stderr,".... reading header \n");

	/* read header information */
	read_sardata_info(imagefile, prm, &header_size, &line_prefix_size);
	assign_sardata_params(prm, line_prefix_size, &line_suffix_size, &record_length0);
	totrecl = line_prefix_size + record_length0;
	set_file_position(imagefile, byte_offset, header_size);

	/* get the sarting burst number and the PRF information for all the bursts and rewind the file */
	for (k=0;k<5;k++) totburst = totburst + n_burst[k];
	for(j = 0; j < totburst; j++) {
		if ( fread((void *) &sdr,sizeof(struct sardata_info), 1, imagefile) !=1 ) break;
		fseek(imagefile, record_length0, SEEK_CUR);
		if (swap) swap_ALOS_data_info(&sdr);
		for (k=0;k<5;k++) {
			if(sdr.n_data_pixels == n_data_burst[k]) {
				PRF[k]=sdr.PRF;
				if(j == 0) kswath0 = k;
			}
		}
	}

        /* get the time interval of a burst  and rewind the file */
	dt = 0.;
	for (k=0;k<5;k++) if(PRF[k] > 0.)  dt = dt + (double)n_burst[k]/(0.001*PRF[k]);
 	tgap = dt - (double)n_burst[*nsub]/(0.001*PRF[*nsub]);
        ngap = (int)(tgap*(0.001*PRF[*nsub])+0.5);
	prm->num_valid_az = 6*(n_burst[*nsub] + ngap);    /* use 6 bursts per aperture */
	rewind(imagefile);
	fseek(imagefile, header_size, SEEK_SET);
	if (verbose) fprintf(stderr," totburst start_busrt# burstcycle_time %d %d %f \n", totburst, kswath0, dt);

	/* set the total number of lines output based on the number of patches requested or default 1000 */
	ntot = *num_burst * (n_burst[*nsub] + ngap);
	if (verbose) fprintf(stderr," dt, tgap, n_burst, ngap ,ntot %f %f %d %d %d %d \n", dt, tgap, n_burst[*nsub], ngap, prm->num_valid_az,ntot);

	/* allocate the memory for data */
	if ((data = (char *) malloc(record_length0)) == NULL) die("couldn't allocate memory for input indata.\n","");
	if ((shift_data = (char *) malloc(record_length0)) == NULL) die("couldn't allocate memory for input indata.\n","");
	if ((gap_data = (char *) malloc(record_length0)) == NULL) die("couldn't allocate memory for input indata.\n","");

	/* seek to beginning of next burst of sub swath nsub, read the line header, reset the parameters, and set the counters */
	skip_swath = ((*nsub +5) - kswath0)%5;
	skiprecl = 0;
	for( k = kswath0; k < kswath0 + skip_swath; k++) skiprecl = skiprecl + n_burst[k%5];
	skiprecl = skiprecl + *burst_skip * totburst;
	if (verbose) fprintf(stderr, " skip_swath skiprecl %d %d \n",skip_swath, skiprecl);
	fseek(imagefile,skiprecl*totrecl, SEEK_CUR);

        /* recalculate the PRF at the new skip location */
	for(j = 0; j < totburst; j++) {
		if ( fread((void *) &sdr,sizeof(struct sardata_info), 1, imagefile) !=1 ) break;
		fseek(imagefile, record_length0, SEEK_CUR);
		if (swap) swap_ALOS_data_info(&sdr);
		for (k=0;k<5;k++) {
			if(sdr.n_data_pixels == n_data_burst[k]) {
				PRF[k]=sdr.PRF;
			}
		}
	}
        /* get the time interval of a burst at the new skip location and rewind the file */
	dt = 0.;
	for (k=0;k<5;k++) if(PRF[k] > 0.)  dt = dt + (double)n_burst[k]/(0.001*PRF[k]);
 	tgap = dt - (double)n_burst[*nsub]/(0.001*PRF[*nsub]);
        ngap = (int)(tgap*(0.001*PRF[*nsub])+0.5);
	prm->num_valid_az = 6*(n_burst[*nsub] + ngap);    /* use 6 bursts per aperture */
	if (verbose) fprintf(stderr," totburst start_busrt# burstcycle_time %d %d %f \n", totburst, kswath0, dt);

	/* rewind and seek again to start in the correct location */
	rewind(imagefile);
	fseek(imagefile, header_size, SEEK_SET);
	fseek(imagefile,skiprecl*totrecl, SEEK_CUR);
	
        /* read the line header and set the parameters for this subswath */
	fread((void *) &sdr,line_prefix_size, 1, imagefile);
	if (swap) swap_ALOS_data_info(&sdr);
        prm->clock_start =  get_clock(sdr, tbias);
        prm->SC_clock_start = ((double) sdr.sensor_acquisition_year)*1000 + prm->clock_start;
	prm->prf = sdr.PRF;
	if(prm->near_range < 0) prm->near_range = sdr.slant_range;
	fseek(imagefile, -1*line_prefix_size, SEEK_CUR);
	n = sdr.sequence_number -1;
	//m = sdr.sequence_number;
	*byte_offset = ftell(imagefile);
	if (verbose) fprintf(stderr," n skiprecl byte_offset %d %d %ld \n", n, skiprecl, *byte_offset);

	/* now start at the beginning but with the intervals known */
	if (verbose) fprintf(stderr,".... reading data (byte %ld) \n",ftell(imagefile));
	shift0 = 0;
  	//m = 0;

	/* read the rest of the file */
	while ( (fread((void *) &sdr,sizeof(struct sardata_info), 1, imagefile)) == 1 ) {
        	n++;
		if (swap) swap_ALOS_data_info(&sdr);

	/* check to make sure there is no prf-change in any of the subswaths */
		for (k=0;k<5;k++) {
			if(sdr.n_data_pixels == n_data_burst[k]) {
          		if ((sdr.PRF) != PRF[k]) {
				PRF[*nsub] = 0.;
			}
			}
		}

		/* detect a different subswath and skip intil the next subswath */
		if(sdr.n_data_pixels == n_data_burst[*nsub]) {

			kburst++;

          		if (sdr.sequence_number != n) printf(" missing line: n, seq# %d %d \n", n, sdr.sequence_number);

			/* check for changes in record_length and PRF */
          		record_length1 = sdr.record_length - line_prefix_size;
          		if (record_length0  != record_length1)  die("record_length changed",""); 

			/* if prf changes exit */
          		if ((sdr.PRF) != PRF[*nsub]) {
				fprintf(stderr," ERROR  PRF changed, oldPRF, newPRF %f %f \n",PRF[*nsub]*.001,sdr.PRF*.001);
				*byte_offset=ftell(imagefile);
				nprfchange = (*byte_offset - header_size)/totrecl;
				nburstchange = nprfchange/totburst;
				fprintf(stderr," rec# burst# %d %d \n",nprfchange,nburstchange);
                                break;
			}

			/* check shift to see if it varies from beginning or from command line value */
			check_shift(prm, &shift, &ishift, &shift0, record_length1);
		
			if ((verbose) && (n/2000.0 == n/2000)) {
				fprintf(stderr," Working on line %d prf %f record length %d slant_range %d \n"
				,sdr.sequence_number, 0.001*sdr.PRF, record_length1, sdr.slant_range);
			}

			/* read data (and trailing bytes) */
          		if ( fread ((char *) data, record_length1, (size_t) 1, imagefile) != 1 ) break;

			data_length = 2*n_data_burst[*nsub];

			/* write line header to output data  */
          		fwrite((void *) &sdr, line_prefix_size, 1, outfile);
			nlines++;

			/* check to see if this is enough data */
			if(nlines >= ntot) break;

			/* Shimada says the first 13 lines are bad.  I only saw 11 bad. shift these lines outside the window */
			if(kburst < 12) ishift = data_length;
			/* ishift and write the data */
			fill_shift_data(shift, ishift, data_length, line_suffix_size, record_length1, data, shift_data, outfile); 

			/* if kburst it equal to the length of this burst then write the appropriate number of zero lines */
			if(kburst == n_burst[*nsub]) {
				ttot = ttot + dt;
				if(verbose) fprintf(stderr," %d %d %f %f %d %f \n",*nsub+1,kburst,dt,tgap,ngap,ttot);
				kburst = 0;
			/* write the appropriate number of zero lines  */
				for(j=0;j<ngap;j++) {
          				fwrite((void *) &sdr, line_prefix_size, 1, outfile);
					nlines++;
				/* set the gap data to 15.5 */
					for (k=0;k<record_length0;k++) gap_data[k]=NULL_DATA+znew%2;
					fwrite((char *) gap_data, record_length1, 1, outfile); 
				}
			}
		}
		else {
			record_length1 = sdr.record_length - line_prefix_size;
			if ( fread ((char *) data, record_length1, (size_t) 1, imagefile) != 1 ) break;
		}
	}
      
	/* calculate end time and fix prf */
	prm->prf = 0.001*PRF[*nsub];

        prm->clock_stop =  get_clock(sdr, tbias);
        prm->SC_clock_stop = ((double) sdr.sensor_acquisition_year)*1000 + prm->clock_stop;

	/* m is non-zero only in the event of a prf change */
	prm->num_lines = nlines-1;
	prm->num_patches = (int)((1.0*prm->num_lines)/(1.0*prm->num_valid_az));
	if (prm->num_lines == 0) prm->num_lines = 1;

	if (verbose) print_params(prm); 

	free(data);
	free(shift_data);
	fclose (outfile);

	return(*byte_offset);
}
示例#28
0
文件: main.c 项目: sli92/netcon
int main(void)
{
    uint32_t lastperiodic = 0;
    uint32_t lastarp = 0;

    uint8_t i;

    sysclk_init();

    clock_init();

    /* Interrupts aktivieren. */
    IE |= (1 << _EA);

    io_init();
    emif_init();
    uart_init();
    cp2200_init();

    uip_init();
    uip_arp_init();


    memcpy(uip_ethaddr.addr, mac_addr, sizeof(uip_ethaddr.addr));

    tcp_app_init();
    udp_app_init();


    while(1 > 0) {
        uip_len = cp2200_receive(uip_buf, UIP_CONF_BUFFER_SIZE);

        if(uip_len > 0) {
            if(UIP_BUFFER->type == HTONS(UIP_ETHTYPE_IP)) {
                uip_arp_ipin();
                uip_input();

                if(uip_len > 0) {
                    uip_arp_out();
                    cp2200_transmit(uip_buf, uip_len);
                }
            } else if(UIP_BUFFER->type == HTONS(UIP_ETHTYPE_ARP)) {
                uip_arp_arpin();
                if(uip_len > 0) {
                    cp2200_transmit(uip_buf, uip_len);
                }
            }
        } else if((get_clock() - lastperiodic) > CLOCK_TICKS_PER_SECOND / 2) {
            lastperiodic = get_clock();

            for(i = 0; i < UIP_CONNS; i++) {
                uip_periodic(i);

                if(uip_len > 0) {
                    uip_arp_out();
                    cp2200_transmit(uip_buf, uip_len);
                }
            }

            for(i = 0; i < UIP_UDP_CONNS; i++) {
                uip_udp_periodic(i);

                if(uip_len > 0) {
                    uip_arp_out();
                    cp2200_transmit(uip_buf, uip_len);
                }
            }

        }

        if((get_clock() - lastarp) > CLOCK_TICKS_PER_SECOND * 10) {
            lastarp = get_clock();
            uip_arp_timer();
        }
    }

    return 0;
}
示例#29
0
/*
 * Scheduler clock - returns current time in nanosec units.
 */
unsigned long long sched_clock(void)
{
	return ((get_clock() - jiffies_timer_cc) * 125) >> 9;
}
示例#30
0
int main(int argc, char *argv[]) {
	srand(time(NULL));

	screen = SDL_SetVideoMode(LED_WIDTH * ZOOM + ZOOM / 15, LED_HEIGHT * ZOOM + ZOOM / 15,
		32, SDL_SWSURFACE | SDL_DOUBLEBUF);

	SDL_Rect rect = { 0, 0, LED_WIDTH*ZOOM+(ZOOM/15), LED_HEIGHT*ZOOM+(ZOOM/15) };
	SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 0x20,0x20,0x20));


	int running = 1;
	unsigned long long int startTime = get_clock();
	while(running) {
		SDL_Event ev;
		while(SDL_PollEvent(&ev)) {
			switch(ev.type) {
				case SDL_QUIT:
					running = 0;
					break;
				case SDL_KEYUP:
				case SDL_KEYDOWN:
					switch(ev.key.keysym.sym) {
						case SDLK_ESCAPE:
							running = 0;
							break;
						default: break;
					}
				default: break;
			}
		}

		running &= !tick_fp();

		int x, y;
		for(x = 0; x < LED_WIDTH; x++) {
			for(y = 0; y < LED_HEIGHT; y++) {

				if(leds[y][x][3] == 1)
				{

					SDL_Rect rect = { ZOOM*x+(ZOOM/15), ZOOM*(LED_HEIGHT - y - 1)+(ZOOM/15), ZOOM-(ZOOM/15), ZOOM-(ZOOM/15) };
					SDL_FillRect(
						screen, 
						&rect, 
						SDL_MapRGB(screen->format, leds[y][x][0],leds[y][x][1],leds[y][x][2])
					);
					leds[y][x][3] = 0;

				}

			}
		}

		startTime+=interval;
		int delay = startTime-get_clock();
		if(delay > 0)
			usleep(delay);
		
		SDL_Flip(screen);
	}

	SDL_Quit();
	return 0;
}