/*----------------------------------------------------------------------------------*/ int rp_osc_worker_exit(void) { int ret_val = 0; /* Change worker state to quite state */ rp_osc_worker_change_state(rp_osc_quit_state); if(rp_osc_thread_handler) { ret_val = pthread_join(*rp_osc_thread_handler, NULL); /* Free thread memory space */ free(rp_osc_thread_handler); rp_osc_thread_handler = NULL; } if(ret_val != 0) { fprintf(stderr, "pthread_join() failed: %s\n", strerror(errno)); } osc_fpga_exit(); rp_cleanup_signals(&rp_osc_signals); rp_cleanup_signals(&rp_tmp_signals); rp_clean_params(rp_osc_params); return 0; }
/** @brief Cleans up worker module. * * This function stops the working thread (sending quit state to it) and waits * until it is shutdown. After that it cleans up FPGA module and internal * structures. * After this function is called any access to worker module are forbidden. * * @retval 0 Always returns 0 */ int rp_osc_worker_exit(void) { int ret_val; rp_osc_worker_change_state(rp_osc_quit_state); ret_val = pthread_join(rp_osc_thread_handler, NULL); if(ret_val != 0) { fprintf(stderr, "pthread_join() failed: %s\n", strerror(errno)); } osc_fpga_exit(); rp_cleanup_signals(&rp_osc_signals); rp_cleanup_signals(&rp_tmp_signals); return 0; }
/*----------------------------------------------------------------------------------*/ int rp_osc_worker_init(rp_app_params_t *params, int params_len, rp_calib_params_t *calib_params) { int ret_val; rp_osc_ctrl = rp_osc_idle_state; rp_osc_params_dirty = 0; rp_osc_params_fpga_update = 0; rp_copy_params(params, (rp_app_params_t **)&rp_osc_params); rp_cleanup_signals(&rp_osc_signals); if(rp_create_signals(&rp_osc_signals) < 0) return -1; rp_cleanup_signals(&rp_tmp_signals); if(rp_create_signals(&rp_tmp_signals) < 0) { rp_cleanup_signals(&rp_osc_signals); return -1; } if(osc_fpga_init() < 0) { rp_cleanup_signals(&rp_osc_signals); rp_cleanup_signals(&rp_tmp_signals); return -1; } rp_calib_params = calib_params; osc_fpga_get_sig_ptr(&rp_fpga_cha_signal, &rp_fpga_chb_signal); rp_osc_thread_handler = (pthread_t *)malloc(sizeof(pthread_t)); if(rp_osc_thread_handler == NULL) { rp_cleanup_signals(&rp_osc_signals); rp_cleanup_signals(&rp_tmp_signals); return -1; } ret_val = pthread_create(rp_osc_thread_handler, NULL, rp_osc_worker_thread, NULL); if(ret_val != 0) { osc_fpga_exit(); rp_cleanup_signals(&rp_osc_signals); rp_cleanup_signals(&rp_tmp_signals); fprintf(stderr, "pthread_create() failed: %s\n", strerror(errno)); return -1; } return 0; }
int rp_lti_worker_clean(void) { lti_fpga_exit(); rp_cleanup_signals(&rp_lti_signals); rp_cleanup_signals(&rp_tmp_signals); rp_lti_fft_clean(); if(rp_cha_in) { free(rp_cha_in); rp_cha_in = NULL; } if(rp_chb_in) { free(rp_chb_in); rp_chb_in = NULL; } if(rp_dsp_state_a) { free(rp_dsp_state_a); rp_dsp_state_a = NULL; } if(rp_dsp_state_b) { free(rp_dsp_state_b); rp_dsp_state_b = NULL; } if(rp_dsp_par_a) { free(rp_dsp_par_a); rp_dsp_par_a = NULL; } if(rp_dsp_par_b) { free(rp_dsp_par_b); rp_dsp_par_b = NULL; } if(rp_cha_fft) { free(rp_cha_fft); rp_cha_fft = NULL; } if(rp_chb_fft) { free(rp_chb_fft); rp_chb_fft = NULL; } return 0; }
int rp_spectr_worker_clean(void) { spectr_fpga_exit(); rp_cleanup_signals(&rp_spectr_signals); rp_cleanup_signals(&rp_tmp_signals); rp_spectr_fft_clean(); if(rp_cha_in) { free(rp_cha_in); rp_cha_in = NULL; } if(rp_chb_in) { free(rp_chb_in); rp_chb_in = NULL; } if(rp_cha_resp) { free(rp_cha_resp); rp_cha_resp = NULL; } if(rp_chb_resp) { free(rp_chb_resp); rp_chb_resp = NULL; } if(rp_cha_resp_cal) { free(rp_cha_resp_cal); rp_cha_resp_cal = NULL; } if(rp_chb_resp_cal) { free(rp_chb_resp_cal); rp_chb_resp_cal = NULL; } return 0; }
/** @brief Initializes worker module * * This function starts new worker thread, initializes internal structures * (signals, state, ...) and initializes FPGA module. * * @retval -1 Failure * @retval 0 Success */ int rp_osc_worker_init(rp_calib_params_t *calib_params)//ERG { int ret_val; rp_osc_ctrl = rp_osc_idle_state; rp_osc_params_dirty = 0; rp_osc_params_fpga_update = 0; wrkr_rp_calib_params = calib_params;//ERG /* Create output signal structure */ rp_cleanup_signals(&rp_osc_signals); if(rp_create_signals(&rp_osc_signals) < 0) return -1; /* Create working signal structure */ rp_cleanup_signals(&rp_tmp_signals); if(rp_create_signals(&rp_tmp_signals) < 0) { rp_cleanup_signals(&rp_osc_signals); return -1; } /* FPGA module initialization */ if(osc_fpga_init() < 0) { rp_cleanup_signals(&rp_osc_signals); rp_cleanup_signals(&rp_tmp_signals); return -1; } /* Initializing the pointers for the FPGA input signal buffers */ osc_fpga_get_sig_ptr(&rp_fpga_cha_signal, &rp_fpga_chb_signal); /* Creating worker thread */ ret_val = pthread_create(&rp_osc_thread_handler, NULL, rp_osc_worker_thread, NULL); if(ret_val != 0) { osc_fpga_exit(); rp_cleanup_signals(&rp_osc_signals); rp_cleanup_signals(&rp_tmp_signals); fprintf(stderr, "pthread_create() failed: %s\n", strerror(errno)); return -1; } return 0; }
int rp_create_signals(float ***a_signals) { int i; float **s; s = (float **)malloc(SIGNALS_NUM * sizeof(float *)); if(s == NULL) { return -1; } for(i = 0; i < SIGNALS_NUM; i++) s[i] = NULL; for(i = 0; i < SIGNALS_NUM; i++) { s[i] = (float *)malloc(SIGNAL_LENGTH * sizeof(float)); if(s[i] == NULL) { rp_cleanup_signals(a_signals); return -1; } memset(&s[i][0], 0, SIGNAL_LENGTH * sizeof(float)); } *a_signals = s; return 0; }
int rp_create_signals(float ***a_signals) { int i; float **s; s = (float **)malloc(SIGNALS_NUM * sizeof(float *)); if(s == NULL) { return -1; } for(i = 0; i < SIGNALS_NUM; i++) s[i] = NULL; for(i = 0; i < SIGNALS_NUM; i++) { s[i] = (float *)malloc((rp_main_params[LCR_STEPS].value) * sizeof(float)); if(s[i] == NULL) { rp_cleanup_signals(a_signals); return -1; } memset(&s[i][0], 0, (rp_main_params[LCR_STEPS].value) * sizeof(float)); } *a_signals = s; return 0; }
/*----------------------------------------------------------------------------------*/ int rp_osc_worker_init(rp_app_params_t *params, int params_len, rp_calib_params_t *calib_params) { int ret_val; rp_osc_ctrl = rp_osc_idle_state; rp_osc_params_dirty = 0; rp_osc_params_fpga_update = 0; /* First copy of main params from main.c */ rp_copy_params(params, (rp_app_params_t **)&rp_osc_params); /* First cleans up the params, case mem is already allocated */ rp_cleanup_signals(&rp_osc_signals); /* Creates a double dimension vector with 3 values - s[i], where i is from 0 - 2 */ if(rp_create_signals(&rp_osc_signals) < 0) return -1; /* Same for tmp_signals */ rp_cleanup_signals(&rp_tmp_signals); if(rp_create_signals(&rp_tmp_signals) < 0) { rp_cleanup_signals(&rp_osc_signals); return -1; } /* cleans up FPGA memory buffer, if -1, we stop. */ if(osc_fpga_init() < 0) { rp_cleanup_signals(&rp_osc_signals); rp_cleanup_signals(&rp_tmp_signals); return -1; } /* Calibration parameters */ rp_calib_params = calib_params; /* Signal pointer directly to memory for channel A and B */ osc_fpga_get_sig_ptr(&rp_fpga_cha_signal, &rp_fpga_chb_signal); /* Thread creation */ rp_osc_thread_handler = (pthread_t *)malloc(sizeof(pthread_t)); if(rp_osc_thread_handler == NULL) { rp_cleanup_signals(&rp_osc_signals); rp_cleanup_signals(&rp_tmp_signals); return -1; } ret_val = pthread_create(rp_osc_thread_handler, NULL, rp_osc_worker_thread, NULL); /* If thread creation failed */ if(ret_val != 0) { osc_fpga_exit(); rp_cleanup_signals(&rp_osc_signals); rp_cleanup_signals(&rp_tmp_signals); fprintf(stderr, "pthread_create() failed: %s\n", strerror(errno)); return -1; } return 0; }
int rp_spectr_worker_init(void) { int ret_val; rp_spectr_ctrl = rp_spectr_idle_state; rp_spectr_params_dirty = 1; rp_spectr_params_fpga_update = 1; rp_cleanup_signals(&rp_spectr_signals); if(rp_create_signals(&rp_spectr_signals) < 0) return -1; rp_cleanup_signals(&rp_tmp_signals); if(rp_create_signals(&rp_tmp_signals) < 0) { rp_cleanup_signals(&rp_spectr_signals); return -1; } rp_cha_in = (double *)malloc(sizeof(double) * SPECTR_FPGA_SIG_LEN); rp_chb_in = (double *)malloc(sizeof(double) * SPECTR_FPGA_SIG_LEN); rp_cha_resp = (double *)malloc(sizeof(double) * SPECTR_OUT_SIG_LEN); rp_chb_resp = (double *)malloc(sizeof(double) * SPECTR_OUT_SIG_LEN); rp_cha_resp_cal = (double *)malloc(sizeof(double) * SPECTR_OUT_SIG_LEN); rp_chb_resp_cal = (double *)malloc(sizeof(double) * SPECTR_OUT_SIG_LEN); if(!rp_cha_resp || !rp_chb_resp || !rp_cha_resp_cal || !rp_chb_resp_cal || !rp_cha_in || !rp_chb_in) { rp_spectr_worker_clean(); return -1; } if(spectr_fpga_init() < 0) { rp_spectr_worker_clean(); return -1; } if(rp_spectr_fft_init() < 0) { rp_spectr_worker_clean(); return -1; } spectr_fpga_get_sig_ptr(&rp_fpga_cha_signal, &rp_fpga_chb_signal); rp_spectr_thread_handler = (pthread_t *)malloc(sizeof(pthread_t)); if(rp_spectr_thread_handler == NULL) { rp_cleanup_signals(&rp_spectr_signals); rp_cleanup_signals(&rp_tmp_signals); return -1; } ret_val = pthread_create(rp_spectr_thread_handler, NULL, rp_spectr_worker_thread, NULL); if(ret_val != 0) { spectr_fpga_exit(); rp_cleanup_signals(&rp_spectr_signals); rp_cleanup_signals(&rp_tmp_signals); fprintf(stderr, "pthread_create() failed: %s\n", strerror(errno)); return -1; } return 0; }
int rp_lti_worker_init(void) { int ret_val; rp_lti_ctrl = rp_lti_idle_state; rp_lti_params_dirty = 1; rp_lti_params_fpga_update = 1; rp_cleanup_signals(&rp_lti_signals); if(rp_create_signals(&rp_lti_signals) < 0) return -1; rp_cleanup_signals(&rp_tmp_signals); if(rp_create_signals(&rp_tmp_signals) < 0) { rp_cleanup_signals(&rp_lti_signals); return -1; } //Input acquisition data rp_cha_in = (double *)malloc(sizeof(double) * LTI_FPGA_SIG_LEN); rp_chb_in = (double *)malloc(sizeof(double) * LTI_FPGA_SIG_LEN); //DSP states rp_dsp_state_a = (double *)malloc(sizeof(double) * LTI_DSP_STATES); rp_dsp_state_b = (double *)malloc(sizeof(double) * LTI_DSP_STATES); //DSP parameters rp_dsp_par_a = (double *)malloc(sizeof(double) * LTI_DSP_PARAMS); rp_dsp_par_b = (double *)malloc(sizeof(double) * LTI_DSP_PARAMS); //FFT data (currently not used) rp_cha_fft = (double *)malloc(sizeof(double) * c_dsp_sig_len); rp_chb_fft = (double *)malloc(sizeof(double) * c_dsp_sig_len); if(!rp_cha_in || !rp_chb_in || !rp_dsp_state_a || !rp_dsp_state_b || !rp_dsp_par_a || !rp_dsp_par_b || !rp_cha_fft || !rp_chb_fft) { rp_lti_worker_clean(); return -1; } if(lti_fpga_init() < 0) { rp_lti_worker_clean(); return -1; } if(rp_lti_fft_init() < 0) { rp_lti_worker_clean(); return -1; } lti_fpga_get_sig_ptr(&rp_fpga_cha_signal, &rp_fpga_chb_signal); rp_lti_thread_handler = (pthread_t *)malloc(sizeof(pthread_t)); if(rp_lti_thread_handler == NULL) { rp_cleanup_signals(&rp_lti_signals); rp_cleanup_signals(&rp_tmp_signals); return -1; } ret_val = pthread_create(rp_lti_thread_handler, NULL, rp_lti_worker_thread, NULL); if(ret_val != 0) { lti_fpga_exit(); rp_cleanup_signals(&rp_lti_signals); rp_cleanup_signals(&rp_tmp_signals); fprintf(stderr, "pthread_create() failed: %s\n", strerror(errno)); return -1; } return 0; }