int main(int argc, char* argv[]) { #ifdef SW init_pipe_handler_with_log("pipelog.txt"); PTHREAD_DECL(vector_control_daemon); // declare the Daemon thread. PTHREAD_CREATE(vector_control_daemon); // start the Daemon.. #endif double *iq, *iq_prev, *id, *id_prev, *flq, *flq_prev, *fld, *fld_prev, *spd, *spd_prev, vd, vq, torque, load_torque, *time = 0; double speed_ref int i=0; int no_of_cycles = 4000 ; // 100u/25n (Ideal time necessary for conputation for FPGA/Motor_iteration_step) while(1) { for(i = 0; i< no_of_cycles; i++){ im_zep(&iq,&iq_prev,&id,&id_prev,&flq,&flq_prev,&fld,&fld_prev,&spd_prev,vd,vq,&torque,load_torque,&time) } write_float32("in_data",*id); write_float32("in_data",*iq); write_float32("in_data",speed_ref); vd = read_float32("out_data"); vq = read_float32("out_data"); } #ifdef SW close_pipe_handler(); PTHREAD_CANCEL(vector_control_daemon); #endif return(0); }
void streamProcessor() { while(1) { #ifndef SW #ifdef PIPELINE __loop_pipelining_on__(32,2,1); #endif #endif float x = read_float32("x_pipe"); float y = read_float32("y_pipe"); uint8_t op_code = read_uint8("op_pipe"); float result = 0; if(op_code == 0) result = x*y; else if(op_code == 1) result = x+y; else if(op_code == 2) result = (x*x) - (y*y); else if(op_code == 3) result = (x + y) * (x + y); else result = 0; write_float32("z_pipe",result); } }
void correlator() { uint32_t i,j,k; float bc; uint32_t bi; while(1) { float best_corr; uint32_t best_index; get_input(); write_uint8("start_slave_0",1); #ifdef USE2 write_uint8("start_slave_1",1); float bc0 = read_float32("best_correlation_0_pipe"); uint32_t bi0 = read_uint32("best_index_0_pipe"); float bc1 = read_float32("best_correlation_1_pipe"); uint32_t bi1 = read_uint32("best_index_1_pipe"); uint32_t cr = (bc0 < bc1); bc = (cr ? bc1 : bc0); bi = (cr ? bi1 : bi0); #else bc = read_float32("best_correlation_0_pipe"); bi = read_uint32("best_index_0_pipe"); #endif write_float32("best_correlation_pipe", bc); write_uint32("best_index_pipe", bi); } }
int main(int argc, char* argv[]) { float result; signal(SIGINT, Exit); signal(SIGTERM, Exit); #ifdef SW init_pipe_handler(); PTHREAD_DECL(dotProduct); PTHREAD_CREATE(dotProduct); #endif uint8_t idx; float expected_result = 0.0; for(idx = 0; idx < ORDER; idx++) { float val = drand48(); expected_result += (val*val); write_float32("in_data_pipe",val); } result = read_float32("out_data_pipe"); fprintf(stdout,"Result = %f, expected = %f.\n", result, expected_result); #ifdef SW close_pipe_handler(); PTHREAD_CANCEL(dotProduct); return(0); #endif }
void write_float32_n(const char *id, float* buf, int buf_len) { int i; for(i = 0; i < buf_len; i++) { write_float32((char*) id,buf[i]); } }
void slave_0() { while(1) { uint8_t s = read_uint8("start_slave_0"); float bc; int bi; #ifdef USE2 __correlatorBase(ref_vector_0, check_vectors_0, bc, bi, NUM_VECS_BY_2); write_float32("best_correlation_0_pipe",bc); write_uint32("best_index_0_pipe",bi); #else __correlatorBase(ref_vector, check_vectors, bc, bi, NUM_VECS); write_float32("best_correlation_0_pipe",bc); write_uint32("best_index_0_pipe",bi); #endif } }
void write_matrices() { uint32_t i,j; for(i = 0; i < ORDER; i++) { for(j = 0; j < ORDER; j++) { write_float32("in_data_pipe",a_matrix[i][j]); } } fprintf(stderr,"Sent a.\n"); for(i = 0; i < ORDER; i++) { for(j = 0; j < ORDER; j++) { write_float32("in_data_pipe",b_matrix[i][j]); } } fprintf(stderr,"Sent b.\n"); }
void slave_1() { while(1) { uint8_t s = read_uint8("start_slave_1"); float bc; int bi; __correlatorBase(ref_vector_1, check_vectors_1, bc, bi, NUM_VECS_BY_2); write_float32("best_correlation_1_pipe",bc); write_uint32("best_index_1_pipe",bi); } }
void vectorSum() { while(1) // unpipelined loop! { // read from a_pipe float a = read_float32("a_pipe"); // add 1.0 float ap1 = a + 1.0; // multiply by a float result = a*ap1; // send result.. write_float32("result_pipe",result); } }
int start(void) #endif { int i; uint32_t apl; float ong; uint64_t apl64; uint16_t apl16; uint8_t apl8; void* ptr; double ong64; for (i = 0; i < 10; ++i) { apl64 = read_uint64("apples64"); #ifdef RUN fprintf(stderr, "\n(%d.a) got a 64 bit apple: %llu..", i, apl64); #endif ong64 = (double)apl64; write_float64("oranges64", ong64); #ifdef RUN fprintf(stderr, "\nsent a (double) orange: %le.", ong64); #endif apl = read_uint32("apples32"); #ifdef RUN fprintf(stderr, "\n(%d.b) got a 32-bit apple: %d.", i, apl); #endif ong = (float)apl; write_float32("oranges32", ong); #ifdef RUN fprintf(stderr, "\nsent a (float) orange: %f.", ong); #endif apl16 = read_uint16("apples16"); #ifdef RUN fprintf(stderr, "\n(%d.c) got a 16-bit apple: %d.", i, apl16); #endif apl8 = (uint8_t)apl; write_uint8("oranges8", apl8); #ifdef RUN fprintf(stderr, "\nsent an 8-bit orange: %d.", apl8); #endif ptr = read_pointer("apples32"); #ifdef RUN fprintf(stderr, "\n(%d.d) got a pointer apple: %d.", i, (unsigned int) ptr); #endif write_pointer("oranges32", ptr); #ifdef RUN fprintf(stderr, "\nsent a pointer orange: %d.", (unsigned int) ptr); #endif } #ifdef RUN fprintf(stderr, "\n"); #endif return 0; }