From: drowe67 Date: Wed, 13 Aug 2014 08:41:01 +0000 (+0000) Subject: renamed the profiling/machdep functions X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=21c9bd8de39bad7ac81ae9aa9fc4a3ca9469c19a;p=freetel-svn-tracking.git renamed the profiling/machdep functions git-svn-id: https://svn.code.sf.net/p/freetel/code@1795 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/src/codec2.c b/codec2-dev/src/codec2.c index 09dd7578..a167f763 100644 --- a/codec2-dev/src/codec2.c +++ b/codec2-dev/src/codec2.c @@ -974,7 +974,7 @@ void codec2_encode_1300(struct CODEC2 *c2, unsigned char * bits, short speech[]) int Wo_index, e_index; int i; unsigned int nbit = 0; - #ifdef TIMER + #ifdef PROFILE unsigned int quant_start; #endif @@ -1005,8 +1005,8 @@ void codec2_encode_1300(struct CODEC2 *c2, unsigned char * bits, short speech[]) Wo_index = encode_Wo(model.Wo); pack_natural_or_gray(bits, &nbit, Wo_index, WO_BITS, c2->gray); - #ifdef TIMER - quant_start = machdep_timer_sample(); + #ifdef PROFILE + quant_start = machdep_profile_sample(); #endif e = speech_to_uq_lsps(lsps, ak, c2->Sn, c2->w, LPC_ORD); e_index = encode_energy(e); @@ -1016,8 +1016,8 @@ void codec2_encode_1300(struct CODEC2 *c2, unsigned char * bits, short speech[]) for(i=0; igray); } - #ifdef TIMER - machdep_timer_sample_and_log(quant_start, " quant/packing"); + #ifdef PROFILE + machdep_profile_sample_and_log(quant_start, " quant/packing"); #endif assert(nbit == (unsigned)codec2_bits_per_frame(c2)); @@ -1046,7 +1046,7 @@ void codec2_decode_1300(struct CODEC2 *c2, short speech[], const unsigned char * int i,j; unsigned int nbit = 0; float weight; - TIMER_VAR(recover_start); + PROFILE_VAR(recover_start); assert(c2 != NULL); @@ -1092,7 +1092,7 @@ void codec2_decode_1300(struct CODEC2 *c2, short speech[], const unsigned char * /* Wo, energy, and LSPs are sampled every 40ms so we interpolate the 3 frames in between */ - TIMER_SAMPLE(recover_start); + PROFILE_SAMPLE(recover_start); for(i=0, weight=0.25; i<3; i++, weight += 0.25) { interpolate_lsp_ver2(&lsps[i][0], c2->prev_lsps_dec, &lsps[3][0], weight); interp_Wo2(&model[i], &c2->prev_model_dec, &model[3], weight); @@ -1107,7 +1107,7 @@ void codec2_decode_1300(struct CODEC2 *c2, short speech[], const unsigned char * c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma); apply_lpc_correction(&model[i]); } - TIMER_SAMPLE_AND_LOG2(recover_start, " recover"); + PROFILE_SAMPLE_AND_LOG2(recover_start, " recover"); #ifdef DUMP dump_lsp_(&lsps[3][0]); dump_ak_(&ak[3][0], LPC_ORD); @@ -1318,25 +1318,25 @@ void codec2_decode_1200(struct CODEC2 *c2, short speech[], const unsigned char * void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model, float ak[]) { int i; - TIMER_VAR(phase_start, pf_start, synth_start); + PROFILE_VAR(phase_start, pf_start, synth_start); #ifdef DUMP dump_quantised_model(model); #endif - TIMER_SAMPLE(phase_start); + PROFILE_SAMPLE(phase_start); phase_synth_zero_order(c2->fft_fwd_cfg, model, ak, &c2->ex_phase, LPC_ORD); - TIMER_SAMPLE_AND_LOG(pf_start,phase_start, " phase_synth"); + PROFILE_SAMPLE_AND_LOG(pf_start,phase_start, " phase_synth"); postfilter(model, &c2->bg_est); - TIMER_SAMPLE_AND_LOG(synth_start, pf_start, " postfilter"); + PROFILE_SAMPLE_AND_LOG(synth_start, pf_start, " postfilter"); synthesise(c2->fft_inv_cfg, c2->Sn_, model, c2->Pn, 1); - TIMER_SAMPLE_AND_LOG2(synth_start, " synth"); + PROFILE_SAMPLE_AND_LOG2(synth_start, " synth"); ear_protection(c2->Sn_, N); @@ -1369,7 +1369,7 @@ void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]) COMP Ew[FFT_ENC]; float pitch; int i; - TIMER_VAR(dft_start, nlp_start, model_start, two_stage, estamps); + PROFILE_VAR(dft_start, nlp_start, model_start, two_stage, estamps); /* Read input speech */ @@ -1378,14 +1378,14 @@ void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]) for(i=0; iSn[i+M-N] = speech[i]; - TIMER_SAMPLE(dft_start); + PROFILE_SAMPLE(dft_start); dft_speech(c2->fft_fwd_cfg, Sw, c2->Sn, c2->w); - TIMER_SAMPLE_AND_LOG(nlp_start, dft_start, " dft_speech"); + PROFILE_SAMPLE_AND_LOG(nlp_start, dft_start, " dft_speech"); /* Estimate pitch */ nlp(c2->nlp,c2->Sn,N,P_MIN,P_MAX,&pitch,Sw, c2->W, &c2->prev_Wo_enc); - TIMER_SAMPLE_AND_LOG(model_start, nlp_start, " nlp"); + PROFILE_SAMPLE_AND_LOG(model_start, nlp_start, " nlp"); model->Wo = TWO_PI/pitch; model->L = PI/model->Wo; @@ -1393,12 +1393,12 @@ void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]) /* estimate model parameters */ two_stage_pitch_refinement(model, Sw); - TIMER_SAMPLE_AND_LOG(two_stage, model_start, " two_stage"); + PROFILE_SAMPLE_AND_LOG(two_stage, model_start, " two_stage"); estimate_amplitudes(model, Sw, c2->W, 0); - TIMER_SAMPLE_AND_LOG(estamps, two_stage, " est_amps"); + PROFILE_SAMPLE_AND_LOG(estamps, two_stage, " est_amps"); est_voicing_mbe(model, Sw, c2->W, Sw_, Ew); c2->prev_Wo_enc = model->Wo; - TIMER_SAMPLE_AND_LOG2(estamps, " est_voicing"); + PROFILE_SAMPLE_AND_LOG2(estamps, " est_voicing"); #ifdef DUMP dump_model(model); #endif diff --git a/codec2-dev/src/fdmdv.c b/codec2-dev/src/fdmdv.c index 2f6bf61f..2841f74d 100644 --- a/codec2-dev/src/fdmdv.c +++ b/codec2-dev/src/fdmdv.c @@ -553,16 +553,16 @@ void fdmdv_mod(struct FDMDV *fdmdv, COMP tx_fdm[], int tx_bits[], int *sync_bit) { COMP tx_symbols[NC+1]; COMP tx_baseband[NC+1][M]; - TIMER_VAR(mod_start, tx_filter_start, fdm_upconvert_start); + PROFILE_VAR(mod_start, tx_filter_start, fdm_upconvert_start); - TIMER_SAMPLE(mod_start); + PROFILE_SAMPLE(mod_start); bits_to_dqpsk_symbols(tx_symbols, fdmdv->Nc, fdmdv->prev_tx_symbols, tx_bits, &fdmdv->tx_pilot_bit, fdmdv->old_qpsk_mapping); memcpy(fdmdv->prev_tx_symbols, tx_symbols, sizeof(COMP)*(fdmdv->Nc+1)); - TIMER_SAMPLE_AND_LOG(tx_filter_start, mod_start, " bits_to_dqpsk_symbols"); + PROFILE_SAMPLE_AND_LOG(tx_filter_start, mod_start, " bits_to_dqpsk_symbols"); tx_filter(tx_baseband, fdmdv->Nc, tx_symbols, fdmdv->tx_filter_memory); - TIMER_SAMPLE_AND_LOG(fdm_upconvert_start, tx_filter_start, " tx_filter"); + PROFILE_SAMPLE_AND_LOG(fdm_upconvert_start, tx_filter_start, " tx_filter"); fdm_upconvert(tx_fdm, fdmdv->Nc, tx_baseband, fdmdv->phase_tx, fdmdv->freq, &fdmdv->fbb_phase_tx, fdmdv->fbb_rect); - TIMER_SAMPLE_AND_LOG2(fdm_upconvert_start, " fdm_upconvert"); + PROFILE_SAMPLE_AND_LOG2(fdm_upconvert_start, " fdm_upconvert"); *sync_bit = fdmdv->tx_pilot_bit; } @@ -1001,7 +1001,7 @@ void down_convert_and_rx_filter(COMP rx_filt[NC+1][P+1], int Nc, COMP rx_fdm[], COMP rx_baseband[NFILTER+M]; COMP f_rect; - //TIMER_VAR(windback_start, downconvert_start, filter_start); + //PROFILE_VAR(windback_start, downconvert_start, filter_start); /* update memory of rx_fdm */ @@ -1025,12 +1025,12 @@ void down_convert_and_rx_filter(COMP rx_filt[NC+1][P+1], int Nc, COMP rx_fdm[], phase continuity. */ - //TIMER_SAMPLE(windback_start); + //PROFILE_SAMPLE(windback_start); windback_phase = -freq_pol[c]*NFILTER; windback_phase_rect.real = cosf(windback_phase); windback_phase_rect.imag = sinf(windback_phase); phase_rx[c] = cmult(phase_rx[c],windback_phase_rect); - //TIMER_SAMPLE_AND_LOG(downconvert_start, windback_start, " windback"); + //PROFILE_SAMPLE_AND_LOG(downconvert_start, windback_start, " windback"); /* down convert all samples in buffer */ @@ -1048,7 +1048,7 @@ void down_convert_and_rx_filter(COMP rx_filt[NC+1][P+1], int Nc, COMP rx_fdm[], phase_rx[c] = cmult(phase_rx[c], f_rect); rx_baseband[i] = cmult(rx_fdm_mem[i],cconj(phase_rx[c])); } - //TIMER_SAMPLE_AND_LOG(filter_start, downconvert_start, " downconvert"); + //PROFILE_SAMPLE_AND_LOG(filter_start, downconvert_start, " downconvert"); /* now we can filter this carrier's P symbols */ @@ -1064,7 +1064,7 @@ void down_convert_and_rx_filter(COMP rx_filt[NC+1][P+1], int Nc, COMP rx_fdm[], rx_filt[c][k].imag = fir_filter(&rx_baseband[st+i].imag, (float*)gt_alpha5_root, dec_rate); #endif } - //TIMER_SAMPLE_AND_LOG2(filter_start, " filter"); + //PROFILE_SAMPLE_AND_LOG2(filter_start, " filter"); /* normalise digital oscilators as the magnitude can drift over time */ @@ -1478,8 +1478,8 @@ void fdmdv_demod(struct FDMDV *fdmdv, int rx_bits[], COMP rx_symbols[NC+1]; float env[NT*P]; int sync_bit; - TIMER_VAR(demod_start, fdmdv_freq_shift_start, down_convert_and_rx_filter_start); - TIMER_VAR(rx_est_timing_start, qpsk_to_bits_start, snr_update_start, freq_state_start); + PROFILE_VAR(demod_start, fdmdv_freq_shift_start, down_convert_and_rx_filter_start); + PROFILE_VAR(rx_est_timing_start, qpsk_to_bits_start, snr_update_start, freq_state_start); /* shift down to complex baseband */ @@ -1487,23 +1487,23 @@ void fdmdv_demod(struct FDMDV *fdmdv, int rx_bits[], /* freq offset estimation and correction */ - TIMER_SAMPLE(demod_start); + PROFILE_SAMPLE(demod_start); foff_coarse = rx_est_freq_offset(fdmdv, rx_fdm_bb, *nin); - TIMER_SAMPLE_AND_LOG(fdmdv_freq_shift_start, demod_start, " rx_est_freq_offset"); + PROFILE_SAMPLE_AND_LOG(fdmdv_freq_shift_start, demod_start, " rx_est_freq_offset"); if (fdmdv->sync == 0) fdmdv->foff = foff_coarse; fdmdv_freq_shift(rx_fdm_fcorr, rx_fdm_bb, -fdmdv->foff, &fdmdv->foff_phase_rect, *nin); - TIMER_SAMPLE_AND_LOG(down_convert_and_rx_filter_start, fdmdv_freq_shift_start, " fdmdv_freq_shift"); + PROFILE_SAMPLE_AND_LOG(down_convert_and_rx_filter_start, fdmdv_freq_shift_start, " fdmdv_freq_shift"); /* baseband processing */ rxdec_filter(rx_fdm_filter, rx_fdm_fcorr, fdmdv->rxdec_lpf_mem, *nin); down_convert_and_rx_filter(rx_filt, fdmdv->Nc, rx_fdm_filter, fdmdv->rx_fdm_mem, fdmdv->phase_rx, fdmdv->freq, fdmdv->freq_pol, *nin, M/Q); - TIMER_SAMPLE_AND_LOG(rx_est_timing_start, down_convert_and_rx_filter_start, " down_convert_and_rx_filter"); + PROFILE_SAMPLE_AND_LOG(rx_est_timing_start, down_convert_and_rx_filter_start, " down_convert_and_rx_filter"); fdmdv->rx_timing = rx_est_timing(rx_symbols, fdmdv->Nc, rx_filt, fdmdv->rx_filter_mem_timing, env, *nin); - TIMER_SAMPLE_AND_LOG(qpsk_to_bits_start, rx_est_timing_start, " rx_est_timing"); + PROFILE_SAMPLE_AND_LOG(qpsk_to_bits_start, rx_est_timing_start, " rx_est_timing"); /* Adjust number of input samples to keep timing within bounds */ @@ -1518,14 +1518,14 @@ void fdmdv_demod(struct FDMDV *fdmdv, int rx_bits[], foff_fine = qpsk_to_bits(rx_bits, &sync_bit, fdmdv->Nc, fdmdv->phase_difference, fdmdv->prev_rx_symbols, rx_symbols, fdmdv->old_qpsk_mapping); memcpy(fdmdv->prev_rx_symbols, rx_symbols, sizeof(COMP)*(fdmdv->Nc+1)); - TIMER_SAMPLE_AND_LOG(snr_update_start, qpsk_to_bits_start, " qpsk_to_bits"); + PROFILE_SAMPLE_AND_LOG(snr_update_start, qpsk_to_bits_start, " qpsk_to_bits"); snr_update(fdmdv->sig_est, fdmdv->noise_est, fdmdv->Nc, fdmdv->phase_difference); - TIMER_SAMPLE_AND_LOG(freq_state_start, snr_update_start, " snr_update"); + PROFILE_SAMPLE_AND_LOG(freq_state_start, snr_update_start, " snr_update"); /* freq offset estimation state machine */ fdmdv->sync = freq_state(reliable_sync_bit, sync_bit, &fdmdv->fest_state, &fdmdv->timer, fdmdv->sync_mem); - TIMER_SAMPLE_AND_LOG2(freq_state_start, " freq_state"); + PROFILE_SAMPLE_AND_LOG2(freq_state_start, " freq_state"); fdmdv->foff -= TRACK_COEFF*foff_fine; } diff --git a/codec2-dev/src/machdep.h b/codec2-dev/src/machdep.h index ef2e6494..4dff9ba5 100644 --- a/codec2-dev/src/machdep.h +++ b/codec2-dev/src/machdep.h @@ -4,7 +4,8 @@ AUTHOR......: David Rowe DATE CREATED: May 2 2013 - Machine dependant functions. + Machine dependant functions, e.g. profiling that requires access to a clock + counter register. \*---------------------------------------------------------------------------*/ @@ -28,24 +29,24 @@ #ifndef __MACHDEP__ #define __MACHDEP__ -#ifdef TIMER -#define TIMER_VAR(...) unsigned int __VA_ARGS__ -#define TIMER_SAMPLE(timestamp) timestamp = machdep_timer_sample() -#define TIMER_SAMPLE_AND_LOG(timestamp, prev_timestamp, label) \ - timestamp = machdep_timer_sample_and_log(prev_timestamp, label) -#define TIMER_SAMPLE_AND_LOG2(prev_timestamp, label) \ - machdep_timer_sample_and_log(prev_timestamp, label) +#ifdef PROFILE +#define PROFILE_VAR(...) unsigned int __VA_ARGS__ +#define PROFILE_SAMPLE(timestamp) timestamp = machdep_profile_sample() +#define PROFILE_SAMPLE_AND_LOG(timestamp, prev_timestamp, label) \ + timestamp = machdep_profile_sample_and_log(prev_timestamp, label) +#define PROFILE_SAMPLE_AND_LOG2(prev_timestamp, label) \ + machdep_profile_sample_and_log(prev_timestamp, label) #else -#define TIMER_VAR(...) -#define TIMER_SAMPLE(timestamp) -#define TIMER_SAMPLE_AND_LOG(timestamp, prev_timestamp, label) -#define TIMER_SAMPLE_AND_LOG2(prev_timestamp, label) +#define PROFILE_VAR(...) +#define PROFILE_SAMPLE(timestamp) +#define PROFILE_SAMPLE_AND_LOG(timestamp, prev_timestamp, label) +#define PROFILE_SAMPLE_AND_LOG2(prev_timestamp, label) #endif -void machdep_timer_init(void); -void machdep_timer_reset(void); -unsigned int machdep_timer_sample(void); -unsigned int machdep_timer_sample_and_log(unsigned int start, char s[]); -void machdep_timer_print_logged_samples(void); +void machdep_profile_init(void); +void machdep_profile_reset(void); +unsigned int machdep_profile_sample(void); +unsigned int machdep_profile_sample_and_log(unsigned int start, char s[]); +void machdep_profile_print_logged_samples(void); #endif diff --git a/codec2-dev/src/nlp.c b/codec2-dev/src/nlp.c index 7d842e53..9ed05616 100644 --- a/codec2-dev/src/nlp.c +++ b/codec2-dev/src/nlp.c @@ -29,7 +29,7 @@ #include "nlp.h" #include "dump.h" #include "kiss_fft.h" -#undef TIMER +#undef PROFILE #include "machdep.h" #include @@ -236,13 +236,13 @@ float nlp( int gmax_bin; int m, i,j; float best_f0; - TIMER_VAR(start, tnotch, filter, peakpick, window, fft, magsq, shiftmem); + PROFILE_VAR(start, tnotch, filter, peakpick, window, fft, magsq, shiftmem); assert(nlp_state != NULL); nlp = (NLP*)nlp_state; m = nlp->m; - TIMER_SAMPLE(start); + PROFILE_SAMPLE(start); /* Square, notch filter at DC, and LP filter vector */ @@ -264,7 +264,7 @@ float nlp( exactly sure why. */ } - TIMER_SAMPLE_AND_LOG(tnotch, start, " square and notch"); + PROFILE_SAMPLE_AND_LOG(tnotch, start, " square and notch"); for(i=m-n; isq[i] += nlp->mem_fir[j]*nlp_fir[j]; } - TIMER_SAMPLE_AND_LOG(filter, tnotch, " filter"); + PROFILE_SAMPLE_AND_LOG(filter, tnotch, " filter"); /* Decimate and DFT */ @@ -288,18 +288,18 @@ float nlp( for(i=0; isq[i*DEC]*nlp->w[i]; } - TIMER_SAMPLE_AND_LOG(window, filter, " window"); + PROFILE_SAMPLE_AND_LOG(window, filter, " window"); #ifdef DUMP dump_dec(Fw); #endif kiss_fft(nlp->fft_cfg, (kiss_fft_cpx *)fw, (kiss_fft_cpx *)Fw); - TIMER_SAMPLE_AND_LOG(fft, window, " fft"); + PROFILE_SAMPLE_AND_LOG(fft, window, " fft"); for(i=0; isq); dump_Fw(Fw); @@ -316,7 +316,7 @@ float nlp( } } - TIMER_SAMPLE_AND_LOG(peakpick, magsq, " peak pick"); + PROFILE_SAMPLE_AND_LOG(peakpick, magsq, " peak pick"); //#define POST_PROCESS_MBE #ifdef POST_PROCESS_MBE @@ -325,7 +325,7 @@ float nlp( best_f0 = post_process_sub_multiples(Fw, pmin, pmax, gmax, gmax_bin, prev_Wo); #endif - TIMER_SAMPLE_AND_LOG(shiftmem, peakpick, " post process"); + PROFILE_SAMPLE_AND_LOG(shiftmem, peakpick, " post process"); /* Shift samples in buffer to make room for new samples */ @@ -336,9 +336,9 @@ float nlp( *pitch = (float)SAMPLE_RATE/best_f0; - TIMER_SAMPLE_AND_LOG2(shiftmem, " shift mem"); + PROFILE_SAMPLE_AND_LOG2(shiftmem, " shift mem"); - TIMER_SAMPLE_AND_LOG2(start, " nlp int"); + PROFILE_SAMPLE_AND_LOG2(start, " nlp int"); return(best_f0); } diff --git a/codec2-dev/src/quantise.c b/codec2-dev/src/quantise.c index b3431bd1..429a6add 100644 --- a/codec2-dev/src/quantise.c +++ b/codec2-dev/src/quantise.c @@ -37,7 +37,7 @@ #include "lpc.h" #include "lsp.h" #include "kiss_fft.h" -#undef TIMER +#undef PROFILE #include "machdep.h" #define LSP_DELTA1 0.01 /* grid spacing for LSP root searches */ @@ -796,9 +796,9 @@ void lpc_post_filter(kiss_fft_cfg fft_fwd_cfg, COMP Pw[], float ak[], float Pfw; float max_Rw, min_Rw; float coeff; - TIMER_VAR(tstart, tfft1, taw, tfft2, tww, tr); + PROFILE_VAR(tstart, tfft1, taw, tfft2, tww, tr); - TIMER_SAMPLE(tstart); + PROFILE_SAMPLE(tstart); /* Determine LPC inverse filter spectrum 1/A(exp(jw)) -----------*/ @@ -816,13 +816,13 @@ void lpc_post_filter(kiss_fft_cfg fft_fwd_cfg, COMP Pw[], float ak[], x[i].real = ak[i]; kiss_fft(fft_fwd_cfg, (kiss_fft_cpx *)x, (kiss_fft_cpx *)Aw); - TIMER_SAMPLE_AND_LOG(tfft1, tstart, " fft1"); + PROFILE_SAMPLE_AND_LOG(tfft1, tstart, " fft1"); for(i=0; i. -*/ - -#ifndef __MACHDEP__ -#define __MACHDEP__ - -#ifdef TIMER -#define TIMER_VAR(...) unsigned int __VA_ARGS__ -#define TIMER_SAMPLE(timestamp) timestamp = machdep_timer_sample() -#define TIMER_SAMPLE_AND_LOG(timestamp, prev_timestamp, label) \ - timestamp = machdep_timer_sample_and_log(prev_timestamp, label) -#define TIMER_SAMPLE_AND_LOG2(prev_timestamp, label) \ - machdep_timer_sample_and_log(prev_timestamp, label) -#else -#define TIMER_VAR(...) -#define TIMER_SAMPLE(timestamp) -#define TIMER_SAMPLE_AND_LOG(timestamp, prev_timestamp, label) -#define TIMER_SAMPLE_AND_LOG2(prev_timestamp, label) -#endif - -void machdep_timer_init(void); -void machdep_timer_reset(void); -unsigned int machdep_timer_sample(void); -unsigned int machdep_timer_sample_and_log(unsigned int start, char s[]); -void machdep_timer_print_logged_samples(void); - -#endif diff --git a/codec2-dev/stm32/src/power_ut.c b/codec2-dev/stm32/src/power_ut.c index bc701d54..267d5f99 100644 --- a/codec2-dev/stm32/src/power_ut.c +++ b/codec2-dev/stm32/src/power_ut.c @@ -120,7 +120,7 @@ void gpio_init() { int main(int argc, char *argv[]) { SystemInit(); gpio_init(); - machdep_timer_init (); + machdep_profile_init (); adc_open(4*DAC_BUF_SZ); dac_open(4*DAC_BUF_SZ); diff --git a/codec2-dev/stm32/src/sm1000_main.c b/codec2-dev/stm32/src/sm1000_main.c index 138d84ff..9b6cbbdd 100644 --- a/codec2-dev/stm32/src/sm1000_main.c +++ b/codec2-dev/stm32/src/sm1000_main.c @@ -67,6 +67,7 @@ int main(void) { [ ] switch debouncing? [ ] light led with bit errors [ ] 16 to 8 kHz rate conversion + [ ] change freedv_api interface to float[] */ /* clear filter memories */ diff --git a/codec2-dev/stm32/src/stm32f4_machdep.c b/codec2-dev/stm32/src/stm32f4_machdep.c new file mode 100644 index 00000000..5dd39c4c --- /dev/null +++ b/codec2-dev/stm32/src/stm32f4_machdep.c @@ -0,0 +1,86 @@ + +/*---------------------------------------------------------------------------*\ + + FILE........: stm32f4_machdep.c + AUTHOR......: David Rowe + DATE CREATED: May 2 2013 + + STM32F4 implementation of the machine dependant timer functions, + e.g. profiling using a clock cycle counter.. + +\*---------------------------------------------------------------------------*/ + +/* + Copyright (C) 2013 David Rowe + + All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 2.1, as + published by the Free Software Foundation. This program is + distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, see . +*/ + +#include +#include "machdep.h" +#include "gdb_stdio.h" + +volatile unsigned int *DWT_CYCCNT = (volatile unsigned int *)0xE0001004; +volatile unsigned int *DWT_CONTROL = (volatile unsigned int *)0xE0001000; +volatile unsigned int *SCB_DEMCR = (volatile unsigned int *)0xE000EDFC; + +#define CORE_CLOCK 168E6 +#define BUF_SZ 4096 + +static char buf[BUF_SZ]; + +void machdep_profile_init(void) +{ + static int enabled = 0; + + if (!enabled) { + *SCB_DEMCR = *SCB_DEMCR | 0x01000000; + *DWT_CYCCNT = 0; // reset the counter + *DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter + + enabled = 1; + } + *buf = 0; +} + +void machdep_profile_reset(void) +{ + *DWT_CYCCNT = 0; // reset the counter +} + +unsigned int machdep_profile_sample(void) { + return *DWT_CYCCNT; +} + +/* log to a buffer, we only call printf after timing finished as it is slow */ + +unsigned int machdep_profile_sample_and_log(unsigned int start, char s[]) +{ + char tmp[80]; + float msec; + + unsigned int dwt = *DWT_CYCCNT - start; + msec = 1000.0*(float)dwt/CORE_CLOCK; + sprintf(tmp, "%s %5.2f msecs\n",s,(double)msec); + if ((strlen(buf) + strlen(tmp)) < BUF_SZ) + strcat(buf, tmp); + return *DWT_CYCCNT; +} + +void machdep_profile_print_logged_samples(void) +{ + gdb_stdio_printf("%s", buf); + *buf = 0; +} + diff --git a/codec2-dev/stm32/src/stm32f4_timer.c b/codec2-dev/stm32/src/stm32f4_timer.c deleted file mode 100644 index a2dc1461..00000000 --- a/codec2-dev/stm32/src/stm32f4_timer.c +++ /dev/null @@ -1,85 +0,0 @@ - -/*---------------------------------------------------------------------------*\ - - FILE........: stm32f4_timer.c - AUTHOR......: David Rowe - DATE CREATED: May 2 2013 - - STM32F4 implementation of the machine dependant timer functions. - -\*---------------------------------------------------------------------------*/ - -/* - Copyright (C) 2013 David Rowe - - All rights reserved. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1, as - published by the Free Software Foundation. This program is - distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, see . -*/ - -#include -#include "machdep.h" -#include "gdb_stdio.h" - -volatile unsigned int *DWT_CYCCNT = (volatile unsigned int *)0xE0001004; -volatile unsigned int *DWT_CONTROL = (volatile unsigned int *)0xE0001000; -volatile unsigned int *SCB_DEMCR = (volatile unsigned int *)0xE000EDFC; - -#define CORE_CLOCK 168E6 -#define BUF_SZ 4096 - -static char buf[BUF_SZ]; - -void machdep_timer_init(void) -{ - static int enabled = 0; - - if (!enabled) { - *SCB_DEMCR = *SCB_DEMCR | 0x01000000; - *DWT_CYCCNT = 0; // reset the counter - *DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter - - enabled = 1; - } - *buf = 0; -} - -void machdep_timer_reset(void) -{ - *DWT_CYCCNT = 0; // reset the counter -} - -unsigned int machdep_timer_sample(void) { - return *DWT_CYCCNT; -} - -/* log to a buffer, we only call printf after timing finished as it is slow */ - -unsigned int machdep_timer_sample_and_log(unsigned int start, char s[]) -{ - char tmp[80]; - float msec; - - unsigned int dwt = *DWT_CYCCNT - start; - msec = 1000.0*(float)dwt/CORE_CLOCK; - sprintf(tmp, "%s %5.2f msecs\n",s,(double)msec); - if ((strlen(buf) + strlen(tmp)) < BUF_SZ) - strcat(buf, tmp); - return *DWT_CYCCNT; -} - -void machdep_timer_print_logged_samples(void) -{ - gdb_stdio_printf("%s", buf); - *buf = 0; -} -