int Wo_index, e_index;
int i;
unsigned int nbit = 0;
- #ifdef TIMER
+ #ifdef PROFILE
unsigned int quant_start;
#endif
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);
for(i=0; i<LSP_SCALAR_INDEXES; i++) {
pack_natural_or_gray(bits, &nbit, lsp_indexes[i], lsp_bits(i), c2->gray);
}
- #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));
int i,j;
unsigned int nbit = 0;
float weight;
- TIMER_VAR(recover_start);
+ PROFILE_VAR(recover_start);
assert(c2 != NULL);
/* 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);
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);
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);
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 */
for(i=0; i<N; i++)
c2->Sn[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;
/* 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
{
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;
}
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 */
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 */
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 */
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 */
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 */
/* 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 */
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;
}
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.
\*---------------------------------------------------------------------------*/
#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
#include "nlp.h"
#include "dump.h"
#include "kiss_fft.h"
-#undef TIMER
+#undef PROFILE
#include "machdep.h"
#include <assert.h>
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 */
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; i<m; i++) { /* FIR filter vector */
nlp->sq[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 */
for(i=0; i<m/DEC; i++) {
fw[i].real = nlp->sq[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; i<PE_FFT_SIZE; i++)
Fw[i].real = Fw[i].real*Fw[i].real + Fw[i].imag*Fw[i].imag;
- TIMER_SAMPLE_AND_LOG(magsq, fft, " mag sq");
+ PROFILE_SAMPLE_AND_LOG(magsq, fft, " mag sq");
#ifdef DUMP
dump_sq(nlp->sq);
dump_Fw(Fw);
}
}
- TIMER_SAMPLE_AND_LOG(peakpick, magsq, " peak pick");
+ PROFILE_SAMPLE_AND_LOG(peakpick, magsq, " peak pick");
//#define POST_PROCESS_MBE
#ifdef POST_PROCESS_MBE
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 */
*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);
}
#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 */
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)) -----------*/
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<FFT_ENC/2; i++) {
Aw[i].real = 1.0/(Aw[i].real*Aw[i].real + Aw[i].imag*Aw[i].imag);
}
- TIMER_SAMPLE_AND_LOG(taw, tfft1, " Aw");
+ PROFILE_SAMPLE_AND_LOG(taw, tfft1, " Aw");
/* Determine weighting filter spectrum W(exp(jw)) ---------------*/
}
kiss_fft(fft_fwd_cfg, (kiss_fft_cpx *)x, (kiss_fft_cpx *)Ww);
- TIMER_SAMPLE_AND_LOG(tfft2, taw, " fft2");
+ PROFILE_SAMPLE_AND_LOG(tfft2, taw, " fft2");
for(i=0; i<FFT_ENC/2; i++) {
Ww[i].real = Ww[i].real*Ww[i].real + Ww[i].imag*Ww[i].imag;
}
- TIMER_SAMPLE_AND_LOG(tww, tfft2, " Ww");
+ PROFILE_SAMPLE_AND_LOG(tww, tfft2, " Ww");
/* Determined combined filter R = WA ---------------------------*/
}
- TIMER_SAMPLE_AND_LOG(tr, tww, " R");
+ PROFILE_SAMPLE_AND_LOG(tr, tww, " R");
#ifdef DUMP
if (dump)
}
}
- TIMER_SAMPLE_AND_LOG2(tr, " filt");
+ PROFILE_SAMPLE_AND_LOG2(tr, " filt");
}
float Em; /* energy in band */
float Am; /* spectral amplitude sample */
float signal, noise;
- TIMER_VAR(tstart, tfft, tpw, tpf);
+ PROFILE_VAR(tstart, tfft, tpw, tpf);
- TIMER_SAMPLE(tstart);
+ PROFILE_SAMPLE(tstart);
r = TWO_PI/(FFT_ENC);
pw[i].real = ak[i];
kiss_fft(fft_fwd_cfg, (kiss_fft_cpx *)pw, (kiss_fft_cpx *)Pw);
- TIMER_SAMPLE_AND_LOG(tfft, tstart, " fft");
+ PROFILE_SAMPLE_AND_LOG(tfft, tstart, " fft");
/* Determine power spectrum P(w) = E/(A(exp(jw))^2 ------------------------*/
for(i=0; i<FFT_ENC/2; i++)
Pw[i].real = E/(Pw[i].real*Pw[i].real + Pw[i].imag*Pw[i].imag);
- TIMER_SAMPLE_AND_LOG(tpw, tfft, " Pw");
+ PROFILE_SAMPLE_AND_LOG(tpw, tfft, " Pw");
if (pf)
lpc_post_filter(fft_fwd_cfg, Pw, ak, order, dump, beta, gamma, bass_boost);
- TIMER_SAMPLE_AND_LOG(tpf, tpw, " LPC post filter");
+ PROFILE_SAMPLE_AND_LOG(tpf, tpw, " LPC post filter");
#ifdef DUMP
if (dump)
}
*snr = 10.0*log10f(signal/noise);
- TIMER_SAMPLE_AND_LOG2(tpf, " rec");
+ PROFILE_SAMPLE_AND_LOG2(tpf, " rec");
}
/*---------------------------------------------------------------------------*\
$(DSPLIB)/Examples/arm_fft_bin_example/arm_fft_bin_data.c \
fft_test.c \
src/startup_stm32f4xx.s \
-stm32f4_timer.c \
+stm32f4_machdep.c \
gdb_stdio.c \
../src/kiss_fft.c
###################################################
-all: libstm32f4.a codec2_profile.elf fft_test.elf dac_ut.elf dac_play.elf adc_rec.elf pwm_ut.elf fdmdv_profile.elf sm1000_leds_switches_ut.elf sm1000.elf adcdac_ut.elf
+all: libstm32f4.a codec2_profile.elf fft_test.elf dac_ut.elf dac_play.elf adc_rec.elf pwm_ut.elf fdmdv_profile.elf sm1000_leds_switches_ut.elf sm1000.elf adcdac_ut.elf freedv_profile.elf
dl/$(PERIPHLIBZIP):
mkdir -p dl
CODEC2_PROFILE_SRCS=\
src/codec2_profile.c \
src/gdb_stdio.c \
-src/stm32f4_timer.c \
+src/stm32f4_machdep.c \
src/startup_stm32f4xx.s \
src/init.c \
src/system_stm32f4xx.c
CODEC2_PROFILE_SRCS += $(CODEC2_SRCS)
codec2_profile.elf: $(CODEC2_PROFILE_SRCS)
- $(CC) $(CFLAGS) -DTIMER $^ -o $@ $(LIBPATHS) $(LIBS)
+ $(CC) $(CFLAGS) -DPROFILE $^ -o $@ $(LIBPATHS) $(LIBS)
fft_test.elf: $(FFT_TEST_SRCS)
$(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS)
src/system_stm32f4xx.c \
src/startup_stm32f4xx.s \
src/init.c \
-src/stm32f4_timer.c \
+src/stm32f4_machdep.c \
POWER_UT_SRCS += $(CODEC2_SRCS)
src/system_stm32f4xx.c \
src/startup_stm32f4xx.s \
src/init.c \
-src/stm32f4_timer.c
+src/stm32f4_machdep.c
FDMDV_PROFILE_SRCS += $(CODEC2_SRCS)
fdmdv_profile.elf: $(FDMDV_PROFILE_SRCS)
- $(CC) $(CFLAGS) -DTIMER $^ -o $@ $(LIBPATHS) $(LIBS)
+ $(CC) $(CFLAGS) -DPROFILE $^ -o $@ $(LIBPATHS) $(LIBS)
SM1000_LEDS_SWITCHES_UT_SRCS=\
src/sm1000_leds_switches_ut.c \
sm1000.elf: $(SM1000_SRCS) src/stm32f4_dac.o src/stm32f4_adc.o
$(CC) $(CFLAGS) -O3 $^ -o $@ $(LIBPATHS) $(LIBS)
+FREEDV_PROFILE_SRCS=\
+src/freedv_profile.c \
+src/stm32f4_machdep.c \
+gdb_stdio.c \
+src/system_stm32f4xx.c \
+src/startup_stm32f4xx.s \
+src/init.c
+
+FREEDV_PROFILE_SRCS += $(CODEC2_SRCS)
+
+freedv_profile.elf: $(FREEDV_PROFILE_SRCS)
+ $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS)
+
clean:
rm -f *.o
rm -f *.elf
int nsam, nbit;\r
FILE *fin, *fout;\r
int frame;\r
- TIMER_VAR(enc_start, dec_start);\r
+ PROFILE_VAR(enc_start, dec_start);\r
\r
codec2 = codec2_create(mode);\r
nsam = codec2_samples_per_frame(codec2);\r
frame = 0;\r
\r
while (fread(inbuf, sizeof(short), nsam, fin) == nsam) {\r
- TIMER_SAMPLE(enc_start);\r
+ PROFILE_SAMPLE(enc_start);\r
codec2_encode(codec2, bits, inbuf);\r
- TIMER_SAMPLE_AND_LOG(dec_start, enc_start, " enc"); \r
+ PROFILE_SAMPLE_AND_LOG(dec_start, enc_start, " enc"); \r
codec2_decode(codec2, outbuf, bits);\r
- TIMER_SAMPLE_AND_LOG2(dec_start, " dec"); \r
- TIMER_SAMPLE_AND_LOG2(enc_start, " enc & dec"); \r
+ PROFILE_SAMPLE_AND_LOG2(dec_start, " dec"); \r
+ PROFILE_SAMPLE_AND_LOG2(enc_start, " enc & dec"); \r
fwrite((char*)outbuf, sizeof(short), nsam, fout);\r
printf("frame: %d\n", ++frame);\r
- machdep_timer_print_logged_samples();\r
+ machdep_profile_print_logged_samples();\r
}\r
\r
#ifdef DUMP\r
\r
int main(int argc, char *argv[]) {\r
gpio_init();\r
- machdep_timer_init ();\r
+ machdep_profile_init ();\r
\r
printf("Starting c2demo\n");\r
\r
int i, j, nin, reliable_sync_bit[2], sync_bit, bit_errors, ntest_bits, test_frame_sync;\r
short *error_pattern;\r
struct FDMDV_STATS stats;\r
- TIMER_VAR(mod_start, demod_start);\r
+ PROFILE_VAR(mod_start, demod_start);\r
\r
- machdep_timer_init ();\r
+ machdep_profile_init ();\r
fdmdv = fdmdv_create(FDMDV_NC);\r
\r
bits_per_fdmdv_frame = fdmdv_bits_per_frame(fdmdv);\r
fdmdv_get_test_bits(fdmdv, tx_bits);\r
fdmdv_get_test_bits(fdmdv, &tx_bits[bits_per_fdmdv_frame]);\r
\r
- TIMER_SAMPLE(mod_start);\r
+ PROFILE_SAMPLE(mod_start);\r
\r
fdmdv_mod(fdmdv, tx_fdm, tx_bits, &sync_bit);\r
assert(sync_bit == 1);\r
assert(sync_bit == 0);\r
channel_in(tx_fdm, 2*FDMDV_NOM_SAMPLES_PER_FRAME);\r
\r
- TIMER_SAMPLE_AND_LOG(demod_start, mod_start, " mod"); \r
+ PROFILE_SAMPLE_AND_LOG(demod_start, mod_start, " mod"); \r
\r
for(j=0; j<2; j++) {\r
channel_out(rx_fdm, nin);\r
fdmdv_put_test_bits(fdmdv, &test_frame_sync, error_pattern, &bit_errors, &ntest_bits, &codec_bits[bits_per_fdmdv_frame]);\r
}\r
}\r
- TIMER_SAMPLE_AND_LOG2(demod_start, " demod"); \r
- TIMER_SAMPLE_AND_LOG2(mod_start, " mod & demod"); \r
+ PROFILE_SAMPLE_AND_LOG2(demod_start, " demod"); \r
+ PROFILE_SAMPLE_AND_LOG2(mod_start, " mod & demod"); \r
\r
fdmdv_get_demod_stats(fdmdv, &stats);\r
\r
printf("frame: %d sync: %d reliable_sync_bit: %d %d SNR: %3.2f test_frame_sync: %d\n", \r
i, stats.sync, reliable_sync_bit[0], reliable_sync_bit[1], (double)stats.snr_est, \r
test_frame_sync);\r
- machdep_timer_print_logged_samples();\r
+ machdep_profile_print_logged_samples();\r
}\r
\r
fdmdv_destroy(fdmdv);\r
kiss_fft_cfg fft_fwd_cfg;\r
\r
SystemInit();\r
- machdep_timer_init();\r
+ machdep_profile_init();\r
fft_fwd_cfg = kiss_fft_alloc(fftSize, 0, NULL, NULL);\r
- kiss_fft_start = machdep_timer_sample(); \r
+ kiss_fft_start = machdep_profile_sample(); \r
kiss_fft(fft_fwd_cfg, (kiss_fft_cpx *)testInput_f32_10khz, \r
(kiss_fft_cpx *)kiss_complex_out);\r
- machdep_timer_sample_and_log(kiss_fft_start, " kiss_fft"); \r
+ machdep_profile_sample_and_log(kiss_fft_start, " kiss_fft"); \r
\r
status = ARM_MATH_SUCCESS; \r
\r
status = arm_cfft_radix2_init_f32(&S, fftSize, ifftFlag, doBitReverse); \r
\r
/* Process the data through the CFFT/CIFFT module */ \r
- fft_start = machdep_timer_sample(); \r
+ fft_start = machdep_profile_sample(); \r
arm_cfft_radix2_f32(&S, testInput_f32_10khz); \r
- machdep_timer_sample_and_log(fft_start, " fft"); \r
- machdep_timer_print_logged_samples();\r
+ machdep_profile_sample_and_log(fft_start, " fft"); \r
+ machdep_profile_print_logged_samples();\r
\r
/* Process the data through the Complex Magnitude Module for \r
calculating the magnitude at each bin */ \r
+++ /dev/null
-/*---------------------------------------------------------------------------*\
-
- FILE........: machdep.h
- AUTHOR......: David Rowe
- DATE CREATED: May 2 2013
-
- Machine dependant 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 <http://www.gnu.org/licenses/>.
-*/
-
-#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
int main(int argc, char *argv[]) {\r
SystemInit();\r
gpio_init();\r
- machdep_timer_init ();\r
+ machdep_profile_init ();\r
adc_open(4*DAC_BUF_SZ);\r
dac_open(4*DAC_BUF_SZ);\r
\r
[ ] switch debouncing?\r
[ ] light led with bit errors\r
[ ] 16 to 8 kHz rate conversion\r
+ [ ] change freedv_api interface to float[]\r
*/\r
\r
/* clear filter memories */\r
--- /dev/null
+
+/*---------------------------------------------------------------------------*\
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include <string.h>
+#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;
+}
+
+++ /dev/null
-
-/*---------------------------------------------------------------------------*\
-
- 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 <http://www.gnu.org/licenses/>.
-*/
-
-#include <string.h>
-#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;
-}
-