From: sjlongland Date: Thu, 24 Sep 2015 08:11:29 +0000 (+0000) Subject: Remove trailing whitespace X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=a9f37770fe1bbb841dbb701282309355e5697ef9;p=freetel-svn-tracking.git Remove trailing whitespace git-svn-id: https://svn.code.sf.net/p/freetel/code@2353 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/README_fdmdv.txt b/codec2-dev/README_fdmdv.txt index 0aec27f7..eb0c0dff 100644 --- a/codec2-dev/README_fdmdv.txt +++ b/codec2-dev/README_fdmdv.txt @@ -8,7 +8,7 @@ Introduction A 1400 bit/s (nominal) Frequency Division Multiplexed Digital Voice (FDMDV) modem based on [1]. Used for digital audio over HF SSB. - + The FDMDV modem was first implemented in GNU Octave, then ported to C. Algorithm development is generally easier in Octave, but for real time work we need the C version. Automated units tests ensure the @@ -24,11 +24,11 @@ Built as part of codec2-dev, see README for build instructions. $ ./fdmdv_get_test_bits test.c2 1400 $ ./fdmdv_mod test.c2 test.raw $ play -r 8000 -s -2 test.raw - -2. Two seconds of test frame data modulated and sent out of sound device: - + +2. Two seconds of test frame data modulated and sent out of sound device: + $ ./fdmdv_get_test_bits - 2800 | ./fdmdv_mod - - | play -t raw -r 8000 -s -2 - - + 3. Send 14000 modulated bits (10 seconds) to the demod and count errors: $ ./fdmdv_get_test_bits - 14000 | ./fdmdv_mod - - | ./fdmdv_demod - - 14 demod_dump.txt | ./fdmdv_put_test_bits - @@ -125,7 +125,7 @@ fdmdv_ut.m - Unit test for fdmdv Octave code, useful while DBPSK pilot. Currently the noise generation code doesn't take the pilot power into account, so in this example the real SNR is actually 5dB. - + fdmdv_mod.m - Octave version of modulator that outputs a raw file. The modulator is driven by a test frame of bits. This can then be played over a real channel or through a @@ -134,7 +134,7 @@ fdmdv_mod.m - Octave version of modulator that outputs a raw file. sample clocks. To generate 10 seconds of modulated signal: - + octave:8> fdmdv_mod("test.raw",1400*10); fdmdv_demod.m - Demodulator program that takes a raw file as input, diff --git a/codec2-dev/asterisk/codec_codec2.c b/codec2-dev/asterisk/codec_codec2.c index d161be7e..ce043d05 100644 --- a/codec2-dev/asterisk/codec_codec2.c +++ b/codec2-dev/asterisk/codec_codec2.c @@ -51,7 +51,7 @@ static int codec2_new(struct ast_trans_pvt *pvt) tmp->codec2 = codec2_create(CODEC2_MODE_2400); if (!tmp->codec2) return -1; - + return 0; } @@ -124,7 +124,7 @@ static void codec2_destroy_stuff(struct ast_trans_pvt *pvt) } static struct ast_translator codec2tolin = { - .name = "codec2tolin", + .name = "codec2tolin", .srcfmt = AST_FORMAT_CODEC2, .dstfmt = AST_FORMAT_SLINEAR, .newpvt = codec2_new, @@ -137,7 +137,7 @@ static struct ast_translator codec2tolin = { }; static struct ast_translator lintocodec2 = { - .name = "lintocodec2", + .name = "lintocodec2", .srcfmt = AST_FORMAT_SLINEAR, .dstfmt = AST_FORMAT_CODEC2, .newpvt = codec2_new, @@ -171,11 +171,11 @@ static int load_module(void) int res; res = ast_register_translator(&codec2tolin); - if (!res) + if (!res) res=ast_register_translator(&lintocodec2); else ast_unregister_translator(&codec2tolin); - if (res) + if (res) return AST_MODULE_LOAD_FAILURE; return AST_MODULE_LOAD_SUCCESS; } diff --git a/codec2-dev/src/_kiss_fft_guts.h b/codec2-dev/src/_kiss_fft_guts.h index 64bc1d11..1c62a34c 100644 --- a/codec2-dev/src/_kiss_fft_guts.h +++ b/codec2-dev/src/_kiss_fft_guts.h @@ -20,7 +20,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include #define MAXFACTORS 32 -/* e.g. an fft of length 128 has 4 factors +/* e.g. an fft of length 128 has 4 factors as far as kissfft is concerned 4*4*4*2 */ @@ -48,7 +48,7 @@ struct kiss_fft_state{ #define SAMP_MAX 2147483647 #else # define FRACBITS 15 -# define SAMPPROD int32_t +# define SAMPPROD int32_t #define SAMP_MAX 32767 #endif @@ -152,12 +152,12 @@ struct kiss_fft_state{ #ifdef KISS_FFT_USE_ALLOCA // define this to allow use of alloca instead of malloc for temporary buffers -// Temporary buffers are used in two case: +// Temporary buffers are used in two case: // 1. FFT sizes that have "bad" factors. i.e. not 2,3 and 5 // 2. "in-place" FFTs. Notice the quotes, since kissfft does not really do an in-place transform. #include #define KISS_FFT_TMP_ALLOC(nbytes) alloca(nbytes) -#define KISS_FFT_TMP_FREE(ptr) +#define KISS_FFT_TMP_FREE(ptr) #else #define KISS_FFT_TMP_ALLOC(nbytes) KISS_FFT_MALLOC(nbytes) #define KISS_FFT_TMP_FREE(ptr) KISS_FFT_FREE(ptr) diff --git a/codec2-dev/src/ampexp.c b/codec2-dev/src/ampexp.c index 94e2184c..ccec6dce 100644 --- a/codec2-dev/src/ampexp.c +++ b/codec2-dev/src/ampexp.c @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - - FILE........: ampexp.c - AUTHOR......: David Rowe + + FILE........: ampexp.c + AUTHOR......: David Rowe DATE CREATED: 7 August 2012 - + Functions for experimenting with amplitude quantisation. - + \*---------------------------------------------------------------------------*/ /* @@ -22,7 +22,7 @@ License for more details. You should have received a copy of the GNU Lesser General Public License - along with this program; if not,see . + along with this program; if not,see . */ @@ -45,7 +45,7 @@ struct codebook { unsigned int log2m; unsigned int m; float *cb; - unsigned int offset; + unsigned int offset; }; struct AEXP { @@ -86,7 +86,7 @@ static float get_float(FILE * in, const char * name, char * * cursor, char * buf while ( (c = *s) != '\0' && !isdigit(c) && c != '-' && c != '.' ) s++; - + /* Comments start with "#" and continue to the end of the line. */ if ( c != '\0' && c != '#' ) { char * end = 0; @@ -222,7 +222,7 @@ struct AEXP *amp_experiment_create() { aexp->indexes[j][i] = 0; aexp->mag[i] = 1.0; aexp->model[i].Wo = TWO_PI*100.0/8000.0; - aexp->model[i].L = floor(PI/aexp->model[i].Wo); + aexp->model[i].L = floor(PI/aexp->model[i].Wo); for(m=1; m<=MAX_AMP; m++) aexp->model[i].A[m] = 10.0; aexp->model_uq[i] = aexp->model[i]; @@ -243,10 +243,10 @@ void amp_experiment_destroy(struct AEXP *aexp) { if (aexp->snr != 0.0) printf("snr: %4.2f dB\n", aexp->snr/aexp->snr_n); if (aexp->var != 0.0) - printf("var...: %4.3f std dev...: %4.3f (%d amplitude samples)\n", + printf("var...: %4.3f std dev...: %4.3f (%d amplitude samples)\n", aexp->var/aexp->var_n, sqrt(aexp->var/aexp->var_n), aexp->var_n); if (aexp->vq_var != 0.0) - printf("vq var: %4.3f std dev...: %4.3f (%d amplitude samples)\n", + printf("vq var: %4.3f std dev...: %4.3f (%d amplitude samples)\n", aexp->vq_var/aexp->vq_var_n, sqrt(aexp->vq_var/aexp->vq_var_n), aexp->vq_var_n); free(aexp); } @@ -262,7 +262,7 @@ void amp_experiment_destroy(struct AEXP *aexp) { Quantisation noise simulation. Assume noise on amplitudes is a uniform distribution, of +/- x dB. This means x = sqrt(3)*sigma. - Note: for uniform distribution var = = sigma * sigma = (b-a)*(b-a)/12. + Note: for uniform distribution var = = sigma * sigma = (b-a)*(b-a)/12. */ static void add_quant_noise(struct AEXP *aexp, MODEL *model, int start, int end, float sigma_dB) @@ -376,7 +376,7 @@ static void print_sparse_amp_error(struct AEXP *aexp, MODEL *model, float edB_th edB = frame_energy(model, &enormdB); //printf("%f\n", enormdB); dWo = fabs((aexp->model_uq[2].Wo - aexp->model_uq[1].Wo)/aexp->model_uq[2].Wo); - + if ((edB > edB_thresh) && (dWo < 0.1)) { for(m=0; mcb, &sparse_pe_in[vq->offset], &weights[vq->offset], vq->k, vq->m, &se); printf("\n offset %d k %d m %d vq_ind %d j: ", vq->offset, vq->k, vq->m, vq_ind); - + non_zero = 0; for(i=0, j=vq->offset; ik; i++,j++) { if (sparse_pe_in[j] != 0.0) { @@ -454,8 +454,8 @@ static int split_vq(float sparse_pe_out[], struct AEXP *aexp, struct codebook *v } -static void sparse_vq_pred_error(struct AEXP *aexp, - MODEL *model +static void sparse_vq_pred_error(struct AEXP *aexp, + MODEL *model ) { int m, index; @@ -482,7 +482,7 @@ static void sparse_vq_pred_error(struct AEXP *aexp, } /* vector quantise */ - + for(m=0; mvq_var += pow(sparse_pe_out[m] - sparse_pe_in[m], 2.0); } - + /* transform quantised amps back */ for(m=1; m<=model->L; m++) { @@ -544,7 +544,7 @@ static void sparse_vq_amp(struct AEXP *aexp, MODEL *model) frame_energy(model, &enormdB); aexp->mag[2] = enormdB; - + for(m=0; mindexes[0][2] = split_vq(sparse_pe_out, aexp, aexp->vq1, weights, sparse_pe_in); - + aexp->indexes[1][2] = split_vq(sparse_pe_out, aexp, aexp->vq2, weights, sparse_pe_in); aexp->indexes[2][2] = split_vq(sparse_pe_out, aexp, aexp->vq3, weights, sparse_pe_in); aexp->indexes[3][2] = split_vq(sparse_pe_out, aexp, aexp->vq4, weights, sparse_pe_in); @@ -590,7 +590,7 @@ static void sparse_vq_amp(struct AEXP *aexp, MODEL *model) if (sparse_pe_in[m] != 0.0) aexp->vq_var += pow(sparse_pe_out[m] - sparse_pe_in[m], 2.0); } - + /* transform quantised amps back */ for(m=1; m<=model->L; m++) { @@ -611,7 +611,7 @@ static void update_snr_calc(struct AEXP *aexp, MODEL *m1, MODEL *m2) assert(m1->L == m2->L); signal = 0.0; noise = 1E-32; - for(m=1; m<=m1->L; m++) { + for(m=1; m<=m1->L; m++) { signal += m1->A[m]*m1->A[m]; noise += pow(m1->A[m] - m2->A[m], 2.0); //printf("%f %f\n", before[m], model->phi[m]); @@ -650,7 +650,7 @@ int gain_shape_vq_amp(float cb[], float vec[], float weights[], int d, int e, fl } } gain = (sumAm - sumCb)/m; - + /* compute error */ metric = error = 0.0; @@ -682,7 +682,7 @@ static void gain_shape_split_vq(float sparse_pe_out[], struct AEXP *aexp, struct vq_ind = gain_shape_vq_amp(vq->cb, &sparse_pe_in[vq->offset], &weights[vq->offset], vq->k, vq->m, &se, best_gain); //printf("\n offset %d k %d m %d vq_ind %d gain: %4.2f j: ", vq->offset, vq->k, vq->m, vq_ind, *best_gain); - + non_zero = 0; for(i=0, j=vq->offset; ik; i++,j++) { if (sparse_pe_in[j] != 0.0) { @@ -718,7 +718,7 @@ static void gain_shape_sparse_vq_amp(struct AEXP *aexp, MODEL *model) } /* vector quantise */ - + for(m=0; mvq_var += pow(sparse_pe_out[m] - sparse_pe_in[m], 2.0); } - + /* transform quantised amps back */ for(m=1; m<=model->L; m++) { @@ -749,7 +749,7 @@ static void interp_split_vq(float sparse_pe_out[], struct AEXP *aexp, struct cod { int i, j; float amp_dB; - + for(i=0, j=vq->offset; ik; i++,j++) { if (sparse_pe_in[j] != 0.0) { amp_dB = 0.5*(aexp->mag[0] + vq->cb[vq->k * aexp->indexes[ind][0] + i]); @@ -767,7 +767,7 @@ static void vq_interp(struct AEXP *aexp, MODEL *model, int on) //struct codebook *vq = aexp->vq1; float sparse_pe_in[MAX_AMP]; float sparse_pe_out[MAX_AMP]; - + /* replace odd frames with interp */ /* once we get an even input frame we can interpolate and output odd */ /* using VQ to interpolate. This assumes some correlation in @@ -802,7 +802,7 @@ static void vq_interp(struct AEXP *aexp, MODEL *model, int on) //sparse_pe_out[m] = sparse_pe_in[m]; sparse_pe_out[m] = 0; } - + interp_split_vq(sparse_pe_out, aexp, aexp->vq1, sparse_pe_in, 0); interp_split_vq(sparse_pe_out, aexp, aexp->vq2, sparse_pe_in, 1); interp_split_vq(sparse_pe_out, aexp, aexp->vq3, sparse_pe_in, 2); @@ -817,9 +817,9 @@ static void vq_interp(struct AEXP *aexp, MODEL *model, int on) model->A[m] = pow(10.0, amp_dB/20.0); //printf(" %4.2f\n", 10.0*log10(model->A[m])); } - + #ifdef INITIAL_VER - + for(m=1; m<=model->L; m++) { index = MAX_AMP*m*model->Wo/PI; assert(index < MAX_AMP); @@ -833,7 +833,7 @@ static void vq_interp(struct AEXP *aexp, MODEL *model, int on) printf(" %4.2f\n", 10.0*log10(model->A[m])); } } - + #endif } else @@ -867,7 +867,7 @@ void smooth_samples(struct AEXP *aexp, MODEL *model, int mode) float enormdB; frame_energy(model, &enormdB); - + for(m=0; mL; m++) { index = MAX_AMP*m*model->Wo/PI; assert(index < MAX_AMP); @@ -945,7 +945,7 @@ void smooth_samples(struct AEXP *aexp, MODEL *model, int mode) //printf("%d %4.2f %4.2f\n", m, 10.0*log10(model->A[m]), amp_dB); model->A[m] = pow(10.0, amp_dB/20.0); } - + } #define MAX_BINS 40 @@ -987,7 +987,7 @@ void smooth_amp(struct AEXP *aexp, MODEL *model) { av[b] += model->A[m]*model->A[m]; nav[b]++; } - + } /* use averages to est amps */ @@ -1007,9 +1007,9 @@ void smooth_amp(struct AEXP *aexp, MODEL *model) { printf("L %d m %d f %4.f b %d\n", model->L, m, f, b); - printf(" %d: %4.3f -> ", m, 20*log10(model->A[m])); + printf(" %d: %4.3f -> ", m, 20*log10(model->A[m])); model->A[m] = sqrt(av[b]/nav[b]); - printf("%4.3f\n", 20*log10(model->A[m])); + printf("%4.3f\n", 20*log10(model->A[m])); } } printf("\n"); @@ -1025,7 +1025,7 @@ void smooth_amp(struct AEXP *aexp, MODEL *model) { void amp_experiment(struct AEXP *aexp, MODEL *model, char *arg) { int m,i; - + memcpy(&aexp->model_uq[2], model, sizeof(MODEL)); if (strcmp(arg, "qn") == 0) { @@ -1035,7 +1035,7 @@ void amp_experiment(struct AEXP *aexp, MODEL *model, char *arg) { /* print training samples that can be > train.txt for training VQ */ - if (strcmp(arg, "train") == 0) + if (strcmp(arg, "train") == 0) print_sparse_amp_error(aexp, model, 00.0); /* VQ of amplitudes, no interpolation (ie 10ms rate) */ @@ -1085,7 +1085,7 @@ void amp_experiment(struct AEXP *aexp, MODEL *model, char *arg) { /* update states */ for(m=1; m<=model->L; m++) - aexp->A_prev[m] = model->A[m]; + aexp->A_prev[m] = model->A[m]; aexp->frames++; for(i=0; i<3; i++) aexp->model_uq[i] = aexp->model_uq[i+1]; diff --git a/codec2-dev/src/ampexp.h b/codec2-dev/src/ampexp.h index 313abb15..8954ea28 100644 --- a/codec2-dev/src/ampexp.h +++ b/codec2-dev/src/ampexp.h @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - - FILE........: ampexp.h - AUTHOR......: David Rowe + + FILE........: ampexp.h + AUTHOR......: David Rowe DATE CREATED: & August 2012 - + Functions for experimenting with amplitude quantisation. - + \*---------------------------------------------------------------------------*/ /* @@ -22,7 +22,7 @@ License for more details. You should have received a copy of the GNU Lesser General Public License - along with this program; if not,see . + along with this program; if not,see . */ #ifndef __AMPEX__ diff --git a/codec2-dev/src/c2dec.c b/codec2-dev/src/c2dec.c index a6d9348c..1e261ac6 100644 --- a/codec2-dev/src/c2dec.c +++ b/codec2-dev/src/c2dec.c @@ -74,10 +74,10 @@ int main(int argc, char *argv[]) { NULL, no_argument, NULL, 0 } }; int num_opts=sizeof(long_options)/sizeof(struct option); - + if (argc < 4) print_help(long_options, num_opts, argv); - + if (strcmp(argv[1],"3200") == 0) mode = CODEC2_MODE_3200; else if (strcmp(argv[1],"2400") == 0) @@ -133,7 +133,7 @@ int main(int argc, char *argv[]) while(1) { int option_index = 0; - int opt = getopt_long(argc, argv, opt_string, + int opt = getopt_long(argc, argv, opt_string, long_options, &option_index); if (opt == -1) break; @@ -153,11 +153,11 @@ int main(int argc, char *argv[]) optarg, strerror(errno)); exit(1); } - - } + + } #ifdef DUMP else if(strcmp(long_options[option_index].name, "dump") == 0) { - if (dump) + if (dump) dump_on(optarg); } #endif @@ -175,18 +175,18 @@ int main(int argc, char *argv[]) assert(nend_bit <= nbit); codec2_set_natural_or_gray(codec2, !natural); //printf("%d %d\n", nstart_bit, nend_bit); - + //fprintf(stderr, "softdec: %d natural: %d\n", softdec, natural); if (softdec) ret = (fread(softdec_bits, sizeof(float), nbit, fin) == (size_t)nbit); else ret = (fread(bits, sizeof(char), nbyte, fin) == (size_t)nbyte); - + while(ret) { frames++; // apply bit errors, MSB of byte 0 is bit 0 in frame, only works in packed mode - + if ((error_mode == UNIFORM) || (error_mode == UNIFORM_RANGE)) { assert(softdec == 0); for(i=nstart_bit; imode = mode; for(i=0; ibpf_buf != NULL); for(i=0; ibpf_buf[i] = 0.0; - + c2->softdec = NULL; return c2; } /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_destroy - AUTHOR......: David Rowe - DATE CREATED: 21/8/2010 + + FUNCTION....: codec2_destroy + AUTHOR......: David Rowe + DATE CREATED: 21/8/2010 Destroy an instance of the codec. @@ -189,9 +189,9 @@ void codec2_destroy(struct CODEC2 *c2) } /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_bits_per_frame - AUTHOR......: David Rowe + + FUNCTION....: codec2_bits_per_frame + AUTHOR......: David Rowe DATE CREATED: Nov 14 2011 Returns the number of bits per frame. @@ -221,9 +221,9 @@ int codec2_bits_per_frame(struct CODEC2 *c2) { /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_samples_per_frame - AUTHOR......: David Rowe + + FUNCTION....: codec2_samples_per_frame + AUTHOR......: David Rowe DATE CREATED: Nov 14 2011 Returns the number of speech samples per frame. @@ -255,11 +255,11 @@ void codec2_encode(struct CODEC2 *c2, unsigned char *bits, short speech[]) { assert(c2 != NULL); assert( - (c2->mode == CODEC2_MODE_3200) || - (c2->mode == CODEC2_MODE_2400) || - (c2->mode == CODEC2_MODE_1600) || - (c2->mode == CODEC2_MODE_1400) || - (c2->mode == CODEC2_MODE_1300) || + (c2->mode == CODEC2_MODE_3200) || + (c2->mode == CODEC2_MODE_2400) || + (c2->mode == CODEC2_MODE_1600) || + (c2->mode == CODEC2_MODE_1400) || + (c2->mode == CODEC2_MODE_1300) || (c2->mode == CODEC2_MODE_1200) || (c2->mode == CODEC2_MODE_700) || (c2->mode == CODEC2_MODE_700B) @@ -294,11 +294,11 @@ void codec2_decode_ber(struct CODEC2 *c2, short speech[], const unsigned char *b { assert(c2 != NULL); assert( - (c2->mode == CODEC2_MODE_3200) || - (c2->mode == CODEC2_MODE_2400) || - (c2->mode == CODEC2_MODE_1600) || - (c2->mode == CODEC2_MODE_1400) || - (c2->mode == CODEC2_MODE_1300) || + (c2->mode == CODEC2_MODE_3200) || + (c2->mode == CODEC2_MODE_2400) || + (c2->mode == CODEC2_MODE_1600) || + (c2->mode == CODEC2_MODE_1400) || + (c2->mode == CODEC2_MODE_1300) || (c2->mode == CODEC2_MODE_1200) || (c2->mode == CODEC2_MODE_700) || (c2->mode == CODEC2_MODE_700B) @@ -326,12 +326,12 @@ void codec2_decode_ber(struct CODEC2 *c2, short speech[], const unsigned char *b /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_encode_3200 - AUTHOR......: David Rowe + + FUNCTION....: codec2_encode_3200 + AUTHOR......: David Rowe DATE CREATED: 13 Sep 2012 - Encodes 160 speech samples (20ms of speech) into 64 bits. + Encodes 160 speech samples (20ms of speech) into 64 bits. The codec2 algorithm actually operates internally on 10ms (80 sample) frames, so we run the encoding algorithm twice. On the @@ -348,7 +348,7 @@ void codec2_decode_ber(struct CODEC2 *c2, short speech[], const unsigned char *b Energy 5 Voicing (10ms update) 2 TOTAL 64 - + \*---------------------------------------------------------------------------*/ void codec2_encode_3200(struct CODEC2 *c2, unsigned char * bits, short speech[]) @@ -377,7 +377,7 @@ void codec2_encode_3200(struct CODEC2 *c2, unsigned char * bits, short speech[]) pack(bits, &nbit, model.voiced, 1); Wo_index = encode_Wo(model.Wo, WO_BITS); pack(bits, &nbit, Wo_index, WO_BITS); - + e = speech_to_uq_lsps(lsps, ak, c2->Sn, c2->w, LPC_ORD); e_index = encode_energy(e, E_BITS); pack(bits, &nbit, e_index, E_BITS); @@ -391,9 +391,9 @@ void codec2_encode_3200(struct CODEC2 *c2, unsigned char * bits, short speech[]) /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_decode_3200 - AUTHOR......: David Rowe + + FUNCTION....: codec2_decode_3200 + AUTHOR......: David Rowe DATE CREATED: 13 Sep 2012 Decodes a frame of 64 bits into 160 samples (20ms) of speech. @@ -414,7 +414,7 @@ void codec2_decode_3200(struct CODEC2 *c2, short speech[], const unsigned char * COMP Aw[FFT_ENC]; assert(c2 != NULL); - + /* only need to zero these out due to (unused) snr calculation */ for(i=0; i<2; i++) @@ -440,7 +440,7 @@ void codec2_decode_3200(struct CODEC2 *c2, short speech[], const unsigned char * lspd_indexes[i] = unpack(bits, &nbit, lspd_bits(i)); } decode_lspds_scalar(&lsps[1][0], lspd_indexes, LPC_ORD); - + /* interpolate ------------------------------------------------*/ /* Wo and energy are sampled every 20ms, so we interpolate just 1 @@ -456,8 +456,8 @@ void codec2_decode_3200(struct CODEC2 *c2, short speech[], const unsigned char * for(i=0; i<2; i++) { lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD); - aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, - c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); + aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, + c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); } @@ -472,12 +472,12 @@ void codec2_decode_3200(struct CODEC2 *c2, short speech[], const unsigned char * /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_encode_2400 - AUTHOR......: David Rowe - DATE CREATED: 21/8/2010 - Encodes 160 speech samples (20ms of speech) into 48 bits. + FUNCTION....: codec2_encode_2400 + AUTHOR......: David Rowe + DATE CREATED: 21/8/2010 + + Encodes 160 speech samples (20ms of speech) into 48 bits. The codec2 algorithm actually operates internally on 10ms (80 sample) frames, so we run the encoding algorithm twice. On the @@ -493,7 +493,7 @@ void codec2_decode_3200(struct CODEC2 *c2, short speech[], const unsigned char * Voicing (10ms update) 2 Spare 2 TOTAL 48 - + \*---------------------------------------------------------------------------*/ void codec2_encode_2400(struct CODEC2 *c2, unsigned char * bits, short speech[]) @@ -521,7 +521,7 @@ void codec2_encode_2400(struct CODEC2 *c2, unsigned char * bits, short speech[]) analyse_one_frame(c2, &model, &speech[N]); pack(bits, &nbit, model.voiced, 1); - + e = speech_to_uq_lsps(lsps, ak, c2->Sn, c2->w, LPC_ORD); WoE_index = encode_WoE(&model, e, c2->xq_enc); pack(bits, &nbit, WoE_index, WO_E_BITS); @@ -537,10 +537,10 @@ void codec2_encode_2400(struct CODEC2 *c2, unsigned char * bits, short speech[]) /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_decode_2400 - AUTHOR......: David Rowe - DATE CREATED: 21/8/2010 + + FUNCTION....: codec2_decode_2400 + AUTHOR......: David Rowe + DATE CREATED: 21/8/2010 Decodes frames of 48 bits into 160 samples (20ms) of speech. @@ -560,7 +560,7 @@ void codec2_decode_2400(struct CODEC2 *c2, short speech[], const unsigned char * COMP Aw[FFT_ENC]; assert(c2 != NULL); - + /* only need to zero these out due to (unused) snr calculation */ for(i=0; i<2; i++) @@ -584,7 +584,7 @@ void codec2_decode_2400(struct CODEC2 *c2, short speech[], const unsigned char * decode_lsps_scalar(&lsps[1][0], lsp_indexes, LPC_ORD); check_lsp_order(&lsps[1][0], LPC_ORD); bw_expand_lsps(&lsps[1][0], LPC_ORD, 50.0, 100.0); - + /* interpolate ------------------------------------------------*/ /* Wo and energy are sampled every 20ms, so we interpolate just 1 @@ -592,15 +592,15 @@ void codec2_decode_2400(struct CODEC2 *c2, short speech[], const unsigned char * interp_Wo(&model[0], &c2->prev_model_dec, &model[1]); e[0] = interp_energy(c2->prev_e_dec, e[1]); - + /* LSPs are sampled every 20ms so we interpolate the frame in between, then recover spectral amplitudes */ interpolate_lsp_ver2(&lsps[0][0], c2->prev_lsps_dec, &lsps[1][0], 0.5, LPC_ORD); for(i=0; i<2; i++) { lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD); - aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, - c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); + aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, + c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); } @@ -615,9 +615,9 @@ void codec2_decode_2400(struct CODEC2 *c2, short speech[], const unsigned char * /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_encode_1600 - AUTHOR......: David Rowe + + FUNCTION....: codec2_encode_1600 + AUTHOR......: David Rowe DATE CREATED: Feb 28 2013 Encodes 320 speech samples (40ms of speech) into 64 bits. @@ -639,7 +639,7 @@ void codec2_decode_2400(struct CODEC2 *c2, short speech[], const unsigned char * Energy 5 5 10 Voicing (10ms update) 2 2 4 TOTAL 14 50 64 - + \*---------------------------------------------------------------------------*/ void codec2_encode_1600(struct CODEC2 *c2, unsigned char * bits, short speech[]) @@ -652,7 +652,7 @@ void codec2_encode_1600(struct CODEC2 *c2, unsigned char * bits, short speech[]) int Wo_index, e_index; int i; unsigned int nbit = 0; - + assert(c2 != NULL); memset(bits, '\0', ((codec2_bits_per_frame(c2) + 7) / 8)); @@ -661,12 +661,12 @@ void codec2_encode_1600(struct CODEC2 *c2, unsigned char * bits, short speech[]) analyse_one_frame(c2, &model, speech); pack(bits, &nbit, model.voiced, 1); - + /* frame 2: - voicing, scalar Wo & E -------------------------------*/ analyse_one_frame(c2, &model, &speech[N]); pack(bits, &nbit, model.voiced, 1); - + Wo_index = encode_Wo(model.Wo, WO_BITS); pack(bits, &nbit, Wo_index, WO_BITS); @@ -684,14 +684,14 @@ void codec2_encode_1600(struct CODEC2 *c2, unsigned char * bits, short speech[]) analyse_one_frame(c2, &model, &speech[3*N]); pack(bits, &nbit, model.voiced, 1); - + Wo_index = encode_Wo(model.Wo, WO_BITS); pack(bits, &nbit, Wo_index, WO_BITS); e = speech_to_uq_lsps(lsps, ak, c2->Sn, c2->w, LPC_ORD); e_index = encode_energy(e, E_BITS); pack(bits, &nbit, e_index, E_BITS); - + encode_lsps_scalar(lsp_indexes, lsps, LPC_ORD); for(i=0; ifft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, - c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); + c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); } @@ -799,9 +799,9 @@ void codec2_decode_1600(struct CODEC2 *c2, short speech[], const unsigned char * } /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_encode_1400 - AUTHOR......: David Rowe + + FUNCTION....: codec2_encode_1400 + AUTHOR......: David Rowe DATE CREATED: May 11 2012 Encodes 320 speech samples (40ms of speech) into 56 bits. @@ -822,7 +822,7 @@ void codec2_decode_1600(struct CODEC2 *c2, short speech[], const unsigned char * Energy+Wo 8 8 16 Voicing (10ms update) 2 2 4 TOTAL 10 46 56 - + \*---------------------------------------------------------------------------*/ void codec2_encode_1400(struct CODEC2 *c2, unsigned char * bits, short speech[]) @@ -844,7 +844,7 @@ void codec2_encode_1400(struct CODEC2 *c2, unsigned char * bits, short speech[]) analyse_one_frame(c2, &model, speech); pack(bits, &nbit, model.voiced, 1); - + /* frame 2: - voicing, joint Wo & E -------------------------------*/ analyse_one_frame(c2, &model, &speech[N]); @@ -855,7 +855,7 @@ void codec2_encode_1400(struct CODEC2 *c2, unsigned char * bits, short speech[]) WoE_index = encode_WoE(&model, e, c2->xq_enc); pack(bits, &nbit, WoE_index, WO_E_BITS); - + /* frame 3: - voicing ---------------------------------------------*/ analyse_one_frame(c2, &model, &speech[2*N]); @@ -865,11 +865,11 @@ void codec2_encode_1400(struct CODEC2 *c2, unsigned char * bits, short speech[]) analyse_one_frame(c2, &model, &speech[3*N]); pack(bits, &nbit, model.voiced, 1); - + e = speech_to_uq_lsps(lsps, ak, c2->Sn, c2->w, LPC_ORD); WoE_index = encode_WoE(&model, e, c2->xq_enc); pack(bits, &nbit, WoE_index, WO_E_BITS); - + encode_lsps_scalar(lsp_indexes, lsps, LPC_ORD); for(i=0; ixq_dec, WoE_index); @@ -927,14 +927,14 @@ void codec2_decode_1400(struct CODEC2 *c2, short speech[], const unsigned char * model[3].voiced = unpack(bits, &nbit, 1); WoE_index = unpack(bits, &nbit, WO_E_BITS); decode_WoE(&model[3], &e[3], c2->xq_dec, WoE_index); - + for(i=0; iprev_e_dec, e[1]); interp_Wo(&model[2], &model[1], &model[3]); e[2] = interp_energy(e[1], e[3]); - + /* LSPs are sampled every 40ms so we interpolate the 3 frames in between, then recover spectral amplitudes */ @@ -954,7 +954,7 @@ void codec2_decode_1400(struct CODEC2 *c2, short speech[], const unsigned char * for(i=0; i<4; i++) { lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD); aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, - c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); + c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); } @@ -969,9 +969,9 @@ void codec2_decode_1400(struct CODEC2 *c2, short speech[], const unsigned char * } /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_encode_1300 - AUTHOR......: David Rowe + + FUNCTION....: codec2_encode_1300 + AUTHOR......: David Rowe DATE CREATED: March 14 2013 Encodes 320 speech samples (40ms of speech) into 52 bits. @@ -980,7 +980,7 @@ void codec2_decode_1400(struct CODEC2 *c2, short speech[], const unsigned char * sample) frames, so we run the encoding algorithm 4 times: frame 0: voicing bit - frame 1: voicing bit, + frame 1: voicing bit, frame 2: voicing bit frame 3: voicing bit, Wo and E, scalar LSPs @@ -993,7 +993,7 @@ void codec2_decode_1400(struct CODEC2 *c2, short speech[], const unsigned char * Energy 0 5 5 Voicing (10ms update) 2 2 4 TOTAL 2 50 52 - + \*---------------------------------------------------------------------------*/ void codec2_encode_1300(struct CODEC2 *c2, unsigned char * bits, short speech[]) @@ -1018,12 +1018,12 @@ void codec2_encode_1300(struct CODEC2 *c2, unsigned char * bits, short speech[]) analyse_one_frame(c2, &model, speech); pack_natural_or_gray(bits, &nbit, model.voiced, 1, c2->gray); - + /* frame 2: - voicing ---------------------------------------------*/ analyse_one_frame(c2, &model, &speech[N]); pack_natural_or_gray(bits, &nbit, model.voiced, 1, c2->gray); - + /* frame 3: - voicing ---------------------------------------------*/ analyse_one_frame(c2, &model, &speech[2*N]); @@ -1033,7 +1033,7 @@ void codec2_encode_1300(struct CODEC2 *c2, unsigned char * bits, short speech[]) analyse_one_frame(c2, &model, &speech[3*N]); pack_natural_or_gray(bits, &nbit, model.voiced, 1, c2->gray); - + Wo_index = encode_Wo(model.Wo, WO_BITS); pack_natural_or_gray(bits, &nbit, Wo_index, WO_BITS, c2->gray); @@ -1043,13 +1043,13 @@ void codec2_encode_1300(struct CODEC2 *c2, unsigned char * bits, short speech[]) e = speech_to_uq_lsps(lsps, ak, c2->Sn, c2->w, LPC_ORD); e_index = encode_energy(e, E_BITS); pack_natural_or_gray(bits, &nbit, e_index, E_BITS, c2->gray); - + encode_lsps_scalar(lsp_indexes, lsps, LPC_ORD); for(i=0; igray); } #ifdef PROFILE - machdep_profile_sample_and_log(quant_start, " quant/packing"); + machdep_profile_sample_and_log(quant_start, " quant/packing"); #endif assert(nbit == (unsigned)codec2_bits_per_frame(c2)); @@ -1057,9 +1057,9 @@ void codec2_encode_1300(struct CODEC2 *c2, unsigned char * bits, short speech[]) /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_decode_1300 - AUTHOR......: David Rowe + + FUNCTION....: codec2_decode_1300 + AUTHOR......: David Rowe DATE CREATED: 11 May 2012 Decodes frames of 52 bits into 320 samples (40ms) of speech. @@ -1080,7 +1080,7 @@ void codec2_decode_1300(struct CODEC2 *c2, short speech[], const unsigned char * float weight; COMP Aw[FFT_ENC]; PROFILE_VAR(recover_start); - + assert(c2 != NULL); frames+= 4; /* only need to zero these out due to (unused) snr calculation */ @@ -1094,7 +1094,7 @@ void codec2_decode_1300(struct CODEC2 *c2, short speech[], const unsigned char * /* this will partially fill the model params for the 4 x 10ms frames */ - model[0].voiced = unpack_natural_or_gray(bits, &nbit, 1, c2->gray); + model[0].voiced = unpack_natural_or_gray(bits, &nbit, 1, c2->gray); model[1].voiced = unpack_natural_or_gray(bits, &nbit, 1, c2->gray); model[2].voiced = unpack_natural_or_gray(bits, &nbit, 1, c2->gray); model[3].voiced = unpack_natural_or_gray(bits, &nbit, 1, c2->gray); @@ -1105,14 +1105,14 @@ void codec2_decode_1300(struct CODEC2 *c2, short speech[], const unsigned char * e_index = unpack_natural_or_gray(bits, &nbit, E_BITS, c2->gray); e[3] = decode_energy(e_index, E_BITS); - + for(i=0; igray); } decode_lsps_scalar(&lsps[3][0], lsp_indexes, LPC_ORD); check_lsp_order(&lsps[3][0], LPC_ORD); bw_expand_lsps(&lsps[3][0], LPC_ORD, 50.0, 100.0); - + if (ber_est > 0.15) { model[0].voiced = model[1].voiced = model[2].voiced = model[3].voiced = 0; e[3] = decode_energy(10, E_BITS); @@ -1132,12 +1132,12 @@ void codec2_decode_1300(struct CODEC2 *c2, short speech[], const unsigned char * e[i] = interp_energy2(c2->prev_e_dec, e[3],weight); } - /* then recover spectral amplitudes */ + /* then recover spectral amplitudes */ for(i=0; i<4; i++) { lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD); aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, - c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); + c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); } @@ -1148,7 +1148,7 @@ void codec2_decode_1300(struct CODEC2 *c2, short speech[], const unsigned char * if (frames == 4*50) exit(0); */ - PROFILE_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); @@ -1165,12 +1165,12 @@ void codec2_decode_1300(struct CODEC2 *c2, short speech[], const unsigned char * /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_encode_1200 - AUTHOR......: David Rowe - DATE CREATED: Nov 14 2011 - Encodes 320 speech samples (40ms of speech) into 48 bits. + FUNCTION....: codec2_encode_1200 + AUTHOR......: David Rowe + DATE CREATED: Nov 14 2011 + + Encodes 320 speech samples (40ms of speech) into 48 bits. The codec2 algorithm actually operates internally on 10ms (80 sample) frames, so we run the encoding algorithm four times: @@ -1189,7 +1189,7 @@ void codec2_decode_1300(struct CODEC2 *c2, short speech[], const unsigned char * Voicing (10ms update) 2 2 4 Spare 0 1 1 TOTAL 10 38 48 - + \*---------------------------------------------------------------------------*/ void codec2_encode_1200(struct CODEC2 *c2, unsigned char * bits, short speech[]) @@ -1213,7 +1213,7 @@ void codec2_encode_1200(struct CODEC2 *c2, unsigned char * bits, short speech[]) analyse_one_frame(c2, &model, speech); pack(bits, &nbit, model.voiced, 1); - + /* frame 2: - voicing, joint Wo & E -------------------------------*/ analyse_one_frame(c2, &model, &speech[N]); @@ -1224,7 +1224,7 @@ void codec2_encode_1200(struct CODEC2 *c2, unsigned char * bits, short speech[]) WoE_index = encode_WoE(&model, e, c2->xq_enc); pack(bits, &nbit, WoE_index, WO_E_BITS); - + /* frame 3: - voicing ---------------------------------------------*/ analyse_one_frame(c2, &model, &speech[2*N]); @@ -1234,25 +1234,25 @@ void codec2_encode_1200(struct CODEC2 *c2, unsigned char * bits, short speech[]) analyse_one_frame(c2, &model, &speech[3*N]); pack(bits, &nbit, model.voiced, 1); - + e = speech_to_uq_lsps(lsps, ak, c2->Sn, c2->w, LPC_ORD); WoE_index = encode_WoE(&model, e, c2->xq_enc); pack(bits, &nbit, WoE_index, WO_E_BITS); - + encode_lsps_vq(lsp_indexes, lsps, lsps_, LPC_ORD); for(i=0; ixq_dec, WoE_index); - + for(i=0; iprev_e_dec, e[1]); interp_Wo(&model[2], &model[1], &model[3]); e[2] = interp_energy(e[1], e[3]); - + /* LSPs are sampled every 40ms so we interpolate the 3 frames in between, then recover spectral amplitudes */ @@ -1324,7 +1324,7 @@ void codec2_decode_1200(struct CODEC2 *c2, short speech[], const unsigned char * for(i=0; i<4; i++) { lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD); aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, - c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); + c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); } @@ -1340,12 +1340,12 @@ void codec2_decode_1200(struct CODEC2 *c2, short speech[], const unsigned char * #ifndef CORTEX_M4 /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_encode_700 - AUTHOR......: David Rowe + + FUNCTION....: codec2_encode_700 + AUTHOR......: David Rowe DATE CREATED: April 2015 - Encodes 320 speech samples (40ms of speech) into 28 bits. + Encodes 320 speech samples (40ms of speech) into 28 bits. The codec2 algorithm actually operates internally on 10ms (80 sample) frames, so we run the encoding algorithm four times: @@ -1365,7 +1365,7 @@ void codec2_decode_1200(struct CODEC2 *c2, short speech[], const unsigned char * Voicing 0 1 1 spare 0 2 2 TOTAL 0 28 28 - + \*---------------------------------------------------------------------------*/ void codec2_encode_700(struct CODEC2 *c2, unsigned char * bits, short speech[]) @@ -1399,11 +1399,11 @@ void codec2_encode_700(struct CODEC2 *c2, unsigned char * bits, short speech[]) /* frame 1 --------------------------------------------------------*/ analyse_one_frame(c2, &model, bpf_speech); - + /* frame 2 --------------------------------------------------------*/ analyse_one_frame(c2, &model, &bpf_speech[N]); - + /* frame 3 --------------------------------------------------------*/ analyse_one_frame(c2, &model, &bpf_speech[2*N]); @@ -1428,7 +1428,7 @@ void codec2_encode_700(struct CODEC2 *c2, unsigned char * bits, short speech[]) for(i=0; igray); } - + pack_natural_or_gray(bits, &nbit, spare, 2, c2->gray); assert(nbit == (unsigned)codec2_bits_per_frame(c2)); @@ -1436,9 +1436,9 @@ void codec2_encode_700(struct CODEC2 *c2, unsigned char * bits, short speech[]) /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_decode_700 - AUTHOR......: David Rowe + + FUNCTION....: codec2_decode_700 + AUTHOR......: David Rowe DATE CREATED: April 2015 Decodes frames of 28 bits into 320 samples (40ms) of speech. @@ -1479,11 +1479,11 @@ void codec2_decode_700(struct CODEC2 *c2, short speech[], const unsigned char * e_index = unpack_natural_or_gray(bits, &nbit, 3, c2->gray); e[3] = decode_energy(e_index, 3); - + for(i=0; igray); } - + decode_mels_scalar(mel, indexes, LPC_ORD_LOW); for(i=0; ifft_fwd_cfg, &ak[i][0], LPC_ORD_LOW, &model[i], e[i], &snr, 0, 0, - c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); + c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); } @@ -1545,9 +1545,9 @@ void codec2_decode_700(struct CODEC2 *c2, short speech[], const unsigned char * /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_encode_700b - AUTHOR......: David Rowe + + FUNCTION....: codec2_encode_700b + AUTHOR......: David Rowe DATE CREATED: August 2015 Version b of 700 bit/s codec. After some experiments over the air I @@ -1555,7 +1555,7 @@ void codec2_decode_700(struct CODEC2 *c2, short speech[], const unsigned char * trying to improve the speech quality. This version uses a wider BPF and vector quantised mel-lsps. - Encodes 320 speech samples (40ms of speech) into 28 bits. + Encodes 320 speech samples (40ms of speech) into 28 bits. The codec2 algorithm actually operates internally on 10ms (80 sample) frames, so we run the encoding algorithm four times: @@ -1563,7 +1563,7 @@ void codec2_decode_700(struct CODEC2 *c2, short speech[], const unsigned char * frame 0: nothing frame 1: nothing frame 2: nothing - frame 3: voicing bit, 5 bit scalar Wo and 3 bit E, 18 bit LSP MEL VQ, + frame 3: voicing bit, 5 bit scalar Wo and 3 bit E, 18 bit LSP MEL VQ, 1 spare The bit allocation is: @@ -1576,7 +1576,7 @@ void codec2_decode_700(struct CODEC2 *c2, short speech[], const unsigned char * Voicing 0 1 1 spare 0 1 1 TOTAL 0 28 28 - + \*---------------------------------------------------------------------------*/ void codec2_encode_700b(struct CODEC2 *c2, unsigned char * bits, short speech[]) @@ -1611,11 +1611,11 @@ void codec2_encode_700b(struct CODEC2 *c2, unsigned char * bits, short speech[]) /* frame 1 --------------------------------------------------------*/ analyse_one_frame(c2, &model, bpf_speech); - + /* frame 2 --------------------------------------------------------*/ analyse_one_frame(c2, &model, &bpf_speech[N]); - + /* frame 3 --------------------------------------------------------*/ analyse_one_frame(c2, &model, &bpf_speech[2*N]); @@ -1640,7 +1640,7 @@ void codec2_encode_700b(struct CODEC2 *c2, unsigned char * bits, short speech[]) for(i=0; i<3; i++) { pack_natural_or_gray(bits, &nbit, indexes[i], lspmelvq_cb_bits(i), c2->gray); } - + pack_natural_or_gray(bits, &nbit, spare, 1, c2->gray); assert(nbit == (unsigned)codec2_bits_per_frame(c2)); @@ -1648,9 +1648,9 @@ void codec2_encode_700b(struct CODEC2 *c2, unsigned char * bits, short speech[]) /*---------------------------------------------------------------------------*\ - - FUNCTION....: codec2_decode_700b - AUTHOR......: David Rowe + + FUNCTION....: codec2_decode_700b + AUTHOR......: David Rowe DATE CREATED: August 2015 Decodes frames of 28 bits into 320 samples (40ms) of speech. @@ -1691,11 +1691,11 @@ void codec2_decode_700b(struct CODEC2 *c2, short speech[], const unsigned char * e_index = unpack_natural_or_gray(bits, &nbit, 3, c2->gray); e[3] = decode_energy(e_index, 3); - + for(i=0; i<3; i++) { indexes[i] = unpack_natural_or_gray(bits, &nbit, lspmelvq_cb_bits(i), c2->gray); } - + lspmelvq_decode(indexes, mel, LPC_ORD_LOW); #define MEL_ROUND 10 @@ -1712,9 +1712,9 @@ void codec2_decode_700b(struct CODEC2 *c2, short speech[], const unsigned char * lsps[3][i] = f_*(PI/4000.0); //printf("lsps[3][%d] %f\n", i, lsps[3][i]); } - + /* interpolate ------------------------------------------------*/ - + /* LSPs, Wo, and energy are sampled every 40ms so we interpolate the 3 frames in between, then recover spectral amplitudes */ @@ -1726,7 +1726,7 @@ void codec2_decode_700b(struct CODEC2 *c2, short speech[], const unsigned char * for(i=0; i<4; i++) { lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD_LOW); aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD_LOW, &model[i], e[i], &snr, 0, 0, - c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); + c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); } @@ -1749,10 +1749,10 @@ void codec2_decode_700b(struct CODEC2 *c2, short speech[], const unsigned char * #endif /*---------------------------------------------------------------------------*\ - - FUNCTION....: synthesise_one_frame() - AUTHOR......: David Rowe - DATE CREATED: 23/8/2010 + + FUNCTION....: synthesise_one_frame() + AUTHOR......: David Rowe + DATE CREATED: 23/8/2010 Synthesise 80 speech samples (10ms) from model parameters. @@ -1771,15 +1771,15 @@ void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model, COMP phase_synth_zero_order(c2->fft_fwd_cfg, model, &c2->ex_phase, Aw); - PROFILE_SAMPLE_AND_LOG(pf_start, phase_start, " phase_synth"); + PROFILE_SAMPLE_AND_LOG(pf_start, phase_start, " phase_synth"); postfilter(model, &c2->bg_est); - PROFILE_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); - PROFILE_SAMPLE_AND_LOG2(synth_start, " synth"); + PROFILE_SAMPLE_AND_LOG2(synth_start, " synth"); ear_protection(c2->Sn_, N); @@ -1795,14 +1795,14 @@ void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model, COMP } /*---------------------------------------------------------------------------*\ - - FUNCTION....: analyse_one_frame() - AUTHOR......: David Rowe - DATE CREATED: 23/8/2010 + + FUNCTION....: analyse_one_frame() + AUTHOR......: David Rowe + DATE CREATED: 23/8/2010 Extract sinusoidal model parameters from 80 speech samples (10ms of speech). - + \*---------------------------------------------------------------------------*/ void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]) @@ -1828,7 +1828,7 @@ void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]) /* Estimate pitch */ nlp(c2->nlp,c2->Sn,N,P_MIN,P_MAX,&pitch,Sw, c2->W, &c2->prev_Wo_enc); - PROFILE_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; @@ -1836,21 +1836,21 @@ void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]) /* estimate model parameters */ two_stage_pitch_refinement(model, Sw); - PROFILE_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); - PROFILE_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; - PROFILE_SAMPLE_AND_LOG2(estamps, " est_voicing"); + PROFILE_SAMPLE_AND_LOG2(estamps, " est_voicing"); #ifdef DUMP dump_model(model); #endif } /*---------------------------------------------------------------------------*\ - - FUNCTION....: ear_protection() - AUTHOR......: David Rowe + + FUNCTION....: ear_protection() + AUTHOR......: David Rowe DATE CREATED: Nov 7 2012 Limits output level to protect ears when there are bit errors or the input @@ -1896,7 +1896,7 @@ void codec2_set_lpc_post_filter(struct CODEC2 *c2, int enable, int bass_boost, f c2->gamma = gamma; } -/* +/* Allows optional stealing of one of the voicing bits for use as a spare bit, only 1300 & 1400 & 1600 bit/s supported for now. Experimental method of sending voice/data frames for FreeDV. @@ -1923,7 +1923,7 @@ int codec2_get_spare_bit_index(struct CODEC2 *c2) return 27; // bit 27 is spare break; } - + return -1; } @@ -1947,7 +1947,7 @@ int codec2_rebuild_spare_bit(struct CODEC2 *c2, int unpacked_bits[]) /* if either adjacent frame is voiced, make this one voiced */ - unpacked_bits[2] = (v1 || v3); + unpacked_bits[2] = (v1 || v3); return 0; @@ -1959,7 +1959,7 @@ int codec2_rebuild_spare_bit(struct CODEC2 *c2, int unpacked_bits[]) /* if either adjacent frame is voiced, make this one voiced */ - unpacked_bits[10] = (v1 || v3); + unpacked_bits[10] = (v1 || v3); return 0; @@ -1970,7 +1970,7 @@ int codec2_rebuild_spare_bit(struct CODEC2 *c2, int unpacked_bits[]) /* if either adjacent frame is voiced, make this one voiced */ - unpacked_bits[15] = (v1 || v3); + unpacked_bits[15] = (v1 || v3); return 0; diff --git a/codec2-dev/src/codec2.h b/codec2-dev/src/codec2.h index 65cfb65e..8b1cb5b3 100644 --- a/codec2-dev/src/codec2.h +++ b/codec2-dev/src/codec2.h @@ -4,7 +4,7 @@ AUTHOR......: David Rowe DATE CREATED: 21 August 2010 - Codec 2 fully quantised encoder and decoder functions. If you want use + Codec 2 fully quantised encoder and decoder functions. If you want use Codec 2, these are the functions you need to call. \*---------------------------------------------------------------------------*/ diff --git a/codec2-dev/src/codec2_cohpsk.h b/codec2-dev/src/codec2_cohpsk.h index 063a834d..42f6d18b 100644 --- a/codec2-dev/src/codec2_cohpsk.h +++ b/codec2-dev/src/codec2_cohpsk.h @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - + FILE........: codec2_cohpsk.h AUTHOR......: David Rowe DATE CREATED: March 2015 - + Functions that implement a coherent PSK FDM modem. - + \*---------------------------------------------------------------------------*/ /* @@ -33,8 +33,8 @@ #define COHPSK_NOM_SAMPLES_PER_FRAME 600 #define COHPSK_MAX_SAMPLES_PER_FRAME 625 #define COHPSK_RS 75 -#define COHPSK_FS 7500 /* note this is a wierd - value to get an integer +#define COHPSK_FS 7500 /* note this is a wierd + value to get an integer oversampling rate */ #include "comp.h" @@ -56,6 +56,6 @@ void cohpsk_put_test_bits(struct COHPSK *coh, int *state, short error_pattern[], int *bit_errors, float rx_bits_sd[]); int cohpsk_error_pattern_size(void); void cohpsk_set_frame(struct COHPSK *coh, int frame); -void fdmdv_freq_shift_coh(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, float Fs, +void fdmdv_freq_shift_coh(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, float Fs, COMP *foff_phase_rect, int nin); #endif diff --git a/codec2-dev/src/codec2_fdmdv.h b/codec2-dev/src/codec2_fdmdv.h index 334696c9..4298faba 100644 --- a/codec2-dev/src/codec2_fdmdv.h +++ b/codec2-dev/src/codec2_fdmdv.h @@ -1,19 +1,19 @@ /*---------------------------------------------------------------------------*\ - + FILE........: codec2_fdmdv.h AUTHOR......: David Rowe DATE CREATED: April 14 2012 - + A 1400 bit/s (nominal) Frequency Division Multiplexed Digital Voice (FDMDV) modem. Used for digital audio over HF SSB. See README_fdmdv.txt for more information, and fdmdv_mod.c and fdmdv_demod.c for example usage. - + The name codec2_fdmdv.h is used to make it unique when "make installed". - + References: - + [1] http://n1su.com/fdmdv/FDMDV_Docs_Rel_1_4b.pdf \*---------------------------------------------------------------------------*/ @@ -58,8 +58,8 @@ extern "C" { #include "comp.h" #include "modem_stats.h" -#define FDMDV_NC 14 /* default number of data carriers */ -#define FDMDV_NC_MAX 20 /* maximum number of data carriers */ +#define FDMDV_NC 14 /* default number of data carriers */ +#define FDMDV_NC_MAX 20 /* maximum number of data carriers */ #define FDMDV_BITS_PER_FRAME 28 /* 20ms frames, for nominal 1400 bit/s */ #define FDMDV_NOM_SAMPLES_PER_FRAME 160 /* modulator output samples/frame and nominal demod samples/frame */ /* at 8000 Hz sample rate */ @@ -76,7 +76,7 @@ extern "C" { /* FDMDV states and stats structures */ struct FDMDV; - + struct FDMDV * fdmdv_create(int Nc); void fdmdv_destroy(struct FDMDV *fdmdv_state); void fdmdv_use_old_qpsk_mapping(struct FDMDV *fdmdv_state); @@ -86,11 +86,11 @@ void fdmdv_set_fsep(struct FDMDV *fdmdv_state, float fsep); void fdmdv_mod(struct FDMDV *fdmdv_state, COMP tx_fdm[], int tx_bits[], int *sync_bit); void fdmdv_demod(struct FDMDV *fdmdv_state, int rx_bits[], int *reliable_sync_bit, COMP rx_fdm[], int *nin); - + void fdmdv_get_test_bits(struct FDMDV *fdmdv_state, int tx_bits[]); int fdmdv_error_pattern_size(struct FDMDV *fdmdv_state); void fdmdv_put_test_bits(struct FDMDV *f, int *sync, short error_pattern[], int *bit_errors, int *ntest_bits, int rx_bits[]); - + void fdmdv_get_demod_stats(struct FDMDV *fdmdv_state, struct MODEM_STATS *stats); void fdmdv_8_to_16(float out16k[], float in8k[], int n); @@ -104,7 +104,7 @@ void fdmdv_freq_shift(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, void fdmdv_dump_osc_mags(struct FDMDV *f); void fdmdv_simulate_channel(float *sig_pwr_av, COMP samples[], int nin, float target_snr); - + #ifdef __cplusplus } #endif diff --git a/codec2-dev/src/codec2_fifo.h b/codec2-dev/src/codec2_fifo.h index 383254f6..5a90b75b 100644 --- a/codec2-dev/src/codec2_fifo.h +++ b/codec2-dev/src/codec2_fifo.h @@ -1,14 +1,14 @@ /*---------------------------------------------------------------------------*\ - + FILE........: codec2_fifo.h AUTHOR......: David Rowe DATE CREATED: Oct 15 2012 - + A FIFO design useful in gluing the FDMDV modem and codec together in integrated applications. - + The name codec2_fifo.h is used to make it unique when "make - installed". + installed". \*---------------------------------------------------------------------------*/ diff --git a/codec2-dev/src/codec2_fm.h b/codec2-dev/src/codec2_fm.h index 8b79ae4a..36faece1 100644 --- a/codec2-dev/src/codec2_fm.h +++ b/codec2-dev/src/codec2_fm.h @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - + FILE........: codec2_fm.h AUTHOR......: David Rowe DATE CREATED: February 2015 - + Functions that implement analog FM, see also octave/fm.m. - + \*---------------------------------------------------------------------------*/ /* @@ -34,7 +34,7 @@ struct FM { float Fs; /* setme: sample rate */ float fm_max; /* setme: maximum modulation frequency */ float fd; /* setme: maximum deviation */ - float fc; /* setme: carrier frequency */ + float fc; /* setme: carrier frequency */ COMP *rx_bb; COMP rx_bb_filt_prev; float *rx_dem_mem; diff --git a/codec2-dev/src/codec2_internal.h b/codec2-dev/src/codec2_internal.h index 44ff177f..26a5e2b5 100644 --- a/codec2-dev/src/codec2_internal.h +++ b/codec2-dev/src/codec2_internal.h @@ -1,12 +1,12 @@ /*---------------------------------------------------------------------------*\ - + FILE........: codec2_internal.h - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: April 16 2012 - + Header file for Codec2 internal states, exposed via this header file to assist in testing. - + \*---------------------------------------------------------------------------*/ /* @@ -49,7 +49,7 @@ struct CODEC2 { MODEL prev_model_dec; /* previous frame's model parameters */ float prev_lsps_dec[LPC_ORD]; /* previous frame's LSPs */ float prev_e_dec; /* previous frame's LPC energy */ - + int lpc_pf; /* LPC post filter on */ int bass_boost; /* LPC post filter bass boost */ float beta; /* LPC post filter parameters */ diff --git a/codec2-dev/src/cohpsk.c b/codec2-dev/src/cohpsk.c index bcaacc8b..cb8b0cc4 100644 --- a/codec2-dev/src/cohpsk.c +++ b/codec2-dev/src/cohpsk.c @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - + FILE........: cohpsk.c AUTHOR......: David Rowe DATE CREATED: March 2015 - + Functions that implement a coherent PSK FDM modem. - + \*---------------------------------------------------------------------------*/ /* @@ -26,7 +26,7 @@ */ /*---------------------------------------------------------------------------*\ - + INCLUDES \*---------------------------------------------------------------------------*/ @@ -54,24 +54,24 @@ static COMP qpsk_mod[] = { { 0.0,-1.0}, {-1.0, 0.0} }; - + static int sampling_points[] = {0, 1, 6, 7}; void corr_with_pilots(float *corr_out, float *mag_out, struct COHPSK *coh, int t, float f_fine); void update_ct_symb_buf(COMP ct_symb_buf[][COHPSK_NC*ND], COMP ch_symb[][COHPSK_NC*ND]); /*---------------------------------------------------------------------------*\ - + FUNCTIONS \*---------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------* \ - - FUNCTION....: cohpsk_create - AUTHOR......: David Rowe - DATE CREATED: Marcg 2015 + + FUNCTION....: cohpsk_create + AUTHOR......: David Rowe + DATE CREATED: Marcg 2015 Create and initialise an instance of the modem. Returns a pointer to the modem states or NULL on failure. One set of states is @@ -106,7 +106,7 @@ struct COHPSK *cohpsk_create(void) } } } - + /* Clear symbol buffer memory */ for (r=0; rfsep*( -(COHPSK_NC*ND)/2 - 0.5 + pow(c + 1.0, 0.98) ); - + fdmdv->freq[c].real = cosf(2.0*M_PI*freq_hz/COHPSK_FS); fdmdv->freq[c].imag = sinf(2.0*M_PI*freq_hz/COHPSK_FS); fdmdv->freq_pol[c] = 2.0*M_PI*freq_hz/COHPSK_FS; @@ -183,15 +183,15 @@ struct COHPSK *cohpsk_create(void) coh->ptest_bits_coh_tx = coh->ptest_bits_coh_rx = (int*)test_bits_coh; coh->ptest_bits_coh_end = (int*)test_bits_coh + sizeof(test_bits_coh)/sizeof(int); - + return coh; } /*---------------------------------------------------------------------------*\ - - FUNCTION....: cohpsk_destroy - AUTHOR......: David Rowe + + FUNCTION....: cohpsk_destroy + AUTHOR......: David Rowe DATE CREATED: March 2015 Destroy an instance of the modem. @@ -207,9 +207,9 @@ void cohpsk_destroy(struct COHPSK *coh) /*---------------------------------------------------------------------------*\ - - FUNCTION....: bits_to_qpsk_symbols() - AUTHOR......: David Rowe + + FUNCTION....: bits_to_qpsk_symbols() + AUTHOR......: David Rowe DATE CREATED: March 2015 Rate Rs modulator. Maps bits to parallel DQPSK symbols and inserts pilot symbols. @@ -224,7 +224,7 @@ void bits_to_qpsk_symbols(COMP tx_symb[][COHPSK_NC*ND], int tx_bits[], int nbits /* check number of bits supplied matchs number of QPSK symbols in the frame */ assert((NSYMROW*COHPSK_NC)*2 == nbits); - + /* Insert two rows of Nc pilots at beginning of data frame. @@ -247,24 +247,24 @@ void bits_to_qpsk_symbols(COMP tx_symb[][COHPSK_NC*ND], int tx_bits[], int nbits r++; } for(data_r=0; data_rpilot2[p][pc], ct_symb_buf[sampling_points[p]][c]); } - + linreg(&m, &b, x, y, NPILOTSFRAME+2); for(r=0; rphi_[r][c] = atan2(yfit.imag, yfit.real); } - + /* amplitude estimation */ mag = 0.0; @@ -338,7 +338,7 @@ void qpsk_symbols_to_bits(struct COHPSK *coh, float rx_bits[], COMP ct_symb_buf[ coh->amp_[r][c] = amp_; } } - + /* now correct phase of data symbols */ for(c=0; crx_symb[r][c]; } } - + /* and finally optional diversity combination, note output is soft decn a "1" is < 0 */ for(c=0; c 1) { noise_var = (n*sum_xx - sum_x*sum_x)/(n*(n-1)); @@ -395,22 +395,22 @@ void qpsk_symbols_to_bits(struct COHPSK *coh, float rx_bits[], COMP ct_symb_buf[ /*---------------------------------------------------------------------------*\ - - FUNCTION....: tx_filter_and_upconvert_coh() - AUTHOR......: David Rowe + + FUNCTION....: tx_filter_and_upconvert_coh() + AUTHOR......: David Rowe DATE CREATED: May 2015 Given NC symbols construct M samples (1 symbol) of NC filtered and upconverted symbols. - + TODO: work out a way to merge with fdmdv version, e.g. run time define M/NSYM, and run unittests on fdmdv and cohpsk modem afterwards. \*---------------------------------------------------------------------------*/ -void tx_filter_and_upconvert_coh(COMP tx_fdm[], int Nc, COMP tx_symbols[], +void tx_filter_and_upconvert_coh(COMP tx_fdm[], int Nc, COMP tx_symbols[], COMP tx_filter_memory[COHPSK_NC*ND][COHPSK_NSYM], - COMP phase_tx[], COMP freq[], + COMP phase_tx[], COMP freq[], COMP *fbb_phase, COMP fbb_rect) { int c; @@ -423,7 +423,7 @@ void tx_filter_and_upconvert_coh(COMP tx_fdm[], int Nc, COMP tx_symbols[], gain.real = sqrtf(2.0)/2.0; gain.imag = 0.0; - + for(i=0; ireal /= mag; - fbb_phase->imag /= mag; + fbb_phase->real /= mag; + fbb_phase->imag /= mag; /* shift memory, inserting zeros at end */ @@ -509,12 +509,12 @@ void tx_filter_and_upconvert_coh(COMP tx_fdm[], int Nc, COMP tx_symbols[], -void corr_with_pilots(float *corr_out, float *mag_out, struct COHPSK *coh, int t, float f_fine) +void corr_with_pilots(float *corr_out, float *mag_out, struct COHPSK *coh, int t, float f_fine) { COMP acorr, f_fine_rect, f_corr; float mag, corr; int c, p, pc; - + corr = 0.0; mag = 0.0; for (c=0; cff_rect.real = cosf(coh->f_fine_est*2.0*M_PI/COHPSK_RS); coh->ff_rect.imag = -sinf(coh->f_fine_est*2.0*M_PI/COHPSK_RS); if (coh->verbose) fprintf(stderr, " [%d] fine freq f: %6.2f max_ratio: %f ct: %d\n", coh->frame, coh->f_fine_est, max_corr/max_mag, coh->ct); - + if (max_corr/max_mag > 0.9) { if (coh->verbose) fprintf(stderr, " [%d] encouraging sync word!\n", coh->frame); @@ -588,7 +588,7 @@ void frame_sync_fine_freq_est(struct COHPSK *coh, COMP ch_symb[][COHPSK_NC*ND], else { *next_sync = 0; } - coh->ratio = max_corr/max_mag; + coh->ratio = max_corr/max_mag; } } @@ -603,7 +603,7 @@ void update_ct_symb_buf(COMP ct_symb_buf[][COHPSK_NC*ND], COMP ch_symb[][COHPSK_ for(c=0; cct, coh->f_fine_est); - coh->ratio = fabsf(corr)/mag; + coh->ratio = fabsf(corr)/mag; // printf("%f\n", cabsolute(corr)/mag); - if (fabsf(corr)/mag < 0.8) + if (fabsf(corr)/mag < 0.8) coh->sync_timer++; else - coh->sync_timer = 0; + coh->sync_timer = 0; if (coh->sync_timer == 10) { if (coh->verbose) @@ -635,7 +635,7 @@ int sync_state_machine(struct COHPSK *coh, int sync, int next_sync) next_sync = 0; } } - + sync = next_sync; return sync; @@ -643,9 +643,9 @@ int sync_state_machine(struct COHPSK *coh, int sync, int next_sync) /*---------------------------------------------------------------------------*\ - - FUNCTION....: cohpsk_mod() - AUTHOR......: David Rowe + + FUNCTION....: cohpsk_mod() + AUTHOR......: David Rowe DATE CREATED: 5/4/2015 COHPSK modulator, take a frame of COHPSK_BITS_PER_FRAME bits and @@ -667,18 +667,18 @@ void cohpsk_mod(struct COHPSK *coh, COMP tx_fdm[], int tx_bits[]) bits_to_qpsk_symbols(tx_symb, tx_bits, COHPSK_BITS_PER_FRAME); for(r=0; rtx_filter_memory, + for(c=0; ctx_filter_memory, fdmdv->phase_tx, fdmdv->freq, &fdmdv->fbb_phase_tx, fdmdv->fbb_rect); } } /*---------------------------------------------------------------------------*\ - - FUNCTION....: cohpsk_clip() - AUTHOR......: David Rowe + + FUNCTION....: cohpsk_clip() + AUTHOR......: David Rowe DATE CREATED: May 2015 Hard clips a cohpsk modulator signal to improve PAPR, CLIP threshold @@ -694,18 +694,18 @@ void cohpsk_clip(COMP tx_fdm[]) for(i=0; i COHPSK_CLIP) { sam = fcmult( COHPSK_CLIP/mag, sam); } tx_fdm[i] = sam; } } - + /*---------------------------------------------------------------------------*\ - - FUNCTION....: fdm_downconvert_coh - AUTHOR......: David Rowe + + FUNCTION....: fdm_downconvert_coh + AUTHOR......: David Rowe DATE CREATED: May 2015 Frequency shift each modem carrier down to NC baseband signals. @@ -724,8 +724,8 @@ void fdm_downconvert_coh(COMP rx_baseband[COHPSK_NC][COHPSK_M+COHPSK_M/P], int N assert(nin <= (COHPSK_M+COHPSK_M/P)); /* downconvert */ - - for (c=0; creal /= mag; - foff_phase_rect->imag /= mag; + foff_phase_rect->real /= mag; + foff_phase_rect->imag /= mag; } @@ -843,7 +843,7 @@ void rate_Fs_rx_processing(struct COHPSK *coh, COMP ch_symb[][COHPSK_NC*ND], COM fdm_downconvert_coh(rx_baseband, COHPSK_NC*ND, rx_fdm_frame_bb, fdmdv->phase_rx, fdmdv->freq, nin); rx_filter_coh(rx_filt, COHPSK_NC*ND, rx_baseband, coh->rx_filter_memory, nin); rx_timing = rx_est_timing(rx_onesym, fdmdv->Nc, rx_filt, fdmdv->rx_filter_mem_timing, env, nin, COHPSK_M); - + for(c=0; cprev_rx_symbols[c] = rx_onesym[c]; /* 4th power strips QPSK modulation, by multiplying phase by 4 - Using the abs value of the real coord was found to help + Using the abs value of the real coord was found to help non-linear issues when noise power was large. */ amod_strip = cmult(adiff, adiff); @@ -880,19 +880,19 @@ void rate_Fs_rx_processing(struct COHPSK *coh, COMP ch_symb[][COHPSK_NC*ND], COM /* loop filter made up of 1st order IIR plus integrator. Integerator was found to be reqd */ - + fdmdv->foff_filt = (1.0-beta)*fdmdv->foff_filt + beta*atan2(mod_strip.imag, mod_strip.real); //printf("foff_filt: %f angle: %f\n", fdmdv->foff_filt, atan2(mod_strip.imag, mod_strip.real)); *f_est += g*fdmdv->foff_filt; - } + } /* Optional logging used for testing against Octave version */ if (coh->rx_baseband_log) { assert(nin <= (COHPSK_M+COHPSK_M/P)); - for(c=0; crx_baseband_log[c*coh->rx_baseband_log_col_sz + coh->rx_baseband_log_col_index + i] = rx_baseband[c][i]; + coh->rx_baseband_log[c*coh->rx_baseband_log_col_sz + coh->rx_baseband_log_col_index + i] = rx_baseband[c][i]; } } coh->rx_baseband_log_col_index += nin; @@ -900,17 +900,17 @@ void rate_Fs_rx_processing(struct COHPSK *coh, COMP ch_symb[][COHPSK_NC*ND], COM } if (coh->rx_filt_log) { - for(c=0; crx_filt_log[c*coh->rx_filt_log_col_sz + coh->rx_filt_log_col_index + i] = rx_filt[c][i]; + coh->rx_filt_log[c*coh->rx_filt_log_col_sz + coh->rx_filt_log_col_index + i] = rx_filt[c][i]; } } - coh->rx_filt_log_col_index += nin/(COHPSK_M/P); + coh->rx_filt_log_col_index += nin/(COHPSK_M/P); } if (coh->ch_symb_log) { for(c=0; cch_symb_log[coh->ch_symb_log_r*COHPSK_NC*ND + c] = ch_symb[r][c]; + coh->ch_symb_log[coh->ch_symb_log_r*COHPSK_NC*ND + c] = ch_symb[r][c]; } coh->ch_symb_log_r++; } @@ -932,9 +932,9 @@ void rate_Fs_rx_processing(struct COHPSK *coh, COMP ch_symb[][COHPSK_NC*ND], COM /*---------------------------------------------------------------------------*\ - - FUNCTION....: cohpsk_demod() - AUTHOR......: David Rowe + + FUNCTION....: cohpsk_demod() + AUTHOR......: David Rowe DATE CREATED: 5/4/2015 COHPSK demodulator, takes an array of (nominally) nin_frame = @@ -972,7 +972,7 @@ void cohpsk_demod(struct COHPSK *coh, float rx_bits[], int *sync_good, COMP rx_f max_ratio = 0.0; f_est = 0.0; for (coh->f_est = FDMDV_FCENTRE-40.0; coh->f_est <= FDMDV_FCENTRE+40.0; coh->f_est += 40.0) { - + if (coh->verbose) fprintf(stderr, " [%d] acohpsk.f_est: %f +/- 20\n", coh->frame, coh->f_est); @@ -1037,14 +1037,14 @@ void cohpsk_demod(struct COHPSK *coh, float rx_bits[], int *sync_good, COMP rx_f for(c=0; cct_symb_ff_buf[r][c] = coh->ct_symb_buf[coh->ct+r][c]; } - } + } /* If in sync just do sample rate processing on latest frame */ if (sync == 1) { rate_Fs_rx_processing(coh, ch_symb, rx_fdm, &coh->f_est, NSYMROWPILOT, coh->nin, 1); frame_sync_fine_freq_est(coh, ch_symb, sync, &next_sync); - + for(r=0; r<2; r++) for(c=0; cct_symb_ff_buf[r][c] = coh->ct_symb_ff_buf[r+NSYMROWPILOT][c]; @@ -1054,20 +1054,20 @@ void cohpsk_demod(struct COHPSK *coh, float rx_bits[], int *sync_good, COMP rx_f } /* if we are in sync complete demodulation with symbol rate processing */ - + *sync_good = 0; if ((next_sync == 1) || (sync == 1)) { qpsk_symbols_to_bits(coh, rx_bits, coh->ct_symb_ff_buf); *sync_good = 1; } - sync = sync_state_machine(coh, sync, next_sync); + sync = sync_state_machine(coh, sync, next_sync); coh->sync = sync; /* work out how many samples we need for the next call to account for differences in tx and rx sample clocks */ - nin = COHPSK_M; + nin = COHPSK_M; if (sync == 1) { if (coh->rx_timing > COHPSK_M/P) nin = COHPSK_M + COHPSK_M/P; @@ -1082,9 +1082,9 @@ void cohpsk_demod(struct COHPSK *coh, float rx_bits[], int *sync_good, COMP rx_f /*---------------------------------------------------------------------------*\ - - FUNCTION....: cohpsk_fs_offset() - AUTHOR......: David Rowe + + FUNCTION....: cohpsk_fs_offset() + AUTHOR......: David Rowe DATE CREATED: May 2015 Simulates small Fs offset between mod and demod. @@ -1096,7 +1096,7 @@ int cohpsk_fs_offset(COMP out[], COMP in[], int n, float sample_rate_ppm) double tin, f; int tout, t1, t2; - tin = 0.0; tout = 0; + tin = 0.0; tout = 0; while (tin < n) { t1 = floor(tin); t2 = ceil(tin); @@ -1113,9 +1113,9 @@ int cohpsk_fs_offset(COMP out[], COMP in[], int n, float sample_rate_ppm) /*---------------------------------------------------------------------------*\ - - FUNCTION....: cohpsk_get_demod_stats() - AUTHOR......: David Rowe + + FUNCTION....: cohpsk_get_demod_stats() + AUTHOR......: David Rowe DATE CREATED: 14 June 2015 Fills stats structure with a bunch of demod information. @@ -1167,9 +1167,9 @@ void cohpsk_set_frame(struct COHPSK *coh, int frame) /*---------------------------------------------------------------------------*\ - - FUNCTION....: cohpsk_get_test_bits() - AUTHOR......: David Rowe + + FUNCTION....: cohpsk_get_test_bits() + AUTHOR......: David Rowe DATE CREATED: June 2015 Returns a frame of known test bits. @@ -1187,9 +1187,9 @@ void cohpsk_get_test_bits(struct COHPSK *coh, int rx_bits[]) /*---------------------------------------------------------------------------*\ - - FUNCTION....: cohpsk_put_test_bits() - AUTHOR......: David Rowe + + FUNCTION....: cohpsk_put_test_bits() + AUTHOR......: David Rowe DATE CREATED: June 2015 Accepts bits from demod and attempts to sync with the known @@ -1250,13 +1250,13 @@ void cohpsk_put_test_bits(struct COHPSK *coh, int *state, short error_pattern[], coh->ptest_bits_coh_rx = (int*)test_bits_coh; } } - + //fprintf(stderr, "state: %d next_state: %d bit_errors: %d\n", *state, next_state, *bit_errors); *state = next_state; } -int cohpsk_error_pattern_size(void) { +int cohpsk_error_pattern_size(void) { return COHPSK_BITS_PER_FRAME; } diff --git a/codec2-dev/src/cohpsk_ch.c b/codec2-dev/src/cohpsk_ch.c index c263639d..a3eb14ae 100644 --- a/codec2-dev/src/cohpsk_ch.c +++ b/codec2-dev/src/cohpsk_ch.c @@ -1,13 +1,13 @@ /*---------------------------------------------------------------------------*\ - + FILE........: cohpsk_ch.c - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: May 2015 - + Channel impairment program for testing command line versions of cohpsk modem. - - TODO: + + TODO: [ ] measure and prints pwrs to check, prints warning [ ] SNR in 3000Hz input [ ] example operation with sox for sample rate change @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) COMP ch_fdm[BUF_N]; float ssbfiltbuf[SSBFILT_N+BUF_N]; float ssbfiltout[BUF_N]; - + COMP phase_ch; int noise_r, noise_end; float No, variance; @@ -113,16 +113,16 @@ int main(int argc, char *argv[]) exit(1); } fprintf(stderr, "NodB: %4.2f foff: %4.2f Hz fading: %d inclip: %4.2f\n", NodB, foff_hz, fading_en, inclip); - - phase_ch.real = 1.0; phase_ch.imag = 0.0; - noise_r = 0; + + phase_ch.real = 1.0; phase_ch.imag = 0.0; + noise_r = 0; noise_end = sizeof(noise)/sizeof(COMP); /* N = var = NoFs */ No = pow(10.0, NodB/10.0); variance = COHPSK_FS*No; - + tx_pwr = tx_pwr_fade = noise_pwr = 0.0; clipped = 0; peak = 0.0; @@ -169,7 +169,7 @@ int main(int argc, char *argv[]) /* --------------------------------------------------------*\ Main Loop \*---------------------------------------------------------*/ - + while(fread(buf, sizeof(short), BUF_N, fin) == BUF_N) { frames++; @@ -179,7 +179,7 @@ int main(int argc, char *argv[]) for(i=0, j=HT_N; i peak) { peak = fabs(htbuf[j]); } @@ -210,7 +210,7 @@ int main(int argc, char *argv[]) //printf("%d %f %f\n", i, ch_in[i].real, ch_in[i].imag); } assert(j <= (BUF_N+HT_N)); - + /* update HT memory */ for(i=0; i noise_end) { noise_r = 0; - //fprintf(stderr, " [%d] noise wrap\n", f); - } + //fprintf(stderr, " [%d] noise wrap\n", f); + } } /* FIR filter to simulate (a rather flat) SSB filter. Might @@ -309,15 +309,15 @@ int main(int argc, char *argv[]) buffering to occur */ if (fout == stdout) fflush(stdout); - if (fin == stdin) fflush(stdin); + if (fin == stdin) fflush(stdin); } fclose(fin); fclose(fout); - - fprintf(stderr, "peak pwr.....: %7.2f\nav input pwr.: %7.2f\nav pwr fading: %7.2f\nnoise pwr....: %7.2f\nclipping.....: %7.2f %%\n", + + fprintf(stderr, "peak pwr.....: %7.2f\nav input pwr.: %7.2f\nav pwr fading: %7.2f\nnoise pwr....: %7.2f\nclipping.....: %7.2f %%\n", peak*peak, - tx_pwr/(frames*BUF_N), + tx_pwr/(frames*BUF_N), tx_pwr_fade/(frames*BUF_N), noise_pwr/(frames*BUF_N), 100.0*clipped/frames @@ -333,7 +333,7 @@ int main(int argc, char *argv[]) snr3k, EbNo700 ); - + return 0; } diff --git a/codec2-dev/src/cohpsk_demod.c b/codec2-dev/src/cohpsk_demod.c index fcac69d2..c453822d 100644 --- a/codec2-dev/src/cohpsk_demod.c +++ b/codec2-dev/src/cohpsk_demod.c @@ -1,12 +1,12 @@ /*---------------------------------------------------------------------------*\ - + FILE........: cohpsk_demod.c - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: April 6 2015 - + Given an input file of raw file (8kHz, 16 bit shorts) of COHPSK modem samples, outputs a file of bits (note one bit per int, not compressed). - + \*---------------------------------------------------------------------------*/ /* @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) if (argc == 4) { if ( (foct = fopen(argv[3],"wt")) == NULL ) { fprintf(stderr, "Error opening output Octave file: %s: %s.\n", - argv[3], strerror(errno)); + argv[3], strerror(errno)); exit(1); } oct = 1; @@ -124,9 +124,9 @@ int main(int argc, char *argv[]) if (oct) { for(r=0; ramp_[r][c]; - rx_phi_log[log_data_r*COHPSK_NC*ND+c] = cohpsk->phi_[r][c]; - rx_symb_log[log_data_r*COHPSK_NC*ND+c] = cohpsk->rx_symb[r][c]; + rx_amp_log[log_data_r*COHPSK_NC*ND+c] = cohpsk->amp_[r][c]; + rx_phi_log[log_data_r*COHPSK_NC*ND+c] = cohpsk->phi_[r][c]; + rx_symb_log[log_data_r*COHPSK_NC*ND+c] = cohpsk->rx_symb[r][c]; } } @@ -144,7 +144,7 @@ int main(int argc, char *argv[]) buffering to occur */ if (fout == stdout) fflush(stdout); - if (fin == stdin) fflush(stdin); + if (fin == stdin) fflush(stdin); } fclose(fin); @@ -153,17 +153,17 @@ int main(int argc, char *argv[]) /* optionally dump Octave files */ if (foct != NULL) { - octave_save_float(foct, "rx_amp_log_c", (float*)rx_amp_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); - octave_save_float(foct, "rx_phi_log_c", (float*)rx_phi_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); - octave_save_complex(foct, "rx_symb_log_c", (COMP*)rx_symb_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); - octave_save_float(foct, "rx_timing_log_c", (float*)cohpsk->rx_timing_log, 1, cohpsk->rx_timing_log_index, cohpsk->rx_timing_log_index); - octave_save_float(foct, "f_est_log_c", f_est_log, 1, logframes, logframes); - octave_save_float(foct, "ratio_log_c", ratio_log, 1, logframes, logframes); + octave_save_float(foct, "rx_amp_log_c", (float*)rx_amp_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); + octave_save_float(foct, "rx_phi_log_c", (float*)rx_phi_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); + octave_save_complex(foct, "rx_symb_log_c", (COMP*)rx_symb_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); + octave_save_float(foct, "rx_timing_log_c", (float*)cohpsk->rx_timing_log, 1, cohpsk->rx_timing_log_index, cohpsk->rx_timing_log_index); + octave_save_float(foct, "f_est_log_c", f_est_log, 1, logframes, logframes); + octave_save_float(foct, "ratio_log_c", ratio_log, 1, logframes, logframes); fclose(foct); } cohpsk_destroy(cohpsk); - + return 0; } diff --git a/codec2-dev/src/cohpsk_get_test_bits.c b/codec2-dev/src/cohpsk_get_test_bits.c index ed4f5473..0ea18e35 100644 --- a/codec2-dev/src/cohpsk_get_test_bits.c +++ b/codec2-dev/src/cohpsk_get_test_bits.c @@ -1,9 +1,9 @@ /*---------------------------------------------------------------------------*\ - + FILE........: cohpsk_put_test_bits.c - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: April 2015 - + Generates a file of test bits, useful for input to cohpsk_mod. \*---------------------------------------------------------------------------*/ @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) sd_tx_bits[i] = 1.0 - 2.0*tx_bits[i]; fwrite(sd_tx_bits, sizeof(float), COHPSK_BITS_PER_FRAME, fout); - + /* if this is in a pipeline, we probably don't want the usual buffering to occur */ diff --git a/codec2-dev/src/cohpsk_internal.h b/codec2-dev/src/cohpsk_internal.h index 119d9680..b77aff0b 100644 --- a/codec2-dev/src/cohpsk_internal.h +++ b/codec2-dev/src/cohpsk_internal.h @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - + FILE........: cohpsk_internal.h AUTHOR......: David Rowe DATE CREATED: March 2015 - + Functions that implement a coherent PSK FDM modem. - + \*---------------------------------------------------------------------------*/ /* @@ -29,7 +29,7 @@ #define __COHPSK_INTERNAL__ #define NCT_SYMB_BUF (2*NSYMROWPILOT+2) -#define ND 2 /* diversity factor ND 1 is no diveristy, ND we have orginal plus +#define ND 2 /* diversity factor ND 1 is no diveristy, ND we have orginal plus one copy */ #define NSW 4 /* number of sync window frames */ #define COHPSK_ND 2 /* diversity factor */ @@ -39,13 +39,13 @@ #define COHPSK_EXCESS_BW 0.5 /* excess BW factor of root nyq filter */ #define COHPSK_NT 5 /* number of symbols we estimate timing over */ #define COHPSK_CLIP 6.5 /* hard clipping for Nc*Nc=14 to reduce PAPR */ - + #include "fdmdv_internal.h" #include "kiss_fft.h" struct COHPSK { COMP ch_fdm_frame_buf[NSW*NSYMROWPILOT*COHPSK_M]; /* buffer of several frames of symbols from channel */ - float pilot2[2*NPILOTSFRAME][COHPSK_NC]; + float pilot2[2*NPILOTSFRAME][COHPSK_NC]; float phi_[NSYMROW][COHPSK_NC*ND]; /* phase estimates for this frame of rx data symbols */ float amp_[NSYMROW][COHPSK_NC*ND]; /* amplitude estimates for this frame of rx data symbols */ COMP rx_symb[NSYMROW][COHPSK_NC*ND]; /* demodulated symbols */ @@ -69,7 +69,7 @@ struct COHPSK { float noise_rms; struct FDMDV *fdmdv; - + int verbose; int *ptest_bits_coh_tx; @@ -96,9 +96,9 @@ struct COHPSK { void bits_to_qpsk_symbols(COMP tx_symb[][COHPSK_NC*COHPSK_ND], int tx_bits[], int nbits); void qpsk_symbols_to_bits(struct COHPSK *coh, float rx_bits[], COMP ct_symb_buf[][COHPSK_NC*COHPSK_ND]); -void tx_filter_and_upconvert_coh(COMP tx_fdm[], int Nc, COMP tx_symbols[], +void tx_filter_and_upconvert_coh(COMP tx_fdm[], int Nc, COMP tx_symbols[], COMP tx_filter_memory[COHPSK_NC][COHPSK_NSYM], - COMP phase_tx[], COMP freq[], + COMP phase_tx[], COMP freq[], COMP *fbb_phase, COMP fbb_rect); void fdm_downconvert_coh(COMP rx_baseband[COHPSK_NC][COHPSK_M+COHPSK_M/P], int Nc, COMP rx_fdm[], COMP phase_rx[], COMP freq[], int nin); void rx_filter_coh(COMP rx_filt[COHPSK_NC+1][P+1], int Nc, COMP rx_baseband[COHPSK_NC+1][COHPSK_M+COHPSK_M/P], COMP rx_filter_memory[COHPSK_NC+1][COHPSK_NFILTER], int nin); diff --git a/codec2-dev/src/cohpsk_mod.c b/codec2-dev/src/cohpsk_mod.c index 3678d273..94c6fa30 100644 --- a/codec2-dev/src/cohpsk_mod.c +++ b/codec2-dev/src/cohpsk_mod.c @@ -1,13 +1,13 @@ /*---------------------------------------------------------------------------*\ - + FILE........: cohpsk_mod.c - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: April 5 2015 - + Given an input file of bits (note one bit per float, soft decision format), outputs a raw file (8kHz, 16 bit shorts) of COHPSK modem samples ready to send over a HF radio channel. - + \*---------------------------------------------------------------------------*/ /* @@ -90,7 +90,7 @@ int main(int argc, char *argv[]) buffering to occur */ if (fout == stdout) fflush(stdout); - if (fin == stdin) fflush(stdin); + if (fin == stdin) fflush(stdin); } fclose(fin); diff --git a/codec2-dev/src/cohpsk_put_test_bits.c b/codec2-dev/src/cohpsk_put_test_bits.c index f11fa16c..3ca792fd 100644 --- a/codec2-dev/src/cohpsk_put_test_bits.c +++ b/codec2-dev/src/cohpsk_put_test_bits.c @@ -1,10 +1,10 @@ /*---------------------------------------------------------------------------*\ - + FILE........: cohpsk_put_test_bits.c - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: April 2015 - - Sinks a stream of test bits generated by cohpsk_get_test_bits, useful for + + Sinks a stream of test bits generated by cohpsk_get_test_bits, useful for testing coh psk mod and demod. \*---------------------------------------------------------------------------*/ @@ -71,7 +71,7 @@ int main(int argc, char *argv[]) if (argc == 3) { if ( (foct = fopen(argv[2],"wt")) == NULL ) { fprintf(stderr, "Error opening output Octave file: %s: %s.\n", - argv[2], strerror(errno)); + argv[2], strerror(errno)); exit(1); } } @@ -96,8 +96,8 @@ int main(int argc, char *argv[]) } if (foct != NULL) { - octave_save_int(foct, "nerr_log_c", nerr_log, 1, logframes); - octave_save_int(foct, "error_positions_hist_c", error_positions_hist, 1, COHPSK_BITS_PER_FRAME); + octave_save_int(foct, "nerr_log_c", nerr_log, 1, logframes); + octave_save_int(foct, "error_positions_hist_c", error_positions_hist, 1, COHPSK_BITS_PER_FRAME); fclose(foct); } diff --git a/codec2-dev/src/comp.h b/codec2-dev/src/comp.h index cedcab37..ffc20c16 100644 --- a/codec2-dev/src/comp.h +++ b/codec2-dev/src/comp.h @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - + FILE........: comp.h - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: 24/08/09 - + Complex number definition. - + \*---------------------------------------------------------------------------*/ /* diff --git a/codec2-dev/src/comp_prim.h b/codec2-dev/src/comp_prim.h index 41fe8178..af402c14 100644 --- a/codec2-dev/src/comp_prim.h +++ b/codec2-dev/src/comp_prim.h @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - + FILE........: comp_prim.h - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: Marh 2015 - + Complex number maths primitives. - + \*---------------------------------------------------------------------------*/ /* @@ -29,7 +29,7 @@ #define __COMP_PRIM__ /*---------------------------------------------------------------------------*\ - + FUNCTIONS \*---------------------------------------------------------------------------*/ diff --git a/codec2-dev/src/defines.h b/codec2-dev/src/defines.h index 5275ad7f..7b43b773 100644 --- a/codec2-dev/src/defines.h +++ b/codec2-dev/src/defines.h @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - FILE........: defines.h - AUTHOR......: David Rowe - DATE CREATED: 23/4/93 - - Defines and structures used throughout the codec. - + FILE........: defines.h + AUTHOR......: David Rowe + DATE CREATED: 23/4/93 + + Defines and structures used throughout the codec. + \*---------------------------------------------------------------------------*/ /* @@ -29,9 +29,9 @@ #define __DEFINES__ /*---------------------------------------------------------------------------*\ - - DEFINES - + + DEFINES + \*---------------------------------------------------------------------------*/ /* General defines */ @@ -58,9 +58,9 @@ #define P_MAX 160 /* maximum pitch */ /*---------------------------------------------------------------------------*\ - - TYPEDEFS - + + TYPEDEFS + \*---------------------------------------------------------------------------*/ /* Structure to hold model parameters for one frame */ diff --git a/codec2-dev/src/dump.c b/codec2-dev/src/dump.c index f172424d..16aedc31 100644 --- a/codec2-dev/src/dump.c +++ b/codec2-dev/src/dump.c @@ -1,9 +1,9 @@ /*---------------------------------------------------------------------------*\ - + FILE........: dump.c - AUTHOR......: David Rowe - DATE CREATED: 25/8/09 - + AUTHOR......: David Rowe + DATE CREATED: 25/8/09 + Routines to dump data to text files for Octave analysis. \*---------------------------------------------------------------------------*/ @@ -157,10 +157,10 @@ void dump_Sn(float Sn[]) { for(i=0; iWo, model->L); + sprintf(line,"%12f %12d ", model->Wo, model->L); for(l=1; l<=model->L; l++) { sprintf(s,"%12f ",model->A[l]); strcat(line, s); @@ -257,10 +257,10 @@ void dump_model(MODEL *model) { sprintf(s,"%12f ", 0.0); strcat(line,s); } - + sprintf(s,"%d\n",model->voiced); strcat(line,s); - fprintf(fmodel,"%s",line); + fprintf(fmodel,"%s",line); } void dump_quantised_model(MODEL *model) { @@ -276,7 +276,7 @@ void dump_quantised_model(MODEL *model) { assert(fqmodel != NULL); } - sprintf(line,"%12f %12d ", model->Wo, model->L); + sprintf(line,"%12f %12d ", model->Wo, model->L); for(l=1; l<=model->L; l++) { sprintf(s,"%12f ",model->A[l]); strcat(line, s); @@ -285,10 +285,10 @@ void dump_quantised_model(MODEL *model) { sprintf(s,"%12f ", 0.0); strcat(line, s); } - + sprintf(s,"%d\n",model->voiced); strcat(line, s); - fprintf(fqmodel, "%s", line); + fprintf(fqmodel, "%s", line); } void dump_phase(float phase[], int L) { @@ -307,7 +307,7 @@ void dump_phase(float phase[], int L) { fprintf(fphase,"%f\t",phase[l]); for(l=L+1; l<=MAX_AMP; l++) fprintf(fphase,"%f\t",0.0); - fprintf(fphase,"\n"); + fprintf(fphase,"\n"); } void dump_phase_(float phase_[], int L) { @@ -326,7 +326,7 @@ void dump_phase_(float phase_[], int L) { fprintf(fphase_,"%f\t",phase_[l]); for(l=L+1; lNc = Nc; f->ntest_bits = Nc*NB*4; @@ -109,7 +109,7 @@ struct FDMDV * fdmdv_create(int Nc) /* Spread initial FDM carrier phase out as far as possible. This helped PAPR for a few dB. We don't need to adjust rx phase as DQPSK takes care of that. */ - + f->phase_tx[c].real = cosf(2.0*PI*c/(Nc+1)); f->phase_tx[c].imag = sinf(2.0*PI*c/(Nc+1)); @@ -127,7 +127,7 @@ struct FDMDV * fdmdv_create(int Nc) f->freq[Nc].real = cosf(2.0*PI*0.0/FS); f->freq[Nc].imag = sinf(2.0*PI*0.0/FS); f->freq_pol[Nc] = 2.0*PI*0.0/FS; - + f->fbb_rect.real = cosf(2.0*PI*FDMDV_FCENTRE/FS); f->fbb_rect.imag = sinf(2.0*PI*FDMDV_FCENTRE/FS); f->fbb_pol = 2.0*PI*FDMDV_FCENTRE/FS; @@ -151,7 +151,7 @@ struct FDMDV * fdmdv_create(int Nc) } f->pilot_lut_index = 0; f->prev_pilot_lut_index = 3*M; - + for(i=0; irxdec_lpf_mem[i].real = 0.0; f->rxdec_lpf_mem[i].imag = 0.0; @@ -167,8 +167,8 @@ struct FDMDV * fdmdv_create(int Nc) f->foff_phase_rect.imag = 0.0; for(i=0; irx_fdm_mem[i].real = 0.0; - f->rx_fdm_mem[i].imag = 0.0; + f->rx_fdm_mem[i].real = 0.0; + f->rx_fdm_mem[i].imag = 0.0; } f->fest_state = 0; @@ -189,9 +189,9 @@ struct FDMDV * fdmdv_create(int Nc) } /*---------------------------------------------------------------------------*\ - - FUNCTION....: fdmdv_destroy - AUTHOR......: David Rowe + + FUNCTION....: fdmdv_destroy + AUTHOR......: David Rowe DATE CREATED: 16/4/2012 Destroy an instance of the modem. @@ -208,7 +208,7 @@ void fdmdv_destroy(struct FDMDV *fdmdv) void fdmdv_use_old_qpsk_mapping(struct FDMDV *fdmdv) { - fdmdv->old_qpsk_mapping = 1; + fdmdv->old_qpsk_mapping = 1; } @@ -218,9 +218,9 @@ int fdmdv_bits_per_frame(struct FDMDV *fdmdv) } /*---------------------------------------------------------------------------*\ - - FUNCTION....: fdmdv_get_test_bits() - AUTHOR......: David Rowe + + FUNCTION....: fdmdv_get_test_bits() + AUTHOR......: David Rowe DATE CREATED: 16/4/2012 Generate a frame of bits from a repeating sequence of random data. OK so @@ -272,9 +272,9 @@ void fdmdv_set_fsep(struct FDMDV *f, float fsep) { /*---------------------------------------------------------------------------*\ - - FUNCTION....: bits_to_dqpsk_symbols() - AUTHOR......: David Rowe + + FUNCTION....: bits_to_dqpsk_symbols() + AUTHOR......: David Rowe DATE CREATED: 16/4/2012 Maps bits to parallel DQPSK symbols. Generate Nc+1 QPSK symbols from @@ -292,7 +292,7 @@ void bits_to_dqpsk_symbols(COMP tx_symbols[], int Nc, COMP prev_tx_symbols[], in old (suboptimal) V0.91 FreeDV mapping */ for(c=0; creal /= mag; - fbb_phase->imag /= mag; + fbb_phase->real /= mag; + fbb_phase->imag /= mag; /* shift memory, inserting zeros at end */ @@ -498,9 +498,9 @@ void tx_filter_and_upconvert(COMP tx_fdm[], int Nc, COMP tx_symbols[], /*---------------------------------------------------------------------------*\ - - FUNCTION....: fdm_upconvert() - AUTHOR......: David Rowe + + FUNCTION....: fdm_upconvert() + AUTHOR......: David Rowe DATE CREATED: 17/4/2012 Construct FDM signal by frequency shifting each filtered symbol @@ -521,7 +521,7 @@ void fdm_upconvert(COMP tx_fdm[], int Nc, COMP tx_baseband[NC+1][M], COMP phase_ tx_fdm[i].imag = 0.0; } - for (c=0; c<=Nc; c++) + for (c=0; c<=Nc; c++) for (i=0; ireal /= mag; - fbb_phase->imag /= mag; + fbb_phase->real /= mag; + fbb_phase->imag /= mag; } /*---------------------------------------------------------------------------*\ - - FUNCTION....: fdmdv_mod() - AUTHOR......: David Rowe + + FUNCTION....: fdmdv_mod() + AUTHOR......: David Rowe DATE CREATED: 26/4/2012 FDMDV modulator, take a frame of FDMDV_BITS_PER_FRAME bits and generates a frame of FDMDV_SAMPLES_PER_FRAME modulated symbols. - Sync bit is returned to aid alignment of your next frame. + Sync bit is returned to aid alignment of your next frame. The sync_bit value returned will be used for the _next_ frame. @@ -583,25 +583,25 @@ void fdmdv_mod(struct FDMDV *fdmdv, COMP tx_fdm[], int tx_bits[], int *sync_bit) 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)); - PROFILE_SAMPLE_AND_LOG(tx_filter_and_upconvert_start, mod_start, " bits_to_dqpsk_symbols"); - tx_filter_and_upconvert(tx_fdm, fdmdv->Nc, tx_symbols, fdmdv->tx_filter_memory, + PROFILE_SAMPLE_AND_LOG(tx_filter_and_upconvert_start, mod_start, " bits_to_dqpsk_symbols"); + tx_filter_and_upconvert(tx_fdm, fdmdv->Nc, tx_symbols, fdmdv->tx_filter_memory, fdmdv->phase_tx, fdmdv->freq, &fdmdv->fbb_phase_tx, fdmdv->fbb_rect); - PROFILE_SAMPLE_AND_LOG2(tx_filter_and_upconvert_start, " tx_filter_and_upconvert"); + PROFILE_SAMPLE_AND_LOG2(tx_filter_and_upconvert_start, " tx_filter_and_upconvert"); *sync_bit = fdmdv->tx_pilot_bit; } /*---------------------------------------------------------------------------*\ - - FUNCTION....: generate_pilot_fdm() - AUTHOR......: David Rowe + + FUNCTION....: generate_pilot_fdm() + AUTHOR......: David Rowe DATE CREATED: 19/4/2012 Generate M samples of DBPSK pilot signal for Freq offset estimation. \*---------------------------------------------------------------------------*/ -void generate_pilot_fdm(COMP *pilot_fdm, int *bit, float *symbol, +void generate_pilot_fdm(COMP *pilot_fdm, int *bit, float *symbol, float *filter_mem, COMP *phase, COMP *freq) { int i,j,k; @@ -609,11 +609,11 @@ void generate_pilot_fdm(COMP *pilot_fdm, int *bit, float *symbol, /* +1 -1 +1 -1 DBPSK sync carrier, once filtered becomes (roughly) two spectral lines at +/- RS/2 */ - + if (*bit) *symbol = -*symbol; - if (*bit) + if (*bit) *bit = 0; else *bit = 1; @@ -622,7 +622,7 @@ void generate_pilot_fdm(COMP *pilot_fdm, int *bit, float *symbol, filter_mem[NFILTER-1] = (sqrtf(2)/2) * *symbol; for(i=0; i= MPILOTFFT/2) *foff = (ix - MPILOTFFT)*r; else @@ -758,9 +758,9 @@ void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[], } /*---------------------------------------------------------------------------*\ - - FUNCTION....: rx_est_freq_offset() - AUTHOR......: David Rowe + + FUNCTION....: rx_est_freq_offset() + AUTHOR......: David Rowe DATE CREATED: 19/4/2012 Estimate frequency offset of FDM signal using BPSK pilot. Note that @@ -786,7 +786,7 @@ float rx_est_freq_offset(struct FDMDV *f, COMP rx_fdm[], int nin, int do_fft) f->pilot_lut_index++; if (f->pilot_lut_index >= 4*M) f->pilot_lut_index = 0; - + prev_pilot[i] = f->pilot_lut[f->prev_pilot_lut_index]; f->prev_pilot_lut_index++; if (f->prev_pilot_lut_index >= 4*M) @@ -818,14 +818,14 @@ float rx_est_freq_offset(struct FDMDV *f, COMP rx_fdm[], int nin, int do_fft) foff = foff1; else foff = foff2; - + return foff; } /*---------------------------------------------------------------------------*\ - - FUNCTION....: fdmdv_freq_shift() - AUTHOR......: David Rowe + + FUNCTION....: fdmdv_freq_shift() + AUTHOR......: David Rowe DATE CREATED: 26/4/2012 Frequency shift modem signal. The use of complex input and output allows @@ -833,7 +833,7 @@ float rx_est_freq_offset(struct FDMDV *f, COMP rx_fdm[], int nin, int do_fft) \*---------------------------------------------------------------------------*/ -void fdmdv_freq_shift(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, +void fdmdv_freq_shift(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, COMP *foff_phase_rect, int nin) { COMP foff_rect; @@ -850,14 +850,14 @@ void fdmdv_freq_shift(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, /* normalise digital oscilator as the magnitude can drfift over time */ mag = cabsolute(*foff_phase_rect); - foff_phase_rect->real /= mag; - foff_phase_rect->imag /= mag; + foff_phase_rect->real /= mag; + foff_phase_rect->imag /= mag; } /*---------------------------------------------------------------------------*\ - - FUNCTION....: fdm_downconvert - AUTHOR......: David Rowe + + FUNCTION....: fdm_downconvert + AUTHOR......: David Rowe DATE CREATED: 22/4/2012 Frequency shift each modem carrier down to Nc+1 baseband signals. @@ -874,8 +874,8 @@ void fdm_downconvert(COMP rx_baseband[NC+1][M+M/P], int Nc, COMP rx_fdm[], COMP assert(nin <= (M+M/P)); /* downconvert */ - - for (c=0; c P) rx_timing -= P; if (rx_timing < -P) @@ -1188,19 +1188,19 @@ float rx_est_timing(COMP rx_symbols[], high_sample = ceilf(rx_timing); //printf("rx_timing: %f low_sample: %d high_sample: %d fract: %f\n", rx_timing, low_sample, high_sample, fract); - + for(c=0; crx_test_bits_mem[i] = f->rx_test_bits_mem[j]; for(i=f->ntest_bits-bits_per_frame,j=0; intest_bits; i++,j++) f->rx_test_bits_mem[i] = rx_bits[j]; - + /* see how many bit errors we get when checked against test sequence */ - + *bit_errors = 0; for(i=0; intest_bits; i++) { error_pattern[i] = test_bits[i] ^ f->rx_test_bits_mem[i]; @@ -1376,19 +1376,19 @@ void fdmdv_put_test_bits(struct FDMDV *f, int *sync, short error_pattern[], /* if less than a thresh we are aligned and in sync with test sequence */ ber = (float)*bit_errors/f->ntest_bits; - + *sync = 0; if (ber < 0.2) *sync = 1; - + *ntest_bits = f->ntest_bits; - + } /*---------------------------------------------------------------------------*\ - - FUNCTION....: freq_state(() - AUTHOR......: David Rowe + + FUNCTION....: freq_state(() + AUTHOR......: David Rowe DATE CREATED: 24/4/2012 Freq offset state machine. Moves between coarse and fine states @@ -1442,7 +1442,7 @@ int freq_state(int *reliable_sync_bit, int sync_bit, int *state, int *timer, int if (*timer == 25) /* sync has been good for 500ms */ next_state = 2; } - else + else next_state = 0; /* quickly fall out of sync */ break; case 2: /* good sync state */ @@ -1468,19 +1468,19 @@ int freq_state(int *reliable_sync_bit, int sync_bit, int *state, int *timer, int sync = 1; else sync = 0; - + return sync; } /*---------------------------------------------------------------------------*\ - - FUNCTION....: fdmdv_demod() - AUTHOR......: David Rowe + + FUNCTION....: fdmdv_demod() + AUTHOR......: David Rowe DATE CREATED: 26/4/2012 FDMDV demodulator, take an array of FDMDV_SAMPLES_PER_FRAME modulated samples, returns an array of FDMDV_BITS_PER_FRAME bits, - plus the sync bit. + plus the sync bit. The input signal is complex to support single sided frequency shifting before the demod input (e.g. fdmdv2 click to tune feature). @@ -1492,7 +1492,7 @@ int freq_state(int *reliable_sync_bit, int sync_bit, int *state, int *timer, int \*---------------------------------------------------------------------------*/ -void fdmdv_demod(struct FDMDV *fdmdv, int rx_bits[], +void fdmdv_demod(struct FDMDV *fdmdv, int rx_bits[], int *reliable_sync_bit, COMP rx_fdm[], int *nin) { float foff_coarse, foff_fine; @@ -1511,53 +1511,53 @@ void fdmdv_demod(struct FDMDV *fdmdv, int rx_bits[], fdmdv_freq_shift(rx_fdm_bb, rx_fdm, -FDMDV_FCENTRE, &fdmdv->fbb_phase_rx, *nin); /* freq offset estimation and correction */ - + PROFILE_SAMPLE(demod_start); foff_coarse = rx_est_freq_offset(fdmdv, rx_fdm_bb, *nin, !fdmdv->sync); - PROFILE_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); - PROFILE_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, + 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); - 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, M); - PROFILE_SAMPLE_AND_LOG(qpsk_to_bits_start, rx_est_timing_start, " rx_est_timing"); - + 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, M); + 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 */ *nin = M; if (fdmdv->rx_timing > 2*M/P) *nin += M/P; - + if (fdmdv->rx_timing < 0) *nin -= M/P; - - foff_fine = qpsk_to_bits(rx_bits, &sync_bit, fdmdv->Nc, fdmdv->phase_difference, fdmdv->prev_rx_symbols, rx_symbols, + + 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)); - PROFILE_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); - PROFILE_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); - PROFILE_SAMPLE_AND_LOG2(freq_state_start, " freq_state"); + PROFILE_SAMPLE_AND_LOG2(freq_state_start, " freq_state"); fdmdv->foff -= TRACK_COEFF*foff_fine; } /*---------------------------------------------------------------------------*\ - - FUNCTION....: calc_snr() - AUTHOR......: David Rowe + + FUNCTION....: calc_snr() + AUTHOR......: David Rowe DATE CREATED: 17 May 2012 Calculate current SNR estimate (3000Hz noise BW) @@ -1570,12 +1570,12 @@ float calc_snr(int Nc, float sig_est[], float noise_est[]) float mean, N50, N50dB, N3000dB; float snr_dB; int c; - + S = 0.0; for(c=0; csig_pwr_av: %e target_snr_linear: %f noise_pwr_4000Hz: %e noise_gain: %e\n", + /* + fprintf(stderr, "sig_pwr: %f f->sig_pwr_av: %e target_snr_linear: %f noise_pwr_4000Hz: %e noise_gain: %e\n", sig_pwr, f->sig_pwr_av, target_snr_linear, noise_pwr_4000Hz, noise_gain); */ } diff --git a/codec2-dev/src/fdmdv_channel.c b/codec2-dev/src/fdmdv_channel.c index e4d87cbe..68eaf89d 100644 --- a/codec2-dev/src/fdmdv_channel.c +++ b/codec2-dev/src/fdmdv_channel.c @@ -1,9 +1,9 @@ /*---------------------------------------------------------------------------*\ - + FILE........: fdmdv_channel.c - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: 2 August 2014 - + Given an input raw file (8kHz, 16 bit shorts) of FDMDV modem samples, adds channel impairments and outputs to another raw file. @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) fdmdv = fdmdv_create(FDMDV_NC); while(fread(rx_fdm_buf, sizeof(short), FDMDV_NOM_SAMPLES_PER_FRAME, fin) == FDMDV_NOM_SAMPLES_PER_FRAME) { - + for(i=0; i> (22-i)) & 0x1; } @@ -267,7 +267,7 @@ int main(int argc, char *argv[]) for(i=0,j=16; i<12; i++,j++) { unpacked_output_bits[j] = (codeword2 >> (22-i)) & 0x1; } - + } /* pack bits, MSB first */ @@ -282,14 +282,14 @@ int main(int argc, char *argv[]) byte++; } } - + fwrite(packed_output_bits, sizeof(char), bytes_per_output_frame, fout); /* if this is in a pipeline, we probably don't want the usual buffering to occur */ if (fout == stdout) fflush(stdout); - if (fin == stdin) fflush(stdin); + if (fin == stdin) fflush(stdin); } codec2_destroy(codec2); diff --git a/codec2-dev/src/fec_enc.c b/codec2-dev/src/fec_enc.c index a26731fe..9b777a72 100644 --- a/codec2-dev/src/fec_enc.c +++ b/codec2-dev/src/fec_enc.c @@ -97,7 +97,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Error in mode: %s. Must be 2000, 1850, or 1600\n", argv[3]); exit(1); } - + /* input parameters and buffers */ codec2 = codec2_create(codec2_mode); @@ -110,7 +110,7 @@ int main(int argc, char *argv[]) unpacked_input_bits = (int*)malloc(bits_per_input_frame*sizeof(int)); assert(unpacked_input_bits != NULL); - /* + /* Output parameters and buffers. Data is split into two 20ms frames for transmission over modem, but this doesn't really bother us here, as fdmdv_mod takes care of that. @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) assert(packed_output_bits != NULL); unpacked_output_bits = (int*)malloc(bits_per_output_frame*sizeof(int)); assert(unpacked_output_bits != NULL); - + fprintf(stderr, "mode: %d Nc: %d\n", mode, Nc); fprintf(stderr, "input bits: %d input_bytes: %d output_bits: %d output_bytes: %d\n", bits_per_input_frame, bytes_per_input_frame, bits_per_output_frame, bytes_per_output_frame); @@ -221,7 +221,7 @@ int main(int argc, char *argv[]) } codeword2 = golay23_encode(data); fprintf(stderr, "codeword2: 0x0%x\n", codeword2); - + /* now pack output frame with parity bits at end to make them as far apart as possible from the data they protect. Parity bits are LSB of the Golay codeword */ @@ -287,14 +287,14 @@ int main(int argc, char *argv[]) } } assert(byte == bytes_per_output_frame); - + fwrite(packed_output_bits, sizeof(char), bytes_per_output_frame, fout); /* if this is in a pipeline, we probably don't want the usual buffering to occur */ if (fout == stdout) fflush(stdout); - if (fin == stdin) fflush(stdin); + if (fin == stdin) fflush(stdin); } codec2_destroy(codec2); diff --git a/codec2-dev/src/fifo.c b/codec2-dev/src/fifo.c index d562a6ac..f9aadc3d 100644 --- a/codec2-dev/src/fifo.c +++ b/codec2-dev/src/fifo.c @@ -1,9 +1,9 @@ /*---------------------------------------------------------------------------*\ - + FILE........: fifo.c AUTHOR......: David Rowe DATE CREATED: Oct 15 2012 - + A FIFO design useful in gluing the FDMDV modem and codec together in integrated applications. The unittest/tfifo indicates these routines are thread safe without the need for syncronisation @@ -98,7 +98,7 @@ int fifo_read(struct FIFO *fifo, short data[], int n) assert(fifo != NULL); assert(data != NULL); - + if (n > fifo_used(fifo)) { return -1; } diff --git a/codec2-dev/src/fm.c b/codec2-dev/src/fm.c index 42c9b903..9d3bb371 100644 --- a/codec2-dev/src/fm.c +++ b/codec2-dev/src/fm.c @@ -1,12 +1,12 @@ /*---------------------------------------------------------------------------*\ - + FILE........: fm.c AUTHOR......: David Rowe DATE CREATED: February 2015 - + Functions that implement analog FM modulation and demodulation, see also octave/fm.m. - + \*---------------------------------------------------------------------------*/ /* @@ -27,7 +27,7 @@ */ /*---------------------------------------------------------------------------*\ - + DEFINES \*---------------------------------------------------------------------------*/ @@ -35,7 +35,7 @@ #define FILT_MEM 200 /*---------------------------------------------------------------------------*\ - + INCLUDES \*---------------------------------------------------------------------------*/ @@ -51,15 +51,15 @@ #include "comp_prim.h" /*---------------------------------------------------------------------------*\ - + FUNCTIONS \*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*\ - - FUNCTION....: fm_create - AUTHOR......: David Rowe + + FUNCTION....: fm_create + AUTHOR......: David Rowe DATE CREATED: 24 Feb 2015 Create and initialise an instance of the "modem". Returns a pointer @@ -102,9 +102,9 @@ void fm_destroy(struct FM *fm_states) } /*---------------------------------------------------------------------------*\ - - FUNCTION....: fm_demod - AUTHOR......: David Rowe + + FUNCTION....: fm_demod + AUTHOR......: David Rowe DATE CREATED: 24 Feb 2015 Demodulate a FM signal to baseband audio. @@ -114,9 +114,9 @@ void fm_destroy(struct FM *fm_states) void fm_demod(struct FM *fm_states, float rx_out[], float rx[]) { float Fs = fm_states->Fs; - float fc = fm_states->fc; + float fc = fm_states->fc; float wc = 2*M_PI*fc/Fs; - float fd = fm_states->fd; + float fd = fm_states->fd; float wd = 2*M_PI*fd/Fs; COMP *rx_bb = fm_states->rx_bb + FILT_MEM; COMP wc_rect, rx_bb_filt, rx_bb_diff; @@ -133,23 +133,23 @@ void fm_demod(struct FM *fm_states, float rx_out[], float rx[]) /* down to complex baseband */ fm_states->lo_phase = cmult(fm_states->lo_phase, wc_rect); - rx_bb[i] = fcmult(rx[i], fm_states->lo_phase); + rx_bb[i] = fcmult(rx[i], fm_states->lo_phase); /* input FIR filter */ rx_bb_filt.real = 0.0; rx_bb_filt.imag = 0.0; - + for(k=0; klo_phase.real, fm_states->lo_phase.imag); //printf("%f %f %f\n", rx[i], rx_bb[i].real, rx_bb[i].imag); //printf("%f %f\n", rx_bb_filt.real, rx_bb_filt.imag); - /* + /* Differentiate first, in rect domain, then find angle, this puts signal on the positive side of the real axis and helps atan2() behaive. @@ -157,7 +157,7 @@ void fm_demod(struct FM *fm_states, float rx_out[], float rx[]) rx_bb_diff = cmult(rx_bb_filt, cconj(fm_states->rx_bb_filt_prev)); fm_states->rx_bb_filt_prev = rx_bb_filt; - + rx_dem = atan2f(rx_bb_diff.imag, rx_bb_diff.real); /* limit maximum phase jumps, to remove static type noise at low SNRs */ @@ -191,15 +191,15 @@ void fm_demod(struct FM *fm_states, float rx_out[], float rx[]) /* normalise digital oscillator as the magnitude can drift over time */ mag = cabsolute(fm_states->lo_phase); - fm_states->lo_phase.real /= mag; - fm_states->lo_phase.imag /= mag; + fm_states->lo_phase.real /= mag; + fm_states->lo_phase.imag /= mag; } /*---------------------------------------------------------------------------*\ - - FUNCTION....: fm_mod - AUTHOR......: Brady O'Brien + + FUNCTION....: fm_mod + AUTHOR......: Brady O'Brien DATE CREATED: Sept. 10 2015 Modulate an FM signal from a baseband modulating signal @@ -220,13 +220,13 @@ void fm_mod(struct FM *fm_states, float tx_in[], float tx_out[]){ float tx_phase = fm_states->tx_phase; //Transmit phase in rads float w; //Temp variable for phase of VFO during loop int i; - + //Go through the samples, spin the oscillator, and generate some FM for(i=0; itx_phase; //Transmit phase in rads float w; //Temp variable for phase of VFO during loop int i; - + //Go through the samples, spin the oscillator, and generate some FM for(i=0; imode = mode; f->test_frames = f->smooth_symbols = 0; f->freedv_put_error_pattern = NULL; f->error_pattern_callback_state = NULL; - + if (mode == FREEDV_MODE_1600) { f->snr_squelch_thresh = 2.0; f->squelch_en = 1; @@ -117,7 +117,7 @@ struct freedv *freedv_open(int mode) { if (mode == FREEDV_MODE_700) codec2_mode = CODEC2_MODE_700; else - codec2_mode = CODEC2_MODE_700B; + codec2_mode = CODEC2_MODE_700B; f->cohpsk = cohpsk_create(); f->nin = COHPSK_NOM_SAMPLES_PER_FRAME; f->n_nat_modem_samples = COHPSK_NOM_SAMPLES_PER_FRAME; // native modem samples as used by the modem @@ -154,7 +154,7 @@ struct freedv *freedv_open(int mode) { if (mode == FREEDV_MODE_1600) f->codec_bits = (int*)malloc(nbit*sizeof(int)); if ((mode == FREEDV_MODE_700) || (mode == FREEDV_MODE_700B)) - f->codec_bits = (int*)malloc(COHPSK_BITS_PER_FRAME*sizeof(int)); + f->codec_bits = (int*)malloc(COHPSK_BITS_PER_FRAME*sizeof(int)); if ((f->packed_codec_bits == NULL) || (f->codec_bits == NULL)) return NULL; @@ -177,14 +177,14 @@ struct freedv *freedv_open(int mode) { f->freedv_put_next_rx_char = NULL; f->total_bit_errors = 0; - + return f; } /*---------------------------------------------------------------------------*\ - + FUNCTION....: freedv_close - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: 3 August 2014 Frees up memory. @@ -219,9 +219,9 @@ void freedv_close(struct freedv *freedv) { } /*---------------------------------------------------------------------------*\ - + FUNCTION....: freedv_tx - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: 3 August 2014 Takes a frame of input speech samples, encodes and modulates them to @@ -277,7 +277,7 @@ void freedv_comptx(struct freedv *f, COMP mod_out[], short speech_in[]) { int bits_per_codec_frame, bits_per_modem_frame; int data, codeword1, data_flag_index, nspare; COMP tx_fdm[f->n_nat_modem_samples]; - + assert((f->mode == FREEDV_MODE_1600) || (f->mode == FREEDV_MODE_700) || (f->mode == FREEDV_MODE_700B)); if (f->mode == FREEDV_MODE_1600) { @@ -297,17 +297,17 @@ void freedv_comptx(struct freedv *f, COMP mod_out[], short speech_in[]) { byte++; } } - + // spare bit in frame that codec defines. Use this 1 // bit/frame to send txt messages data_flag_index = codec2_get_spare_bit_index(f->codec2); - + if (f->nvaricode_bits) { f->codec_bits[data_flag_index] = f->tx_varicode_bits[f->varicode_bit_index++]; f->nvaricode_bits--; - } - + } + if (f->nvaricode_bits == 0) { /* get new char and encode */ char s[2]; @@ -347,7 +347,7 @@ void freedv_comptx(struct freedv *f, COMP mod_out[], short speech_in[]) { f->tx_bits[i] = (codeword1 >> (10-j)) & 0x1; } f->tx_bits[i] = 0; /* spare bit */ - + /* optionally overwrite with test frames */ if (f->test_frames) { @@ -391,7 +391,7 @@ void freedv_comptx(struct freedv *f, COMP mod_out[], short speech_in[]) { byte++; } } - + // spare bits in frame that codec defines. Use these spare // bits/frame to send txt messages @@ -401,14 +401,14 @@ void freedv_comptx(struct freedv *f, COMP mod_out[], short speech_in[]) { nspare = 1; // Just one spare bit for FREEDV_MODE_700B data_flag_index = codec2_get_spare_bit_index(f->codec2); - + for(k=0; knvaricode_bits) { f->codec_bits[j+data_flag_index+k] = f->tx_varicode_bits[f->varicode_bit_index++]; //fprintf(stderr, "%d %d\n", j+data_flag_index+k, f->codec_bits[j+data_flag_index+k]); f->nvaricode_bits--; - } - + } + if (f->nvaricode_bits == 0) { /* get new char and encode */ char s[2]; @@ -421,7 +421,7 @@ void freedv_comptx(struct freedv *f, COMP mod_out[], short speech_in[]) { } } - + /* optionally ovwerwrite the codec bits with test frames */ if (f->test_frames) { @@ -452,9 +452,9 @@ int freedv_nin(struct freedv *f) { } /*---------------------------------------------------------------------------*\ - + FUNCTION....: freedv_rx - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: 3 August 2014 Takes a frame of samples from the radio receiver, demodulates and @@ -512,7 +512,7 @@ int freedv_rx(struct freedv *f, short speech_out[], short demod_in[]) { rx_fdm[i].imag = 0.0; } - return freedv_comprx(f, speech_out, rx_fdm); + return freedv_comprx(f, speech_out, rx_fdm); } @@ -567,7 +567,7 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) { if (reliable_sync_bit == 1) { f->evenframe = 1; } - + if (f->stats.sync) { if (f->evenframe == 0) { memcpy(f->rx_bits, f->fdmdv_bits, bits_per_fdmdv_frame*sizeof(int)); @@ -575,7 +575,7 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) { } else { memcpy(&f->rx_bits[bits_per_fdmdv_frame], f->fdmdv_bits, bits_per_fdmdv_frame*sizeof(int)); - + if (f->test_frames == 0) { recd_codeword = 0; for(i=0; i<8; i++) { @@ -596,7 +596,7 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) { //codeword1 = recd_codeword; //fprintf(stderr, "received codeword1: 0x%x decoded codeword1: 0x%x\n", recd_codeword, codeword1); - + for(i=0; icodec_bits[i] = f->rx_bits[i]; @@ -606,7 +606,7 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) { for(i=8,j=11; i<12; i++,j++) { f->codec_bits[j] = (codeword1 >> (22-i)) & 0x1; } - + // extract txt msg data bit ------------------------------------------------------------ data_flag_index = codec2_get_spare_bit_index(f->codec2); @@ -640,7 +640,7 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) { else { int test_frame_sync, bit_errors, ntest_bits, k; short error_pattern[fdmdv_error_pattern_size(f->fdmdv)]; - + for(k=0; k<2; k++) { /* test frames, so lets sync up to the test frames and count any errors */ fdmdv_put_test_bits(f->fdmdv, &test_frame_sync, error_pattern, &bit_errors, &ntest_bits, &f->rx_bits[k*bits_per_fdmdv_frame]); @@ -687,13 +687,13 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) { f->evenframe = 0; else f->evenframe = 1; - //fprintf(stderr,"%d\n", f->evenframe); + //fprintf(stderr,"%d\n", f->evenframe); } /* if (sync) .... */ else { /* if not in sync pass through analog samples */ /* this lets us "hear" whats going on, e.g. during tuning */ - + //fprintf(stderr, "out of sync\n"); if (f->squelch_en == 0) { @@ -718,7 +718,7 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) { // echo samples back out as default (say if sync not found) for(i=0; iptFilter8000to7500, 15, 16); //if (i != f->nin) @@ -749,9 +749,9 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) { } for (j=0; jmode == FREEDV_MODE_700) nspare = 2; else @@ -759,7 +759,7 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) { for(k=0; kvaricode_dec_states, &ascii_out, abit, 1, 1); if (n_ascii && (f->freedv_put_next_rx_char != NULL)) { (*f->freedv_put_next_rx_char)(f->callback_state, ascii_out); @@ -783,7 +783,7 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) { if (f->squelch_en && (f->stats.snr_est < f->snr_squelch_thresh)) { for(i=0; in_speech_samples; i++) - speech_out[i] = 0; + speech_out[i] = 0; } speech_out += codec2_samples_per_frame(f->codec2); } @@ -805,34 +805,34 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) { } for(i=0; in_speech_samples; i++) - speech_out[i] = 0; - nout = f->n_speech_samples; + speech_out[i] = 0; + nout = f->n_speech_samples; } - + } /* no valid FreeDV signal - squelch output */ if (sync == 0) { - nout = freedv_nin(f); + nout = freedv_nin(f); if (f->squelch_en) { for(i=0; isz_erro struct CODEC2 *freedv_get_codec2 (struct freedv *f){return f->codec2;} -void freedv_get_modem_extended_stats(struct freedv *f, struct MODEM_STATS *stats) -{ +void freedv_get_modem_extended_stats(struct freedv *f, struct MODEM_STATS *stats) +{ if (f->mode == FREEDV_MODE_1600) fdmdv_get_demod_stats(f->fdmdv, stats); #ifndef CORTEX_M4 @@ -959,7 +959,7 @@ void freedv_get_modem_extended_stats(struct freedv *f, struct MODEM_STATS *stats /*-- Functions below this line are private, and not meant for public use --*/ /*---------------------------------------------------------------------------*\ - + FUNCTIONS...: quisk_filt_cfInit AUTHOR......: Jim Ahlstrom DATE CREATED: 27 August 2015 @@ -982,7 +982,7 @@ static void quisk_filt_cfInit(struct quisk_cfFilter * filter, float * coefs, int } /*---------------------------------------------------------------------------*\ - + FUNCTIONS...: quisk_filt_destroy AUTHOR......: Jim Ahlstrom DATE CREATED: 27 August 2015 @@ -1004,7 +1004,7 @@ static void quisk_filt_destroy(struct quisk_cfFilter * filter) } /*---------------------------------------------------------------------------*\ - + FUNCTIONS...: quisk_cfInterpDecim AUTHOR......: Jim Ahlstrom DATE CREATED: 27 August 2015 diff --git a/codec2-dev/src/freedv_api.h b/codec2-dev/src/freedv_api.h index 183b4d94..05f860b2 100644 --- a/codec2-dev/src/freedv_api.h +++ b/codec2-dev/src/freedv_api.h @@ -1,14 +1,14 @@ /*---------------------------------------------------------------------------*\ - + FILE........: freedv_api.h AUTHOR......: David Rowe DATE CREATED: August 2014 - + Library of API functions that implement FreeDV "modes", useful for embedding FreeDV in other programs. Please see the documentation for each function in freedv_api.c, and the sample freedv_tx.c and freedv_rx.c programs. - + \*---------------------------------------------------------------------------*/ /* diff --git a/codec2-dev/src/freedv_api_internal.h b/codec2-dev/src/freedv_api_internal.h index 038d037e..bd52683d 100644 --- a/codec2-dev/src/freedv_api_internal.h +++ b/codec2-dev/src/freedv_api_internal.h @@ -1,9 +1,9 @@ /*---------------------------------------------------------------------------*\ - + FILE........: freedv_api_internal.h AUTHOR......: David Rowe DATE CREATED: August 2014 - + This declares the structure freedv. A pointer to this structure is returned by the FreeDV API freedv_open() function. The pointer is used by the other FreeDV API functions declared in freedv_api.h. This @@ -11,7 +11,7 @@ functions are declared in freedv_api.h. Changes to this structure are expected. Changes (except additions) to freedv_api.h are discouraged. - + \*---------------------------------------------------------------------------*/ /* @@ -110,7 +110,7 @@ struct freedv { short tx_varicode_bits[VARICODE_MAX_BITS]; int nvaricode_bits; int varicode_bit_index; - + /* user defined function ptrs to produce and consume ASCII characters using aux txt channel */ diff --git a/codec2-dev/src/freedv_rx.c b/codec2-dev/src/freedv_rx.c index 80c17d22..f88189f1 100644 --- a/codec2-dev/src/freedv_rx.c +++ b/codec2-dev/src/freedv_rx.c @@ -1,17 +1,17 @@ /*---------------------------------------------------------------------------*\ - + FILE........: freedv_rx.c AUTHOR......: David Rowe DATE CREATED: August 2014 - + Demo receive program for FreeDV API functions, some side information written to freedv_rx_log.txt - + Example usage (all one line): - codec2-dev/build_linux/src$ ./freedv_tx 1600 ../../raw/ve9qrp_10s.raw - | + codec2-dev/build_linux/src$ ./freedv_tx 1600 ../../raw/ve9qrp_10s.raw - | ./freedv_rx 1600 - - | play -t raw -r 8000 -s -2 - - + \*---------------------------------------------------------------------------*/ /* @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) { argv[3], strerror(errno)); exit(1); } - + freedv = freedv_open(mode); assert(freedv != NULL); @@ -104,7 +104,7 @@ int main(int argc, char *argv[]) { } freedv_set_snr_squelch_thresh(freedv, -100.0); freedv_set_squelch_en(freedv, 1); - + n_speech_samples = freedv_get_n_speech_samples(freedv); n_max_modem_samples = freedv_get_n_max_modem_samples(freedv); speech_out = (short*)malloc(sizeof(short)*n_speech_samples); @@ -132,11 +132,11 @@ int main(int argc, char *argv[]) { fwrite(speech_out, sizeof(short), nout, fout); freedv_get_modem_stats(freedv, &sync, &snr_est); total_bit_errors = freedv_get_total_bit_errors(freedv); - + /* log some side info to the txt file */ - + if (ftxt != NULL) { - fprintf(ftxt, "frame: %d demod sync: %d nin:%d demod snr: %3.2f dB bit errors: %d\n", + fprintf(ftxt, "frame: %d demod sync: %d nin:%d demod snr: %3.2f dB bit errors: %d\n", frame, sync, nin, snr_est, total_bit_errors); } @@ -144,7 +144,7 @@ int main(int argc, char *argv[]) { buffering to occur */ if (fout == stdout) fflush(stdout); - if (fin == stdin) fflush(stdin); + if (fin == stdin) fflush(stdin); } if (freedv_get_test_frames(freedv)) { diff --git a/codec2-dev/src/freedv_tx.c b/codec2-dev/src/freedv_tx.c index ee3f07f5..1c6ef407 100644 --- a/codec2-dev/src/freedv_tx.c +++ b/codec2-dev/src/freedv_tx.c @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - + FILE........: freedv_tx.c AUTHOR......: David Rowe DATE CREATED: August 2014 - + Demo transmit program for FreeDV API functions. - + \*---------------------------------------------------------------------------*/ /* @@ -41,11 +41,11 @@ struct my_callback_state { char my_get_next_tx_char(void *callback_state) { struct my_callback_state* pstate = (struct my_callback_state*)callback_state; char c = *pstate->ptx_str++; - + if (*pstate->ptx_str == 0) { pstate->ptx_str = pstate->tx_str; } - + return c; } @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) { argv[3], strerror(errno)); exit(1); } - + freedv = freedv_open(mode); assert(freedv != NULL); @@ -120,7 +120,7 @@ int main(int argc, char *argv[]) { buffering to occur */ if (fout == stdout) fflush(stdout); - if (fin == stdin) fflush(stdin); + if (fin == stdin) fflush(stdin); } free(speech_in); diff --git a/codec2-dev/src/generate_codebook.c b/codec2-dev/src/generate_codebook.c index 0bea80d8..705f29d3 100644 --- a/codec2-dev/src/generate_codebook.c +++ b/codec2-dev/src/generate_codebook.c @@ -1,9 +1,9 @@ /*---------------------------------------------------------------------------*\ - + FILE........: generate_codebook.c - AUTHOR......: Bruce Perens - DATE CREATED: 29 Sep 2010 - + AUTHOR......: Bruce Perens + DATE CREATED: 29 Sep 2010 + Generate header files containing LSP quantisers, runs at compile time. \*---------------------------------------------------------------------------*/ @@ -92,7 +92,7 @@ get_float(FILE * in, const char * name, char * * cursor, char * buffer, while ( (c = *s) != '\0' && !isdigit(c) && c != '-' && c != '.' ) s++; - + /* Comments start with "#" and continue to the end of the line. */ if ( c != '\0' && c != '#' ) { char * end = 0; diff --git a/codec2-dev/src/genlspdtcb.c b/codec2-dev/src/genlspdtcb.c index efac19c5..4b6607ee 100644 --- a/codec2-dev/src/genlspdtcb.c +++ b/codec2-dev/src/genlspdtcb.c @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - + FILE........: genlspdtcb.c - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: 2 Nov 2011 - + Generates codebooks (quantisation tables) for LSP delta-T VQ. - + \*---------------------------------------------------------------------------*/ /* @@ -48,20 +48,20 @@ float lsp5to10[] = { #include #include -void create_codebook_text_file(char filename[], float lsp[], +void create_codebook_text_file(char filename[], float lsp[], int rows, int cols); int main(void) { create_codebook_text_file("codebook/lspdt1-4.txt", lsp1to4, 4, 3); - create_codebook_text_file("codebook/lspdt5-10.txt", lsp5to10, 6, 3); + create_codebook_text_file("codebook/lspdt5-10.txt", lsp5to10, 6, 3); return 0; } -void create_codebook_text_file(char filename[], float lsp[], - int rows, int cols) +void create_codebook_text_file(char filename[], float lsp[], + int rows, int cols) { FILE *f; - int i, digits[MAX_ROWS]; + int i, digits[MAX_ROWS]; f = fopen(filename, "wt"); if (f == NULL) { @@ -85,6 +85,6 @@ void create_codebook_text_file(char filename[], float lsp[], digits[i+1]++; } } while (digits[rows-1] != cols); - + fclose(f); } diff --git a/codec2-dev/src/golay23.c b/codec2-dev/src/golay23.c index ada17c31..9c31d3ab 100644 --- a/codec2-dev/src/golay23.c +++ b/codec2-dev/src/golay23.c @@ -5,7 +5,7 @@ DATE CREATED: 3 March 2013 To test: - + src$ gcc golay23.c -o golay23 -Wall -DGOLAY23_UNITTEST -DRUN_TIME_TABLES src$ ./golay23 @@ -37,9 +37,9 @@ * * Because of its relatively low length (23), dimension (12) and number of * redundant bits (11), the binary (23,12,7) Golay code can be encoded and - * decoded simply by using look-up tables. The program below uses a 16K + * decoded simply by using look-up tables. The program below uses a 16K * encoding table and an 8K decoding table. - * + * * For more information, suggestions, or other ideas on implementing error * correcting codes, please contact me at (I'm temporarily in Japan, but * below is my U.S. address): @@ -54,7 +54,7 @@ * extended Golay code. * * COPYRIGHT NOTICE: This computer program is free for non-commercial purposes. - * You may implement this program for any non-commercial application. You may + * You may implement this program for any non-commercial application. You may * also implement this program for commercial purposes, provided that you * obtain my written permission. Any modification of this program is covered * by this copyright. @@ -113,7 +113,7 @@ static int arr2int(int a[], int r) { int i; long mul, result = 0, temp; - + for (i=1; i<=r; i++) { mul = 1; temp = a[i]-1; @@ -131,7 +131,7 @@ void nextcomb(int n, int r, int a[]) */ { int i, j; - + a[r]++; if (a[r] <= n) return; @@ -155,7 +155,7 @@ int get_syndrome(int pattern) */ { int aux = X22; - + if (pattern >= X11) while (pattern & MASK12) { while (!(aux & pattern)) @@ -166,9 +166,9 @@ int get_syndrome(int pattern) } /*---------------------------------------------------------------------------*\ - - FUNCTION....: golay23_init() - AUTHOR......: David Rowe + + FUNCTION....: golay23_init() + AUTHOR......: David Rowe DATE CREATED: 3 March 2013 Call this once when you start your program to init the Golay tables. @@ -192,7 +192,7 @@ void golay23_init(void) { * integer whose 23 least significant bits are coded bits: Of these, the * 12 most significant bits are information bits and the 11 least * significant bits are redundant bits (systematic encoding). - * --------------------------------------------------------------------- + * --------------------------------------------------------------------- */ for (pattern = 0; pattern < 4096; pattern++) { temp = pattern << 11; /* multiply information by X^{11} */ @@ -207,18 +207,18 @@ void golay23_init(void) { * is the most likely error pattern. First an error pattern is generated. * Then its syndrome is calculated and used as a pointer to the table * where the error pattern value is stored. - * --------------------------------------------------------------------- - * + * --------------------------------------------------------------------- + * * (1) Error patterns of WEIGHT 1 (SINGLE ERRORS) */ decoding_table[0] = 0; decoding_table[1] = 1; - temp = 1; + temp = 1; for (i=2; i<= 23; i++) { temp *= 2; decoding_table[get_syndrome(temp)] = temp; } - /* + /* * (2) Error patterns of WEIGHT 2 (DOUBLE ERRORS) */ a[1] = 1; a[2] = 2; @@ -229,7 +229,7 @@ void golay23_init(void) { temp = arr2int(a,2); decoding_table[get_syndrome(temp)] = temp; } - /* + /* * (3) Error patterns of WEIGHT 3 (TRIPLE ERRORS) */ a[1] = 1; a[2] = 2; a[3] = 3; @@ -245,9 +245,9 @@ void golay23_init(void) { } /*---------------------------------------------------------------------------*\ - - FUNCTION....: golay23_encode() - AUTHOR......: David Rowe + + FUNCTION....: golay23_encode() + AUTHOR......: David Rowe DATE CREATED: 3 March 2013 Given 12 bits of data retiurns a 23 bit codeword for transmission @@ -264,9 +264,9 @@ int golay23_encode(int data) { } /*---------------------------------------------------------------------------*\ - - FUNCTION....: golay23_decode() - AUTHOR......: David Rowe + + FUNCTION....: golay23_decode() + AUTHOR......: David Rowe DATE CREATED: 3 March 2013 Given a 23 bit received codeword, returns the 12 bit corrected data. @@ -305,7 +305,7 @@ static int golay23_test(int error_pattern) { int pattern; int decerror; int i, tests; - + decerror = 0; tests = 0; @@ -336,7 +336,7 @@ int main(void) int a[4]; int error_pattern; - golay23_init(); + golay23_init(); /* --------------------------------------------------------------------- * Generate DATA @@ -345,7 +345,7 @@ int main(void) /* Test all combinations of data and 1,2 or 3 errors */ - tests = 0; + tests = 0; error_pattern = 1; for (i=0; i< 23; i++) { //printf("error_pattern: 0x%x\n", error_pattern); @@ -394,7 +394,7 @@ int main(int argc, char *argv[]) { fprintf(f,"/* Generated by golay23.c -DGOLAY23_MAKETABLE */\n\n"); fprintf(f,"const int static encoding_table[]={\n"); - + for (i=0; i<4095; i++) fprintf(f," 0x%x,\n", encoding_table[i]); fprintf(f, " 0x%x\n};\n", encoding_table[i]); @@ -405,7 +405,7 @@ int main(int argc, char *argv[]) { fprintf(f,"/* Generated by golay23.c -DGOLAY23_MAKETABLE */\n\n"); fprintf(f,"const int static decoding_table[]={\n"); - + for (i=0; i<2047; i++) fprintf(f," 0x%x,\n", decoding_table[i]); fprintf(f, " 0x%x\n};\n", decoding_table[i]); diff --git a/codec2-dev/src/insert_errors.c b/codec2-dev/src/insert_errors.c index cbe83233..7567903c 100644 --- a/codec2-dev/src/insert_errors.c +++ b/codec2-dev/src/insert_errors.c @@ -78,9 +78,9 @@ int main(int argc, char *argv[]) start_bit = 0; end_bit = bits_per_frame; if (argc == 7) { start_bit = atoi(argv[5]); - end_bit = atoi(argv[6]); + end_bit = atoi(argv[6]); } - + bit = 0; bits = errors = 0; @@ -106,8 +106,8 @@ int main(int argc, char *argv[]) if (bits == bits_per_frame) bits = 0; if (fout == stdout) fflush(stdout); - if (fin == stdin) fflush(stdin); - + if (fin == stdin) fflush(stdin); + } fclose(fin); diff --git a/codec2-dev/src/interp.c b/codec2-dev/src/interp.c index 5862bc2e..8c56305f 100644 --- a/codec2-dev/src/interp.c +++ b/codec2-dev/src/interp.c @@ -39,10 +39,10 @@ float sample_log_amp(MODEL *model, float w); /*---------------------------------------------------------------------------*\ - FUNCTION....: interp() - AUTHOR......: David Rowe - DATE CREATED: 22/8/10 - + FUNCTION....: interp() + AUTHOR......: David Rowe + DATE CREATED: 22/8/10 + Given two frames decribed by model parameters 20ms apart, determines the model parameters of the 10ms frame between them. Assumes voicing is available for middle (interpolated) frame. Outputs are @@ -56,7 +56,7 @@ float sample_log_amp(MODEL *model, float w); When this function is used (--dec mode) bg noise appears to be amplitude modulated, and gets louder. The interp_lsp() function below seems to do a better job. - + \*---------------------------------------------------------------------------*/ void interpolate( @@ -95,13 +95,13 @@ void interpolate( /*---------------------------------------------------------------------------*\ FUNCTION....: sample_log_amp() - AUTHOR......: David Rowe - DATE CREATED: 22/8/10 - + AUTHOR......: David Rowe + DATE CREATED: 22/8/10 + Samples the amplitude envelope at an arbitrary frequency w. Uses linear interpolation in the log domain to sample between harmonic amplitudes. - + \*---------------------------------------------------------------------------*/ float sample_log_amp(MODEL *model, float w) @@ -122,7 +122,7 @@ float sample_log_amp(MODEL *model, float w) log_amp = (1.0-f)*log10f(model->A[model->L] + 1E-6); } else { - log_amp = (1.0-f)*log10f(model->A[m] + 1E-6) + + log_amp = (1.0-f)*log10f(model->A[m] + 1E-6) + f*log10f(model->A[m+1] + 1E-6); } @@ -133,10 +133,10 @@ float sample_log_amp(MODEL *model, float w) /*---------------------------------------------------------------------------*\ - FUNCTION....: interp_lsp() - AUTHOR......: David Rowe + FUNCTION....: interp_lsp() + AUTHOR......: David Rowe DATE CREATED: 10 Nov 2010 - + Given two frames decribed by model parameters 20ms apart, determines the model parameters of the 10ms frame between them. Assumes voicing is available for middle (interpolated) frame. Outputs are @@ -144,11 +144,11 @@ float sample_log_amp(MODEL *model, float w) This version uses interpolation of LSPs, seems to do a better job with bg noise. - + \*---------------------------------------------------------------------------*/ void interpolate_lsp( - kiss_fft_cfg fft_fwd_cfg, + kiss_fft_cfg fft_fwd_cfg, MODEL *interp, /* interpolated model params */ MODEL *prev, /* previous frames model params */ MODEL *next, /* next frames model params */ @@ -168,8 +168,8 @@ void interpolate_lsp( if (interp->voiced && !prev->voiced && !next->voiced) { interp->voiced = 0; - } - + } + /* Wo depends on voicing of this and adjacent frames */ if (interp->voiced) { @@ -203,21 +203,21 @@ void interpolate_lsp( /* convert back to amplitudes */ lsp_to_lpc(lsps_interp, ak_interp, LPC_ORD); - aks_to_M2(fft_fwd_cfg, ak_interp, LPC_ORD, interp, e, &snr, 0, 0, 1, 1, LPCPF_BETA, LPCPF_GAMMA); + aks_to_M2(fft_fwd_cfg, ak_interp, LPC_ORD, interp, e, &snr, 0, 0, 1, 1, LPCPF_BETA, LPCPF_GAMMA); //printf(" interp: ak[1]: %f A[1] %f\n", ak_interp[1], interp->A[1]); } #endif /*---------------------------------------------------------------------------*\ - FUNCTION....: interp_Wo() - AUTHOR......: David Rowe + FUNCTION....: interp_Wo() + AUTHOR......: David Rowe DATE CREATED: 22 May 2012 - + Interpolates centre 10ms sample of Wo and L samples given two samples 20ms apart. Assumes voicing is available for centre (interpolated) frame. - + \*---------------------------------------------------------------------------*/ void interp_Wo( @@ -231,12 +231,12 @@ void interp_Wo( /*---------------------------------------------------------------------------*\ - FUNCTION....: interp_Wo2() - AUTHOR......: David Rowe + FUNCTION....: interp_Wo2() + AUTHOR......: David Rowe DATE CREATED: 22 May 2012 - + Weighted interpolation of two Wo samples. - + \*---------------------------------------------------------------------------*/ void interp_Wo2( @@ -250,8 +250,8 @@ void interp_Wo2( if (interp->voiced && !prev->voiced && !next->voiced) { interp->voiced = 0; - } - + } + /* Wo depends on voicing of this and adjacent frames */ if (interp->voiced) { @@ -271,48 +271,48 @@ void interp_Wo2( /*---------------------------------------------------------------------------*\ - FUNCTION....: interp_energy() - AUTHOR......: David Rowe + FUNCTION....: interp_energy() + AUTHOR......: David Rowe DATE CREATED: 22 May 2012 - + Interpolates centre 10ms sample of energy given two samples 20ms apart. - + \*---------------------------------------------------------------------------*/ float interp_energy(float prev_e, float next_e) { return powf(10.0, (log10f(prev_e) + log10f(next_e))/2.0); - + } /*---------------------------------------------------------------------------*\ - FUNCTION....: interp_energy2() - AUTHOR......: David Rowe + FUNCTION....: interp_energy2() + AUTHOR......: David Rowe DATE CREATED: 22 May 2012 - + Interpolates centre 10ms sample of energy given two samples 20ms apart. - + \*---------------------------------------------------------------------------*/ float interp_energy2(float prev_e, float next_e, float weight) { return powf(10.0, (1.0 - weight)*log10f(prev_e) + weight*log10f(next_e)); - + } /*---------------------------------------------------------------------------*\ - FUNCTION....: interpolate_lsp_ver2() - AUTHOR......: David Rowe + FUNCTION....: interpolate_lsp_ver2() + AUTHOR......: David Rowe DATE CREATED: 22 May 2012 - + Weighted interpolation of LSPs. - + \*---------------------------------------------------------------------------*/ void interpolate_lsp_ver2(float interp[], float prev[], float next[], float weight, int order) diff --git a/codec2-dev/src/interp.h b/codec2-dev/src/interp.h index 688fb5a0..5d7f7093 100644 --- a/codec2-dev/src/interp.h +++ b/codec2-dev/src/interp.h @@ -32,7 +32,7 @@ void interpolate(MODEL *interp, MODEL *prev, MODEL *next); void interpolate_lsp(kiss_fft_cfg fft_dec_cfg, - MODEL *interp, MODEL *prev, MODEL *next, + MODEL *interp, MODEL *prev, MODEL *next, float *prev_lsps, float prev_e, float *next_lsps, float next_e, float *ak_interp, float *lsps_interp); diff --git a/codec2-dev/src/kiss_fft.c b/codec2-dev/src/kiss_fft.c index 3d1d4831..05f7f27a 100644 --- a/codec2-dev/src/kiss_fft.c +++ b/codec2-dev/src/kiss_fft.c @@ -250,7 +250,7 @@ void kf_work( const kiss_fft_cpx * Fout_end = Fout + p*m; #ifdef _OPENMP - // use openmp extensions at the + // use openmp extensions at the // top-level (not recursive) if (fstride==1 && p<=5) { @@ -258,15 +258,15 @@ void kf_work( // execute the p different work units in different threads # pragma omp parallel for - for (k=0;k +#include # if (FIXED_POINT == 32) # define kiss_fft_scalar int32_t -# else +# else # define kiss_fft_scalar int16_t # endif #else @@ -55,9 +55,9 @@ typedef struct { typedef struct kiss_fft_state* kiss_fft_cfg; -/* +/* * kiss_fft_alloc - * + * * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. * * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL); @@ -67,18 +67,18 @@ typedef struct kiss_fft_state* kiss_fft_cfg; * * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc. * The returned value should be free()d when done to avoid memory leaks. - * + * * The state can be placed in a user supplied buffer 'mem': * If lenmem is not NULL and mem is not NULL and *lenmem is large enough, * then the function places the cfg in mem and the size used in *lenmem * and returns mem. - * + * * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), - * then the function returns NULL and places the minimum cfg + * then the function returns NULL and places the minimum cfg * buffer size in *lenmem. * */ -kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); +kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); /* * kiss_fft(cfg,in_out_buf) @@ -97,16 +97,16 @@ void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); * */ void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride); -/* If kiss_fft_alloc allocated a buffer, it is one contiguous +/* If kiss_fft_alloc allocated a buffer, it is one contiguous buffer and can be simply free()d when no longer needed*/ #define kiss_fft_free free /* - Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up + Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up your compiler output to call this before you exit. */ void kiss_fft_cleanup(void); - + /* * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5) @@ -118,7 +118,7 @@ int kiss_fft_next_fast_size(int n); (kiss_fft_next_fast_size( ((n)+1)>>1)<<1) #ifdef __cplusplus -} +} #endif #endif diff --git a/codec2-dev/src/linreg.c b/codec2-dev/src/linreg.c index e91a69c8..f37634d5 100644 --- a/codec2-dev/src/linreg.c +++ b/codec2-dev/src/linreg.c @@ -53,12 +53,12 @@ void linreg(COMP *m, COMP *b, float x[], COMP y[], int n) COMP zero; int i; - for (i=0; ifft_cfg != NULL); } -void modem_stats_close(struct MODEM_STATS *f) +void modem_stats_close(struct MODEM_STATS *f) { KISS_FFT_FREE(f->fft_cfg); } /*---------------------------------------------------------------------------*\ - - FUNCTION....: modem_stats_get_rx_spectrum() - AUTHOR......: David Rowe + + FUNCTION....: modem_stats_get_rx_spectrum() + AUTHOR......: David Rowe DATE CREATED: 9 June 2012 Returns the MODEM_STATS_NSPEC point magnitude spectrum of the rx signal in @@ -74,7 +74,7 @@ void modem_stats_close(struct MODEM_STATS *f) \*---------------------------------------------------------------------------*/ -void modem_stats_get_rx_spectrum(struct MODEM_STATS *f, float mag_spec_dB[], COMP rx_fdm[], int nin) +void modem_stats_get_rx_spectrum(struct MODEM_STATS *f, float mag_spec_dB[], COMP rx_fdm[], int nin) { int i,j; COMP fft_in[2*MODEM_STATS_NSPEC]; diff --git a/codec2-dev/src/modem_stats.h b/codec2-dev/src/modem_stats.h index 99dc637a..58e5a768 100644 --- a/codec2-dev/src/modem_stats.h +++ b/codec2-dev/src/modem_stats.h @@ -1,9 +1,9 @@ /*---------------------------------------------------------------------------*\ - + FILE........: modem_stats.h AUTHOR......: David Rowe DATE CREATED: June 2015 - + Common structure for returning demod stats from fdmdv and cohpsk modems. \*---------------------------------------------------------------------------*/ @@ -43,22 +43,22 @@ struct MODEM_STATS { int Nc; float snr_est; /* estimated SNR of rx signal in dB (3 kHz noise BW) */ - COMP rx_symbols[MODEM_STATS_NR_MAX][MODEM_STATS_NC_MAX+1]; - /* latest received symbols, for scatter plot */ + COMP rx_symbols[MODEM_STATS_NR_MAX][MODEM_STATS_NC_MAX+1]; + /* latest received symbols, for scatter plot */ int nr; /* number of rows in rx_symbols */ - int sync; /* demod sync state */ - float foff; /* estimated freq offset in Hz */ + int sync; /* demod sync state */ + float foff; /* estimated freq offset in Hz */ float rx_timing; /* estimated optimum timing offset in samples */ float clock_offset; /* Estimated tx/rx sample clock offset in ppm */ /* Buf for FFT/waterfall */ float fft_buf[2*MODEM_STATS_NSPEC]; - kiss_fft_cfg fft_cfg; + kiss_fft_cfg fft_cfg; }; void modem_stats_open(struct MODEM_STATS *f); -void modem_stats_close(struct MODEM_STATS *f); +void modem_stats_close(struct MODEM_STATS *f); void modem_stats_get_rx_spectrum(struct MODEM_STATS *f, float mag_spec_dB[], COMP rx_fdm[], int nin); #endif diff --git a/codec2-dev/src/nlp.c b/codec2-dev/src/nlp.c index 4ff11c14..d3155367 100644 --- a/codec2-dev/src/nlp.c +++ b/codec2-dev/src/nlp.c @@ -1,9 +1,9 @@ /*---------------------------------------------------------------------------*\ - - FILE........: nlp.c - AUTHOR......: David Rowe - DATE CREATED: 23/3/93 - + + FILE........: nlp.c + AUTHOR......: David Rowe + DATE CREATED: 23/3/93 + Non Linear Pitch (NLP) estimation functions. \*---------------------------------------------------------------------------*/ @@ -37,9 +37,9 @@ #include /*---------------------------------------------------------------------------*\ - - DEFINES - + + DEFINES + \*---------------------------------------------------------------------------*/ #define PMAX_M 600 /* maximum NLP analysis window size */ @@ -56,9 +56,9 @@ //#undef DUMP /*---------------------------------------------------------------------------*\ - - GLOBALS - + + GLOBALS + \*---------------------------------------------------------------------------*/ /* 48 tap 600Hz low pass FIR filter coefficients */ @@ -116,7 +116,7 @@ const float nlp_fir[] = { typedef struct { int m; - float w[PMAX_M/DEC]; /* DFT window */ + float w[PMAX_M/DEC]; /* DFT window */ float sq[PMAX_M]; /* squared speech samples */ float mem_x,mem_y; /* memory for notch filter */ float mem_fir[NLP_NTAP]; /* decimation FIR filter memory */ @@ -125,14 +125,14 @@ typedef struct { float test_candidate_mbe(COMP Sw[], COMP W[], float f0); float post_process_mbe(COMP Fw[], int pmin, int pmax, float gmax, COMP Sw[], COMP W[], float *prev_Wo); -float post_process_sub_multiples(COMP Fw[], +float post_process_sub_multiples(COMP Fw[], int pmin, int pmax, float gmax, int gmax_bin, float *prev_Wo); /*---------------------------------------------------------------------------*\ - - nlp_create() - + + nlp_create() + Initialisation function for NLP pitch estimator. \*---------------------------------------------------------------------------*/ @@ -169,9 +169,9 @@ int m /* analysis window size */ } /*---------------------------------------------------------------------------*\ - + nlp_destroy() - + Shut down function for NLP pitch estimator. \*---------------------------------------------------------------------------*/ @@ -187,9 +187,9 @@ void nlp_destroy(void *nlp_state) } /*---------------------------------------------------------------------------*\ - - nlp() - + + nlp() + Determines the pitch in samples using the Non Linear Pitch (NLP) algorithm [1]. Returns the fundamental in Hz. Note that the actual pitch estimate is for the centre of the M sample Sn[] vector, not @@ -213,11 +213,11 @@ void nlp_destroy(void *nlp_state) References: [1] http://www.itr.unisa.edu.au/~steven/thesis/dgr.pdf Chapter 4 - + \*---------------------------------------------------------------------------*/ float nlp( - void *nlp_state, + void *nlp_state, float Sn[], /* input speech vector */ int n, /* frames shift (no. new samples in Sn[]) */ int pmin, /* minimum pitch value */ @@ -237,7 +237,7 @@ float nlp( int m, i,j; float best_f0; PROFILE_VAR(start, tnotch, filter, peakpick, window, fft, magsq, shiftmem); - + assert(nlp_state != NULL); nlp = (NLP*)nlp_state; m = nlp->m; @@ -278,7 +278,7 @@ float nlp( } PROFILE_SAMPLE_AND_LOG(filter, tnotch, " filter"); - + /* Decimate and DFT */ for(i=0; i= min_bin) { b = gmax_bin/mult; /* determine search interval */ @@ -418,11 +418,11 @@ float post_process_sub_multiples(COMP Fw[], return best_f0; } - + /*---------------------------------------------------------------------------*\ - - post_process_mbe() - + + post_process_mbe() + Use the MBE pitch estimation algorithm to evaluate pitch candidates. This works OK but the accuracy at low F0 is affected by NW, the analysis window size used for the DFT of the input speech Sw[]. Also favours high F0 in @@ -522,14 +522,14 @@ float post_process_mbe(COMP Fw[], int pmin, int pmax, float gmax, COMP Sw[], COM } /*---------------------------------------------------------------------------*\ - - test_candidate_mbe() - - Returns the error of the MBE cost function for the input f0. + + test_candidate_mbe() + + Returns the error of the MBE cost function for the input f0. Note: I think a lot of the operations below can be simplified as W[].imag = 0 and has been normalised such that den always equals 1. - + \*---------------------------------------------------------------------------*/ float test_candidate_mbe( @@ -546,7 +546,7 @@ float test_candidate_mbe( float error; /* accumulated error between originl and synthesised */ float Wo; /* current "test" fundamental freq. */ int L; - + L = floorf((SAMPLE_RATE/2.0)/f0); Wo = f0*(2*PI/SAMPLE_RATE); diff --git a/codec2-dev/src/nlp.h b/codec2-dev/src/nlp.h index 2d2dada1..6e03236c 100644 --- a/codec2-dev/src/nlp.h +++ b/codec2-dev/src/nlp.h @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - - FILE........: nlp.c - AUTHOR......: David Rowe - DATE CREATED: 23/3/93 - - Non Linear Pitch (NLP) estimation functions. - + + FILE........: nlp.c + AUTHOR......: David Rowe + DATE CREATED: 23/3/93 + + Non Linear Pitch (NLP) estimation functions. + \*---------------------------------------------------------------------------*/ /* @@ -32,7 +32,7 @@ void *nlp_create(int m); void nlp_destroy(void *nlp_state); -float nlp(void *nlp_state, float Sn[], int n, int pmin, int pmax, +float nlp(void *nlp_state, float Sn[], int n, int pmin, int pmax, float *pitch, COMP Sw[], COMP W[], float *prev_Wo); #endif diff --git a/codec2-dev/src/octave.c b/codec2-dev/src/octave.c index 2ff5ad14..e73ae1d1 100644 --- a/codec2-dev/src/octave.c +++ b/codec2-dev/src/octave.c @@ -1,9 +1,9 @@ /*---------------------------------------------------------------------------*\ - + FILE........: octave.c - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: April 28 2012 - + Functions to save C arrays in GNU Octave matrix format. The output text file can be directly read into Octave using "load filename". @@ -38,7 +38,7 @@ void octave_save_int(FILE *f, char name[], int data[], int rows, int cols) fprintf(f, "# type: matrix\n"); fprintf(f, "# rows: %d\n", rows); fprintf(f, "# columns: %d\n", cols); - + for(r=0; r> (fieldWidth - sliceWidth)) << (bitsLeft - sliceWidth))); - + *bitIndex = bI + sliceWidth; fieldWidth -= sliceWidth; } while ( fieldWidth != 0 ); @@ -120,7 +120,7 @@ unpack_natural_or_gray( bitsLeft < fieldWidth ? bitsLeft : fieldWidth; field |= (((bitArray[bI >> ShiftRight] >> (bitsLeft - sliceWidth)) & ((1 << sliceWidth) - 1)) << (fieldWidth - sliceWidth)); - + *bitIndex = bI + sliceWidth; fieldWidth -= sliceWidth; } while ( fieldWidth != 0 ); diff --git a/codec2-dev/src/phase.c b/codec2-dev/src/phase.c index 08a2cf41..dcdf6b66 100644 --- a/codec2-dev/src/phase.c +++ b/codec2-dev/src/phase.c @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - - FILE........: phase.c - AUTHOR......: David Rowe - DATE CREATED: 1/2/09 - + + FILE........: phase.c + AUTHOR......: David Rowe + DATE CREATED: 1/2/09 + Functions for modelling and synthesising phase. - + \*---------------------------------------------------------------------------*/ /* @@ -22,7 +22,7 @@ License for more details. You should have received a copy of the GNU Lesser General Public License - along with this program; if not,see . + along with this program; if not,see . */ #include "defines.h" @@ -42,14 +42,14 @@ phase_synth_zero_order() - Synthesises phases based on SNR and a rule based approach. No phase + Synthesises phases based on SNR and a rule based approach. No phase parameters are required apart from the SNR (which can be reduced to a 1 bit V/UV decision per frame). The phase of each harmonic is modelled as the phase of a LPC synthesis filter excited by an impulse. Unlike the first order model the position of the impulse is not transmitted, so we create - an excitation pulse train using a rule based approach. + an excitation pulse train using a rule based approach. Consider a pulse train with a pulse starting time n=0, with pulses repeated at a rate of Wo, the fundamental frequency. A pulse train @@ -90,10 +90,10 @@ This E[m] then gets passed through the LPC synthesis filter to determine the final harmonic phase. - + Comparing to speech synthesised using original phases: - - Through headphones speech synthesised with this model is not as + - Through headphones speech synthesised with this model is not as good. Through a loudspeaker it is very close to original phases. - If there are voicing errors, the speech can sound clicky or @@ -129,7 +129,7 @@ \*---------------------------------------------------------------------------*/ void phase_synth_zero_order( - kiss_fft_cfg fft_fwd_cfg, + kiss_fft_cfg fft_fwd_cfg, MODEL *model, float *ex_phase, /* excitation phase of fundamental */ COMP A[] @@ -152,22 +152,22 @@ void phase_synth_zero_order( H[m].imag = sinf(phi_); } - /* + /* Update excitation fundamental phase track, this sets the position of each pitch pulse during voiced speech. After much experiment I found that using just this frame's Wo improved quality for UV sounds compared to interpolating two frames Wo like this: - + ex_phase[0] += (*prev_Wo+model->Wo)*N/2; */ - + ex_phase[0] += (model->Wo)*N; ex_phase[0] -= TWO_PI*floorf(ex_phase[0]/TWO_PI + 0.5); for(m=1; m<=model->L; m++) { - + /* generate excitation */ - + if (model->voiced) { Ex[m].real = cosf(ex_phase[0]*m); @@ -190,7 +190,7 @@ void phase_synth_zero_order( A_[m].imag = H[m].imag*Ex[m].real + H[m].real*Ex[m].imag; /* modify sinusoidal phase */ - + new_phi = atan2f(A_[m].imag, A_[m].real+1E-12); model->phi[m] = new_phi; } diff --git a/codec2-dev/src/phase.h b/codec2-dev/src/phase.h index 03e1c507..174582a6 100644 --- a/codec2-dev/src/phase.h +++ b/codec2-dev/src/phase.h @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - - FILE........: phase.h - AUTHOR......: David Rowe - DATE CREATED: 1/2/09 - + + FILE........: phase.h + AUTHOR......: David Rowe + DATE CREATED: 1/2/09 + Functions for modelling phase. - + \*---------------------------------------------------------------------------*/ /* @@ -31,8 +31,8 @@ #include "kiss_fft.h" #include "comp.h" -void phase_synth_zero_order(kiss_fft_cfg fft_dec_cfg, - MODEL *model, +void phase_synth_zero_order(kiss_fft_cfg fft_dec_cfg, + MODEL *model, float *ex_phase, COMP A[]); diff --git a/codec2-dev/src/phaseexp.c b/codec2-dev/src/phaseexp.c index be2ad9be..61b240df 100644 --- a/codec2-dev/src/phaseexp.c +++ b/codec2-dev/src/phaseexp.c @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - - FILE........: phaseexp.c - AUTHOR......: David Rowe - DATE CREATED: June 2012 - + + FILE........: phaseexp.c + AUTHOR......: David Rowe + DATE CREATED: June 2012 + Experimental functions for quantising, modelling and synthesising phase. - + \*---------------------------------------------------------------------------*/ /* @@ -22,7 +22,7 @@ License for more details. You should have received a copy of the GNU Lesser General Public License - along with this program; if not,see . + along with this program; if not,see . */ #include "defines.h" @@ -43,7 +43,7 @@ struct codebook { unsigned int log2m; unsigned int m; COMP *cb; - unsigned int offset; + unsigned int offset; }; static const char format[] = @@ -59,7 +59,7 @@ float get_float(FILE * in, const char * name, char * * cursor, char * buffer, in while ( (c = *s) != '\0' && !isdigit(c) && c != '-' && c != '.' ) s++; - + /* Comments start with "#" and continue to the end of the line. */ if ( c != '\0' && c != '#' ) { char * end = 0; @@ -123,7 +123,7 @@ struct PEXP { float snr; float var; int var_n; - struct codebook *vq1,*vq2,*vq3,*vq4,*vq5; + struct codebook *vq1,*vq2,*vq3,*vq4,*vq5; float vq_var; int vq_var_n; MODEL prev_model; @@ -154,7 +154,7 @@ struct PEXP * phase_experiment_create() { pexp->snr = 0.0; pexp->var = 0.0; pexp->var_n = 0; - + /* smoothed 10th order for 1st 1 khz */ //pexp->vq1 = load("../unittest/ph1_10_1024.txt"); //pexp->vq1->offset = 0; @@ -194,10 +194,10 @@ void phase_experiment_destroy(struct PEXP *pexp) { if (pexp->snr != 0.0) printf("snr: %4.2f dB\n", pexp->snr/pexp->frames); if (pexp->var != 0.0) - printf("var...: %4.3f std dev...: %4.3f (%d non zero phases)\n", + printf("var...: %4.3f std dev...: %4.3f (%d non zero phases)\n", pexp->var/pexp->var_n, sqrt(pexp->var/pexp->var_n), pexp->var_n); if (pexp->vq_var != 0.0) - printf("vq var: %4.3f vq std dev: %4.3f (%d non zero phases)\n", + printf("vq var: %4.3f vq std dev: %4.3f (%d non zero phases)\n", pexp->vq_var/pexp->vq_var_n, sqrt(pexp->vq_var/pexp->vq_var_n), pexp->vq_var_n); free(pexp); } @@ -220,7 +220,7 @@ static void bubbleSort(struct AMPINDEX numbers[], int array_size) { int i, j; struct AMPINDEX temp; - + for (i = (array_size - 1); i > 0; i--) { for (j = 1; j <= i; j++) @@ -245,17 +245,17 @@ static void print_pred_error(struct PEXP *pexp, MODEL *model, int start, int end for(i=start; i<=end; i++) mag += model->A[i]*model->A[i]; mag = 10*log10(mag/(end-start)); - + if (mag > mag_thresh) { for(i=start; i<=end; i++) { float pred = pexp->phi_prev[i] + N*i*(model->Wo + pexp->Wo_prev)/2.0; float err = pred - model->phi[i]; err = atan2(sin(err),cos(err)); - printf("%f\n",err); + printf("%f\n",err); } //printf("\n"); } - + } @@ -265,11 +265,11 @@ static void predict_phases(struct PEXP *pexp, MODEL *model, int start, int end) for(i=start; i<=end; i++) { model->phi[i] = pexp->phi_prev[i] + N*i*model->Wo; } - + } -static float refine_Wo(struct PEXP *pexp, - MODEL *model, - int start, +static float refine_Wo(struct PEXP *pexp, + MODEL *model, + int start, int end); /* Fancy state based phase prediction. Actually works OK on most utterances, @@ -296,7 +296,7 @@ static void predict_phases_state(struct PEXP *pexp, MODEL *model, int start, int for(i=start; i<=end; i++) pexp->phi_prev[i] = i*pexp->phi1; } - + break; case 1: if (dWo > 0.1) @@ -321,7 +321,7 @@ static void struct_phases(struct PEXP *pexp, MODEL *model, int start, int end) { for(i=start; i<=end; i++) model->phi[i] = pexp->phi1*i; - + } @@ -340,7 +340,7 @@ static void predict_phases2(struct PEXP *pexp, MODEL *model, int start, int end) pred -= PI/16; model->phi[i] = pred; } - + } static void rand_phases(MODEL *model, int start, int end) { @@ -348,11 +348,11 @@ static void rand_phases(MODEL *model, int start, int end) { for(i=start; i<=end; i++) model->phi[i] = PI*(1.0 - 2.0*(float)rand()/RAND_MAX); - + } static void quant_phase(float *phase, float min, float max, int bits) { - int levels = 1 << bits; + int levels = 1 << bits; int index; float norm, step; @@ -388,7 +388,7 @@ static void fixed_bits_per_frame(struct PEXP *pexp, MODEL *model, int m, int bud if (((budget - res) < 0) || (m > model->L)) finished = 1; else { - quant_phase(&model->phi[m], -PI, PI, res); + quant_phase(&model->phi[m], -PI, PI, res); budget -= res; m++; } @@ -425,7 +425,7 @@ static float est_phi1(MODEL *model, int start, int end) int m; float delta, s, c, phi1_est; - if (end > model->L) + if (end > model->L) end = model->L; s = c = 0.0; @@ -436,7 +436,7 @@ static float est_phi1(MODEL *model, int start, int end) } phi1_est = atan2(s,c); - + return phi1_est; } @@ -509,7 +509,7 @@ static void top_amp(struct PEXP *pexp, MODEL *model, int start, int end, int n_h /* keep phase of top n_harm, predict others */ - for(i=start; iA[i] == sorted[j].amp) { @@ -517,7 +517,7 @@ static void top_amp(struct PEXP *pexp, MODEL *model, int start, int end, int n_h assert(i == sorted[j].index); } } - + #define ALTTOP #ifdef ALTTOP model->phi[i] = 0.0; /* make sure */ @@ -542,27 +542,27 @@ static void top_amp(struct PEXP *pexp, MODEL *model, int start, int end, int n_h } else { /* need to make this work thru budget of bits */ - quant_phase(&model->phi[i], -PI, PI, 3); + quant_phase(&model->phi[i], -PI, PI, 3); not_removed++; } #endif } printf("dim: %d rem %d not_rem %d\n", end-start, removed, not_removed); - + } - -static void limit_prediction_error(struct PEXP *pexp, MODEL *model, int start, int end, float limit) + +static void limit_prediction_error(struct PEXP *pexp, MODEL *model, int start, int end, float limit) { int i; float pred, pred_error, error; for(i=start; i<=end; i++) { pred = pexp->phi_prev[i] + N*i*(model->Wo + pexp->Wo_prev)/2.0; - pred_error = pred - model->phi[i]; + pred_error = pred - model->phi[i]; pred_error -= TWO_PI*floor((pred_error+PI)/TWO_PI); - quant_phase(&pred_error, -limit, limit, 2); - + quant_phase(&pred_error, -limit, limit, 2); + error = pred - pred_error - model->phi[i]; error -= TWO_PI*floor((error+PI)/TWO_PI); printf("%f\n", pred_error); @@ -571,16 +571,16 @@ static void limit_prediction_error(struct PEXP *pexp, MODEL *model, int start, i } -static void quant_prediction_error(struct PEXP *pexp, MODEL *model, int start, int end, float limit) +static void quant_prediction_error(struct PEXP *pexp, MODEL *model, int start, int end, float limit) { int i; float pred, pred_error; for(i=start; i<=end; i++) { pred = pexp->phi_prev[i] + N*i*(model->Wo + pexp->Wo_prev)/2.0; - pred_error = pred - model->phi[i]; + pred_error = pred - model->phi[i]; pred_error -= TWO_PI*floor((pred_error+PI)/TWO_PI); - + printf("%f\n", pred_error); model->phi[i] = pred - pred_error; } @@ -597,7 +597,7 @@ static void print_sparse_pred_error(struct PEXP *pexp, MODEL *model, int start, for(i=start; i<=end; i++) mag += model->A[i]*model->A[i]; mag = 10*log10(mag/(end-start)); - + if (mag > mag_thresh) { for(i=0; iL; m++) { + for(m=1; m<=model->L; m++) { signal += model->A[m]*model->A[m]; - diff = cos(model->phi[m]) - cos(before[m]); + diff = cos(model->phi[m]) - cos(before[m]); noise += pow(model->A[m]*diff, 2.0); - diff = sin(model->phi[m]) - sin(before[m]); + diff = sin(model->phi[m]) - sin(before[m]); noise += pow(model->A[m]*diff, 2.0); //printf("%f %f\n", before[m], model->phi[m]); } @@ -646,7 +646,7 @@ static void update_variance_calc(struct PEXP *pexp, MODEL *model, float before[] int m; float diff; - for(m=1; mL; m++) { + for(m=1; mL; m++) { diff = model->phi[m] - before[m]; diff = atan2(sin(diff), cos(diff)); pexp->var += diff*diff; @@ -659,7 +659,7 @@ void print_vec(COMP cb[], int d, int e) int i,j; for(j=0; joffset, vq->k, vq->m); vq_ind = vq_phase(vq->cb, &sparse_pe_in[vq->offset], &weights[vq->offset], vq->k, vq->m, &pexp->vq_var); - + non_zero = 0; for(i=0, j=vq->offset; ik; i++,j++) { //printf("%f ", atan2(sparse_pe[i].imag, sparse_pe[i].real)); @@ -792,8 +792,8 @@ static void split_vq(COMP sparse_pe_out[], struct PEXP *pexp, struct codebook *v } -static void sparse_vq_pred_error(struct PEXP *pexp, - MODEL *model +static void sparse_vq_pred_error(struct PEXP *pexp, + MODEL *model ) { int i, index; @@ -827,15 +827,15 @@ static void sparse_vq_pred_error(struct PEXP *pexp, weights[index] = model->A[i]; //printf("%d ", index); } - + /* vector quantise */ - + split_vq(sparse_pe_out, pexp, pexp->vq1, weights, sparse_pe_in); split_vq(sparse_pe_out, pexp, pexp->vq2, weights, sparse_pe_in); split_vq(sparse_pe_out, pexp, pexp->vq3, weights, sparse_pe_in); split_vq(sparse_pe_out, pexp, pexp->vq4, weights, sparse_pe_in); split_vq(sparse_pe_out, pexp, pexp->vq5, weights, sparse_pe_in); - + /* transform quantised phases back */ for(i=1; i<=model->L; i++) { @@ -856,7 +856,7 @@ static void predict_phases1(struct PEXP *pexp, MODEL *model, int start, int end) float best_Wo; best_Wo = refine_Wo(pexp, model, 1, model->L); - + for(i=start; i<=end; i++) { model->phi[i] = pexp->phi_prev[i] + N*i*best_Wo; } @@ -954,7 +954,7 @@ void smooth_phase(struct PEXP *pexp, MODEL *model, int mode) printf("\n"); /* convert back to Am */ - + for(m=1; m<=model->L; m++) { index = MAX_AMP*m*model->Wo/PI; assert(index < MAX_AMP); @@ -962,7 +962,7 @@ void smooth_phase(struct PEXP *pexp, MODEL *model, int mode) err = atan2(sparse_pe_out[index].imag, sparse_pe_out[index].real); model->phi[m] = pred + err; } - + } /* @@ -999,10 +999,10 @@ void smooth_phase2(struct PEXP *pexp, MODEL *model) { phi1_ = atan2(s,c); for(i=a; iphi_prev[i] + N*i*best_Wo; - printf("%d: %4.3f -> ", i, model->phi[i]); + printf("%d: %4.3f -> ", i, model->phi[i]); model->phi[i] = pred + phi1_; model->phi[i] = atan2(sin(model->phi[i]),cos(model->phi[i])); - printf("%4.3f ", model->phi[i]); + printf("%4.3f ", model->phi[i]); } } } @@ -1013,7 +1013,7 @@ void smooth_phase2(struct PEXP *pexp, MODEL *model) { //static float bins[] = {2600.0, 2800.0, 3000.0, 3200.0, 3400.0, 3600.0, 3800.0, 4000.0}; static float bins[] = {/* - 1000.0, 1100.0, 1200.0, 1300.0, 1400.0, + 1000.0, 1100.0, 1200.0, 1300.0, 1400.0, 1500.0, 1600.0, 1700.0, 1800.0, 1900.0,*/ 2000.0, 2400.0, 2800.0, @@ -1051,11 +1051,11 @@ void smooth_phase3(struct PEXP *pexp, MODEL *model) { /* est predicted phase from average */ - pred = pexp->phi_prev[m] + N*m*best_Wo; + pred = pexp->phi_prev[m] + N*m*best_Wo; err = model->phi[m] - pred; av[b].real += cos(err); av[b].imag += sin(err); } - + } /* use averages to est phases */ @@ -1077,17 +1077,17 @@ void smooth_phase3(struct PEXP *pexp, MODEL *model) { pred = pexp->phi_prev[m] + N*m*best_Wo; err = atan2(av[b].imag, av[b].real); - printf(" %d: %4.3f -> ", m, model->phi[m]); + printf(" %d: %4.3f -> ", m, model->phi[m]); model->phi[m] = pred + err; model->phi[m] = atan2(sin(model->phi[m]),cos(model->phi[m])); - printf("%4.3f\n", model->phi[m]); + printf("%4.3f\n", model->phi[m]); } } printf("\n"); } -/* +/* Try to code the phase of the largest amplitude in each band. Randomise the phase of the other harmonics. The theory is that only the largest harmonic will be audible. @@ -1125,7 +1125,7 @@ void cb_phase1(struct PEXP *pexp, MODEL *model) { max_ind[b] = m; } } - + } /* randomise phase of other harmonics */ @@ -1148,7 +1148,7 @@ void cb_phase1(struct PEXP *pexp, MODEL *model) { } -/* +/* Theory is only the phase of the envelope of signal matters within a Critical Band. So we estimate the position of an impulse that approximates the envelope of the signal. @@ -1173,12 +1173,12 @@ void cb_phase2(struct PEXP *pexp, MODEL *model) { a = m; b=a+step; if (b > model->L) b = model->L; - + c = s = 0; for(i=a; iphi[i+1] - model->phi[i]; - //w = (model->A[i+1] + model->A[i])/2; + //w = (model->A[i+1] + model->A[i])/2; w = 1.0; c += w*cos(diff); s += w*sin(diff); } @@ -1242,7 +1242,7 @@ void phase_experiment(struct PEXP *pexp, MODEL *model, char *arg) { assert(pexp != NULL); memcpy(before, &model->phi[0], sizeof(float)*MAX_AMP); - if (strcmp(arg,"q3") == 0) { + if (strcmp(arg,"q3") == 0) { quant_phases(model, 1, model->L, 3); update_snr_calc(pexp, model, before); update_variance_calc(pexp, model, before); @@ -1250,7 +1250,7 @@ void phase_experiment(struct PEXP *pexp, MODEL *model, char *arg) { if (strcmp(arg,"dec2") == 0) { if ((pexp->frames % 2) != 0) { - predict_phases(pexp, model, 1, model->L); + predict_phases(pexp, model, 1, model->L); update_snr_calc(pexp, model, before); update_variance_calc(pexp, model, before); } @@ -1258,7 +1258,7 @@ void phase_experiment(struct PEXP *pexp, MODEL *model, char *arg) { if (strcmp(arg,"repeat") == 0) { if ((pexp->frames % 2) != 0) { - repeat_phases(pexp, model); + repeat_phases(pexp, model); update_snr_calc(pexp, model, before); update_variance_calc(pexp, model, before); } @@ -1270,28 +1270,28 @@ void phase_experiment(struct PEXP *pexp, MODEL *model, char *arg) { update_variance_calc(pexp, model, before); } - if (strcmp(arg,"pred") == 0) + if (strcmp(arg,"pred") == 0) predict_phases_state(pexp, model, 1, model->L); - if (strcmp(arg,"pred1k") == 0) + if (strcmp(arg,"pred1k") == 0) predict_phases(pexp, model, 1, model->L/4); if (strcmp(arg,"smooth") == 0) { smooth_phase(pexp, model,0); update_snr_calc(pexp, model, before); } - if (strcmp(arg,"smoothtrain") == 0) + if (strcmp(arg,"smoothtrain") == 0) smooth_phase(pexp, model,1); if (strcmp(arg,"smoothvq") == 0) { smooth_phase(pexp, model,2); update_snr_calc(pexp, model, before); } - if (strcmp(arg,"smooth2") == 0) + if (strcmp(arg,"smooth2") == 0) smooth_phase2(pexp, model); - if (strcmp(arg,"smooth3") == 0) + if (strcmp(arg,"smooth3") == 0) smooth_phase3(pexp, model); - if (strcmp(arg,"smooth4") == 0) + if (strcmp(arg,"smooth4") == 0) smooth_phase4(model); if (strcmp(arg,"vqsmooth3") == 0) { sparse_vq_pred_error(pexp, model); @@ -1348,9 +1348,9 @@ void phase_experiment(struct PEXP *pexp, MODEL *model, char *arg) { //best_Wo = refine_Wo(pexp, model, model->L/2, model->L); pexp->phi1 += N*model->Wo; - + for(m=1; m<=model->L; m++) - pexp->phi_prev[m] = model->phi[m]; + pexp->phi_prev[m] = model->phi[m]; pexp->Wo_prev = model->Wo; pexp->frames++; pexp->prev_model = *model; @@ -1362,7 +1362,7 @@ void phase_experiment(struct PEXP *pexp, MODEL *model, char *arg) { //print_sparse_pred_error(pexp, model, 1, model->L, 40.0); //sparse_vq_pred_error(pexp, model); - + //quant_phases(model, model->L/4+1, model->L, 3); //predict_phases1(pexp, model, 1, model->L/4); @@ -1372,7 +1372,7 @@ void phase_experiment(struct PEXP *pexp, MODEL *model, char *arg) { //update_snr_calc(pexp, model, before); //update_variance_calc(pexp, model, before); - + //fixed_bits_per_frame(pexp, model, 40); //struct_phases(pexp, model, 1, model->L/4); //rand_phases(model, 10, model->L); @@ -1390,25 +1390,25 @@ void phase_experiment(struct PEXP *pexp, MODEL *model, char *arg) { //first_order_band(model, model->L/4, model->L/2); //first_order_band(model, model->L/2, 3*model->L/4); //if (fabs(model->Wo - pexp->Wo_prev)< 0.1*model->Wo) - + //print_pred_error(pexp, model, 1, model->L, 40.0); //print_sparse_pred_error(pexp, model, 1, model->L, 40.0); //phi1_est = est_phi1(model, 1, model->L/4); //print_phi1_pred_error(model, 1, model->L/4); - //first_order_band(model, 1, model->L/4, phi1_est); + //first_order_band(model, 1, model->L/4, phi1_est); //sub_linear(model, 1, model->L/4, phi1_est); //top_amp(pexp, model, 1, model->L/4, 4); //top_amp(pexp, model, model->L/4, model->L/2, 4); - //first_order_band(model, 1, model->L/4, phi1_est); - //first_order_band(model, model->L/4, model->L/2, phi1_est); + //first_order_band(model, 1, model->L/4, phi1_est); + //first_order_band(model, model->L/4, model->L/2, phi1_est); //if (fabs(model->Wo - pexp->Wo_prev) > 0.2*model->Wo) // rand_phases(model, model->L/2, model->L); - + //top_amp(pexp, model, 1, model->L/4, 4); //top_amp(pexp, model, model->L/4, model->L/2, 8); //top_amp(pexp, model, model->L/4+1, model->L/2, 10, 1); @@ -1425,7 +1425,7 @@ void phase_experiment(struct PEXP *pexp, MODEL *model, char *arg) { #ifdef REAS_CAND2 if ((pexp->frames % 2) == 0) { //printf("quant\n"); - predict_phases(pexp, model, 1, model->L/4); + predict_phases(pexp, model, 1, model->L/4); //top_amp(pexp, model, model->L/4+1, 3*model->L/4, 20, 1); top_amp(pexp, model, model->L/4+1, 7*model->L/8, 20, 1); rand_phases(model, 7*model->L/8+1, model->L); @@ -1440,16 +1440,16 @@ void phase_experiment(struct PEXP *pexp, MODEL *model, char *arg) { #ifdef REAS_CAND3 if ((pexp->frames % 3) != 0) { printf("pred\n"); - predict_phases(pexp, model, 1, model->L); + predict_phases(pexp, model, 1, model->L); } else { - predict_phases(pexp, model, 1, model->L/4); + predict_phases(pexp, model, 1, model->L/4); fixed_bits_per_frame(pexp, model, model->L/4+1, 60); } #endif - //predict_phases(pexp, model, model->L/4, model->L); + //predict_phases(pexp, model, model->L/4, model->L); + - //print_pred_error(pexp, model, 1, model->L); //limit_prediction_error(pexp, model, model->L/2, model->L, PI/2); #endif diff --git a/codec2-dev/src/phaseexp.h b/codec2-dev/src/phaseexp.h index b43db75e..865e8aed 100644 --- a/codec2-dev/src/phaseexp.h +++ b/codec2-dev/src/phaseexp.h @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - - FILE........: phaseexp.h - AUTHOR......: David Rowe - DATE CREATED: June 2012 - + + FILE........: phaseexp.h + AUTHOR......: David Rowe + DATE CREATED: June 2012 + Experimental functions for quantising, modelling and synthesising phase. - + \*---------------------------------------------------------------------------*/ /* diff --git a/codec2-dev/src/postfilter.c b/codec2-dev/src/postfilter.c index fc88c0ea..7c1a6061 100644 --- a/codec2-dev/src/postfilter.c +++ b/codec2-dev/src/postfilter.c @@ -1,13 +1,13 @@ /*---------------------------------------------------------------------------*\ - + FILE........: postfilter.c - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: 13/09/09 - + Postfilter to improve sound quality for speech with high levels of background noise. Unlike mixed-excitation models requires no bits to be transmitted to handle background noise. - + \*---------------------------------------------------------------------------*/ /* @@ -46,8 +46,8 @@ #define BG_THRESH 40.0 /* only consider low levels signals for bg_est */ #define BG_BETA 0.1 /* averaging filter constant */ -#define BG_MARGIN 6.0 /* harmonics this far above BG noise are - randomised. Helped make bg noise less +#define BG_MARGIN 6.0 /* harmonics this far above BG noise are + randomised. Helped make bg noise less spikey (impulsive) for mmt1, but speech was perhaps a little rougher. */ @@ -78,7 +78,7 @@ This idea is rather experimental. Some potential problems that may happen: - + 1/ If someone says "aaaaaaaahhhhhhhhh" will background estimator track up to speech level? This would be a bad thing. @@ -95,13 +95,13 @@ 5/ Not sure what happens during long periods of voiced speech e.g. "sshhhhhhh" - + \*---------------------------------------------------------------------------*/ void postfilter( MODEL *model, float *bg_est -) +) { int m, uv; float e, thresh; @@ -111,7 +111,7 @@ void postfilter( e = 1E-12; for(m=1; m<=model->L; m++) e += model->A[m]*model->A[m]; - + assert(e > 0.0); e = 10.0*log10f(e/model->L); diff --git a/codec2-dev/src/postfilter.h b/codec2-dev/src/postfilter.h index bf080b1b..156714e5 100644 --- a/codec2-dev/src/postfilter.h +++ b/codec2-dev/src/postfilter.h @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - + FILE........: postfilter.h - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: 13/09/09 - + Postfilter header file. - + \*---------------------------------------------------------------------------*/ /* diff --git a/codec2-dev/src/quantise.c b/codec2-dev/src/quantise.c index fe1ebe78..9c08ef5e 100644 --- a/codec2-dev/src/quantise.c +++ b/codec2-dev/src/quantise.c @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - + FILE........: quantise.c - AUTHOR......: David Rowe - DATE CREATED: 31/5/92 - - Quantisation functions for the sinusoidal coder. - + AUTHOR......: David Rowe + DATE CREATED: 31/5/92 + + Quantisation functions for the sinusoidal coder. + \*---------------------------------------------------------------------------*/ /* @@ -43,16 +43,16 @@ #define LSP_DELTA1 0.01 /* grid spacing for LSP root searches */ /*---------------------------------------------------------------------------*\ - + FUNCTION HEADERS \*---------------------------------------------------------------------------*/ -float speech_to_uq_lsps(float lsp[], float ak[], float Sn[], float w[], +float speech_to_uq_lsps(float lsp[], float ak[], float Sn[], float w[], int order); /*---------------------------------------------------------------------------*\ - + FUNCTIONS \*---------------------------------------------------------------------------*/ @@ -145,7 +145,7 @@ long quantise(const float * cb, float vec[], float w[], int k, int m, float *se) /*---------------------------------------------------------------------------*\ - + encode_lspds_scalar() Scalar/VQ LSP difference quantiser. @@ -154,9 +154,9 @@ long quantise(const float * cb, float vec[], float w[], int k, int m, float *se) void encode_lspds_scalar( int indexes[], - float lsp[], + float lsp[], int order -) +) { int i,k,m; float lsp_hz[order]; @@ -184,8 +184,8 @@ void encode_lspds_scalar( /* find difference from previous qunatised lsp */ - if (i) - dlsp[i] = lsp_hz[i] - lsp__hz[i-1]; + if (i) + dlsp[i] = lsp_hz[i] - lsp__hz[i-1]; else dlsp[0] = lsp_hz[0]; @@ -196,11 +196,11 @@ void encode_lspds_scalar( dlsp_[i] = cb[indexes[i]*k]; - if (i) + if (i) lsp__hz[i] = lsp__hz[i-1] + dlsp_[i]; else lsp__hz[0] = dlsp_[0]; - + //printf("%d lsp %3.2f dlsp %3.2f dlsp_ %3.2f lsp_ %3.2f\n", i, lsp_hz[i], dlsp[i], dlsp_[i], lsp__hz[i]); } @@ -208,10 +208,10 @@ void encode_lspds_scalar( void decode_lspds_scalar( - float lsp_[], + float lsp_[], int indexes[], int order -) +) { int i,k; float lsp__hz[order]; @@ -224,7 +224,7 @@ void decode_lspds_scalar( cb = lsp_cbd[i].cb; dlsp_[i] = cb[indexes[i]*k]; - if (i) + if (i) lsp__hz[i] = lsp__hz[i-1] + dlsp_[i]; else lsp__hz[0] = dlsp_[0]; @@ -238,7 +238,7 @@ void decode_lspds_scalar( #ifdef __EXPERIMENTAL__ /*---------------------------------------------------------------------------*\ - + lspvq_quantise Vector LSP quantiser. @@ -246,10 +246,10 @@ void decode_lspds_scalar( \*---------------------------------------------------------------------------*/ void lspvq_quantise( - float lsp[], + float lsp[], float lsp_[], int order -) +) { int i,k,m,ncb, nlsp; float wt[order], lsp_hz[order]; @@ -298,21 +298,21 @@ void lspvq_quantise( } /*---------------------------------------------------------------------------*\ - + lspjnd_quantise Experimental JND LSP quantiser. \*---------------------------------------------------------------------------*/ -void lspjnd_quantise(float lsps[], float lsps_[], int order) +void lspjnd_quantise(float lsps[], float lsps_[], int order) { int i,k,m; float wt[order], lsps_hz[order]; const float *cb; float se = 0.0; int index; - + for(i=0; ientries; i++) { for(j=0; jlist[j].index[0]; for(i=0; ilist[j].index[0]; for(i=0; i max_index) index = max_index; @@ -1203,10 +1203,10 @@ int encode_Wo_dt(float Wo, float prev_Wo) } /*---------------------------------------------------------------------------*\ - - FUNCTION....: decode_Wo_dt() - AUTHOR......: David Rowe - DATE CREATED: 6 Nov 2011 + + FUNCTION....: decode_Wo_dt() + AUTHOR......: David Rowe + DATE CREATED: 6 Nov 2011 Decodes Wo using WO_DT_BITS difference from last frame. @@ -1221,14 +1221,14 @@ float decode_Wo_dt(int index, float prev_Wo) int mask; /* sign extend index */ - + //printf("DEC index: %d "); if (index & (1 << (WO_DT_BITS-1))) { mask = ~((1 << WO_DT_BITS) - 1); index |= mask; } //printf("DEC mask: 0x%x index: %d \n", mask, index); - + step = (Wo_max - Wo_min)/WO_LEVELS; Wo = prev_Wo + step*(index); @@ -1242,10 +1242,10 @@ float decode_Wo_dt(int index, float prev_Wo) } /*---------------------------------------------------------------------------*\ - - FUNCTION....: speech_to_uq_lsps() - AUTHOR......: David Rowe - DATE CREATED: 22/8/2010 + + FUNCTION....: speech_to_uq_lsps() + AUTHOR......: David Rowe + DATE CREATED: 22/8/2010 Analyse a windowed frame of time domain speech to determine LPCs which are the converted to LSPs for quantisation and transmission @@ -1255,7 +1255,7 @@ float decode_Wo_dt(int index, float prev_Wo) float speech_to_uq_lsps(float lsp[], float ak[], - float Sn[], + float Sn[], float w[], int order ) @@ -1272,20 +1272,20 @@ float speech_to_uq_lsps(float lsp[], } /* trap 0 energy case as LPC analysis will fail */ - + if (e == 0.0) { for(i=0; iWo = powf(2.0, xq[0])*(PI*50.0)/4000.0; /* bit errors can make us go out of range leading to all sorts of @@ -2054,14 +2054,14 @@ void quantise_WoE(MODEL *model, float *e, float xq[]) } /*---------------------------------------------------------------------------*\ - - FUNCTION....: encode_WoE() - AUTHOR......: Jean-Marc Valin & David Rowe + + FUNCTION....: encode_WoE() + AUTHOR......: Jean-Marc Valin & David Rowe DATE CREATED: 11 May 2012 Joint Wo and LPC energy vector quantiser developed my Jean-Marc Valin. Returns index, and updated states xq[]. - + \*---------------------------------------------------------------------------*/ int encode_WoE(MODEL *model, float e, float xq[]) @@ -2085,7 +2085,7 @@ int encode_WoE(MODEL *model, float e, float xq[]) for (i=0;i @@ -42,25 +42,25 @@ #define HPF_BETA 0.125 /*---------------------------------------------------------------------------*\ - - HEADERS - + + HEADERS + \*---------------------------------------------------------------------------*/ -void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax, +void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax, float pstep); /*---------------------------------------------------------------------------*\ - - FUNCTIONS - + + FUNCTIONS + \*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*\ - - FUNCTION....: make_analysis_window - AUTHOR......: David Rowe - DATE CREATED: 11/5/94 + + FUNCTION....: make_analysis_window + AUTHOR......: David Rowe + DATE CREATED: 11/5/94 Init function that generates the time domain analysis window and it's DFT. @@ -73,15 +73,15 @@ void make_analysis_window(kiss_fft_cfg fft_fwd_cfg, float w[], COMP W[]) COMP temp; int i,j; - /* + /* Generate Hamming window centered on M-sample pitch analysis window - + 0 M/2 M-1 |-------------|-------------| |-------|-------| NW samples - All our analysis/synthsis is centred on the M/2 sample. + All our analysis/synthsis is centred on the M/2 sample. */ m = 0.0; @@ -93,7 +93,7 @@ void make_analysis_window(kiss_fft_cfg fft_fwd_cfg, float w[], COMP W[]) } for(i=M/2+NW/2; iWo - 5; pstep = 1.0; hs_pitch_refinement(model,Sw,pmin,pmax,pstep); - + /* Fine refinement */ - + pmax = TWO_PI/model->Wo + 1; pmin = TWO_PI/model->Wo - 1; pstep = 0.25; hs_pitch_refinement(model,Sw,pmin,pmax,pstep); - + /* Limit range */ - + if (model->Wo < TWO_PI/P_MAX) model->Wo = TWO_PI/P_MAX; if (model->Wo > TWO_PI/P_MIN) @@ -265,20 +265,20 @@ void two_stage_pitch_refinement(MODEL *model, COMP Sw[]) } /*---------------------------------------------------------------------------*\ - - FUNCTION....: hs_pitch_refinement - AUTHOR......: David Rowe - DATE CREATED: 27/5/94 - - Harmonic sum pitch refinement function. - - pmin pitch search range minimum - pmax pitch search range maximum - step pitch search step size - model current pitch estimate in model.Wo - - model refined pitch estimate in model.Wo - + + FUNCTION....: hs_pitch_refinement + AUTHOR......: David Rowe + DATE CREATED: 27/5/94 + + Harmonic sum pitch refinement function. + + pmin pitch search range minimum + pmax pitch search range maximum + step pitch search step size + model current pitch estimate in model.Wo + + model refined pitch estimate in model.Wo + \*---------------------------------------------------------------------------*/ void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax, float pstep) @@ -291,9 +291,9 @@ void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax, float float Em; /* mamimum energy */ float r, one_on_r; /* number of rads/bin */ float p; /* current pitch */ - + /* Initialisation */ - + model->L = PI/model->Wo; /* use initial pitch est. for L */ Wom = model->Wo; Em = 0.0; @@ -310,9 +310,9 @@ void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax, float for(m=1; m<=model->L; m++) { b = (int)(m*Wo*one_on_r + 0.5); E += Sw[b].real*Sw[b].real + Sw[b].imag*Sw[b].imag; - } + } /* Compare to see if this is a maximum */ - + if (E > Em) { Em = E; Wom = Wo; @@ -323,13 +323,13 @@ void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax, float } /*---------------------------------------------------------------------------*\ - - FUNCTION....: estimate_amplitudes - AUTHOR......: David Rowe - DATE CREATED: 27/5/94 - - Estimates the complex amplitudes of the harmonics. - + + FUNCTION....: estimate_amplitudes + AUTHOR......: David Rowe + DATE CREATED: 27/5/94 + + Estimates the complex amplitudes of the harmonics. + \*---------------------------------------------------------------------------*/ void estimate_amplitudes(MODEL *model, COMP Sw[], COMP W[], int est_phase) @@ -375,14 +375,14 @@ void estimate_amplitudes(MODEL *model, COMP Sw[], COMP W[], int est_phase) } /*---------------------------------------------------------------------------*\ - - est_voicing_mbe() - + + est_voicing_mbe() + Returns the error of the MBE cost function for a fiven F0. Note: I think a lot of the operations below can be simplified as W[].imag = 0 and has been normalised such that den always equals 1. - + \*---------------------------------------------------------------------------*/ float est_voicing_mbe( @@ -398,7 +398,7 @@ float est_voicing_mbe( int offset; /* centers Hw[] about current harmonic */ float den; /* denominator of Am expression */ float error; /* accumulated error between original and synthesised */ - float Wo; + float Wo; float sig, snr; float elow, ehigh, eratio; float sixty; @@ -450,16 +450,16 @@ float est_voicing_mbe( error += Ew[m].imag*Ew[m].imag; } } - + snr = 10.0*log10f(sig/error); if (snr > V_THRESH) model->voiced = 1; else model->voiced = 0; - + /* post processing, helps clean up some voicing errors ------------------*/ - /* + /* Determine the ratio of low freqency to high frequency energy, voiced speech tends to be dominated by low frequency energy, unvoiced by high frequency. This measure can be used to @@ -505,10 +505,10 @@ float est_voicing_mbe( } /*---------------------------------------------------------------------------*\ - - FUNCTION....: make_synthesis_window - AUTHOR......: David Rowe - DATE CREATED: 11/5/94 + + FUNCTION....: make_synthesis_window + AUTHOR......: David Rowe + DATE CREATED: 11/5/94 Init function that generates the trapezoidal (Parzen) sythesis window. @@ -537,19 +537,19 @@ void make_synthesis_window(float Pn[]) } /*---------------------------------------------------------------------------*\ - - FUNCTION....: synthesise - AUTHOR......: David Rowe - DATE CREATED: 20/2/95 - + + FUNCTION....: synthesise + AUTHOR......: David Rowe + DATE CREATED: 20/2/95 + Synthesise a speech signal in the frequency domain from the sinusodal model parameters. Uses overlap-add with a trapezoidal window to smoothly interpolate betwen frames. - + \*---------------------------------------------------------------------------*/ void synthesise( - kiss_fft_cfg fft_inv_cfg, + kiss_fft_cfg fft_inv_cfg, float Sn_[], /* time domain synthesised signal */ MODEL *model, /* ptr to model parameters for this frame */ float Pn[], /* time domain Parzen window */ @@ -578,7 +578,7 @@ void synthesise( gives better results for synthesis frames greater than 10ms. Inverse FFT synthesis using a 512 pt FFT works well for 10ms window. I think (but am not sure) that the problem is related to the quantisation of - the harmonic frequencies to the FFT bin size, e.g. there is a + the harmonic frequencies to the FFT bin size, e.g. there is a 8000/512 Hz step between FFT bins. For some reason this makes the speech from longer frame > 10ms sound poor. The effect can also be seen when synthesising test signals like single sine waves, some @@ -620,7 +620,7 @@ void synthesise( } for(i=N-1,j=0; i<2*N; i++,j++) Sw_[j].real += 2.0*model->A[l]*cosf(j*model->Wo*l + model->phi[l]); - } + } #endif /* Overlap add to previous samples */ diff --git a/codec2-dev/src/sine.h b/codec2-dev/src/sine.h index c7c52cc1..1b1ae078 100644 --- a/codec2-dev/src/sine.h +++ b/codec2-dev/src/sine.h @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - + FILE........: sine.h - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: 1/11/94 - + Header file for sinusoidal analysis and synthesis functions. - + \*---------------------------------------------------------------------------*/ /* diff --git a/codec2-dev/src/varicode.c b/codec2-dev/src/varicode.c index 21f7cce1..7d0ec1a9 100644 --- a/codec2-dev/src/varicode.c +++ b/codec2-dev/src/varicode.c @@ -7,7 +7,7 @@ // To test: // $ gcc varicode.c -o varicode -DVARICODE_UNITTEST -Wall // $ ./varicode -// +// // License: // // This program is free software; you can redistribute it and/or modify @@ -72,11 +72,11 @@ int varicode_encode1(short varicode_out[], char ascii_in[], int max_out, int n_i packed <<= 1; varicode_out++; n_out++; - v_len++; + v_len++; } assert(v_len <= VARICODE_MAX_BITS); - n_in--; + n_in--; } return n_out; @@ -86,7 +86,7 @@ int varicode_encode1(short varicode_out[], char ascii_in[], int max_out, int n_i /* Code 2 covers a subset, but is more efficient that Code 1 (282 compared to 1315 bits on unittest) Unsupported characters are - replaced by spaces. We encode/decode two bits at a time. + replaced by spaces. We encode/decode two bits at a time. */ int varicode_encode2(short varicode_out[], char ascii_in[], int max_out, int n_in) { @@ -98,7 +98,7 @@ int varicode_encode2(short varicode_out[], char ascii_in[], int max_out, int n_i while(n_in && (n_out < max_out)) { packed = varicode_table2[0]; // default to space if char not found - + // see if our character exists for(i=0; istate == 0) { if (!varicode_in) return 0; - else + else s->state = 1; } @@ -243,7 +243,7 @@ static int decode_two_bits(struct VARICODE_DEC *s, char *single_ascii, short var if (s->state == 0) { if (!(varicode_in1 || varicode_in2)) return 0; - else + else s->state = 1; } @@ -257,8 +257,8 @@ static int decode_two_bits(struct VARICODE_DEC *s, char *single_ascii, short var else s->n_zeros+=2; - s->v_len+=2; - + s->v_len+=2; + found = 0; /* end of character code */ @@ -307,7 +307,7 @@ int varicode_decode1(struct VARICODE_DEC *dec_states, char ascii_out[], short va if (output) { *ascii_out++ = single_ascii; n_out++; - } + } } return n_out; @@ -336,12 +336,12 @@ int varicode_decode2(struct VARICODE_DEC *dec_states, char ascii_out[], short va output = decode_two_bits(dec_states, &single_ascii, dec_states->in[0], dec_states->in[1]); dec_states->n_in = 0; - + if (output) { //printf(" output: %d single_ascii: 0x%x %c\n", output, (int)single_ascii, single_ascii); *ascii_out++ = single_ascii; n_out++; - } + } } } @@ -396,14 +396,14 @@ void test_varicode(int code_num) { // printf("%d \n", varicode[i]); //} - // split decode in half to test how it preserves state between calls + // split decode in half to test how it preserves state between calls varicode_decode_init(&dec_states, code_num); half = n_varicode_bits_out/2; n_ascii_chars_out = varicode_decode(&dec_states, ascii_out, varicode, length, half); // printf(" n_ascii_chars_out: %d\n", n_ascii_chars_out); - n_ascii_chars_out += varicode_decode(&dec_states, &ascii_out[n_ascii_chars_out], + n_ascii_chars_out += varicode_decode(&dec_states, &ascii_out[n_ascii_chars_out], &varicode[half], length-n_ascii_chars_out, n_varicode_bits_out - half); assert(n_ascii_chars_out == length); @@ -420,7 +420,7 @@ void test_varicode(int code_num) { // 2. Test some ascii with a run of zeros ----------------------------------------------------- sprintf(ascii_in, "CQ CQ CQ this is VK5DGR"); - + assert(strlen(ascii_in) < length); if (code_num == 2) for(i=0; i
© COPYRIGHT 2011 STMicroelectronics
****************************************************************************** - */ + */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F4xx_CONF_H @@ -26,7 +26,7 @@ #if defined (HSE_VALUE) /* Redefine the HSE value; it's equal to 8 MHz on the STM32F4-DISCOVERY Kit */ #undef HSE_VALUE - #define HSE_VALUE ((uint32_t)8000000) + #define HSE_VALUE ((uint32_t)8000000) #endif /* HSE_VALUE */ /* Includes ------------------------------------------------------------------*/ @@ -61,13 +61,13 @@ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ -/* If an external clock source is used, then the value of the following define - should be set to the value of the external clock source, else, if no external +/* If an external clock source is used, then the value of the following define + should be set to the value of the external clock source, else, if no external clock is used, keep this define commented */ /*#define I2S_EXTERNAL_CLOCK_VAL 12288000 */ /* Value of the external clock in Hz */ -/* Uncomment the line below to expanse the "assert_param" macro in the +/* Uncomment the line below to expanse the "assert_param" macro in the Standard Peripheral Library drivers code */ /* #define USE_FULL_ASSERT 1 */ @@ -78,7 +78,7 @@ * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source - * line number of the call that failed. + * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ diff --git a/codec2-dev/stm32/src/adc_rec.c b/codec2-dev/stm32/src/adc_rec.c index 4f6574bd..68736fda 100644 --- a/codec2-dev/stm32/src/adc_rec.c +++ b/codec2-dev/stm32/src/adc_rec.c @@ -9,14 +9,14 @@ Note the semi-hosting system isn't fast enough to transfer 2 16 kHz streams at once. - + ~/stlink$ sudo ./st-util -f ~/codec2-dev/stm32/adc_rec.elf ~/codec2-dev/stm32$ ~/gcc-arm-none-eabi-4_7-2013q1/bin/arm-none-eabi-gdb adc_rec.elf - - (when finished) + + (when finished) $ play -r 16000 -s -2 ~/stlink/adc.raw - adc1 -> "from radio" + adc1 -> "from radio" adc2 -> "mic amp" \*---------------------------------------------------------------------------*/ @@ -67,7 +67,7 @@ int main(void){ for(i=0; iODR = (1 << 13); @@ -152,15 +152,15 @@ static void c2speedtest(int mode, char inputfile[]) } void gpio_init() { - RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN; // enable the clock to GPIOD - GPIOD->MODER = (1 << 26); // set pin 13 to be general + RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN; // enable the clock to GPIOD + GPIOD->MODER = (1 << 26); // set pin 13 to be general // purpose output } int main(int argc, char *argv[]) { gpio_init(); machdep_profile_init (); - + printf("Starting c2demo\n"); /* File I/O test for profiling or (with #define DUMP) @@ -169,7 +169,7 @@ int main(int argc, char *argv[]) { c2demo(CODEC2_MODE_1600, "stm_in.raw", "stm_out.raw"); printf("Starting c2 speed test\n"); - + /* Another test of execution speed. Look at PD13 with a oscilliscope. On time is enc, off is dec */ diff --git a/codec2-dev/stm32/src/dac_it.c b/codec2-dev/stm32/src/dac_it.c index 83803752..a2925fa8 100644 --- a/codec2-dev/stm32/src/dac_it.c +++ b/codec2-dev/stm32/src/dac_it.c @@ -1,11 +1,11 @@ /** ****************************************************************************** - * @file DMA/DMA_FLASHToRAM/stm32f4xx_it.c + * @file DMA/DMA_FLASHToRAM/stm32f4xx_it.c * @author MCD Application Team * @version V1.1.0 * @date 18-January-2013 * @brief Main Interrupt Service Routines. - * This file provides template for all exceptions handler and + * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention @@ -18,8 +18,8 @@ * * http://www.st.com/software_license_agreement_liberty_v2 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. @@ -38,7 +38,7 @@ int interrupts; /** @addtogroup DMA_FLASHToRAM * @{ - */ + */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ @@ -173,7 +173,7 @@ void DMA1_Stream6_IRQHandler(void) /* Clear DMA Stream Transfer Complete interrupt pending bit */ - DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_HTIF6); + DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_HTIF6); interrupts++; } @@ -188,7 +188,7 @@ void DMA1_Stream6_IRQHandler(void) /* Clear DMA Stream Transfer Complete interrupt pending bit */ - DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_TCIF6); + DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_TCIF6); interrupts++; } @@ -196,7 +196,7 @@ void DMA1_Stream6_IRQHandler(void) /** * @} - */ + */ /** * @} diff --git a/codec2-dev/stm32/src/dac_play.c b/codec2-dev/stm32/src/dac_play.c index 644c6859..db42e4b9 100644 --- a/codec2-dev/stm32/src/dac_play.c +++ b/codec2-dev/stm32/src/dac_play.c @@ -44,13 +44,13 @@ int main(void) { printf("Error opening input file: stm_in.raw\n\nTerminating....\n"); exit(1); } - + printf("Starting!\n"); while(fread(buf, sizeof(short), N, fplay) == N) { while(dac1_write(buf, N) == -1); while(dac2_write(buf, N) == -1); - } + } printf("Finished!\n"); fclose(fplay); diff --git a/codec2-dev/stm32/src/dac_ut.c b/codec2-dev/stm32/src/dac_ut.c index b660f0ca..872ecf68 100644 --- a/codec2-dev/stm32/src/dac_ut.c +++ b/codec2-dev/stm32/src/dac_ut.c @@ -54,6 +54,6 @@ int main(void) { dac1_write((short*)aSine, SINE_SAMPLES); dac2_write((short*)aSine, SINE_SAMPLES); } - + } diff --git a/codec2-dev/stm32/src/debugblinky.c b/codec2-dev/stm32/src/debugblinky.c index 2c694fdf..171cd5cc 100644 --- a/codec2-dev/stm32/src/debugblinky.c +++ b/codec2-dev/stm32/src/debugblinky.c @@ -35,11 +35,11 @@ void init_debug_blinky(void) { RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3; - GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; - GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIOE, &GPIO_InitStruct); + GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; + GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; + GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; + GPIO_Init(GPIOE, &GPIO_InitStruct); } diff --git a/codec2-dev/stm32/src/fast_dac_ut.c b/codec2-dev/stm32/src/fast_dac_ut.c index 7678a3d9..9712c441 100644 --- a/codec2-dev/stm32/src/fast_dac_ut.c +++ b/codec2-dev/stm32/src/fast_dac_ut.c @@ -42,7 +42,7 @@ /* 32 sample sine wave which at Fs=16kHz will be 500Hz. Note samples are 16 bit 2's complement, the DAC driver convertsto 12 bit unsigned. */ - + short aWave[] = {4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0, 4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,4095,0,}; @@ -67,7 +67,7 @@ void setup_timer() { RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); - TIM_TimeBaseInitTypeDef timerInitStructure; + TIM_TimeBaseInitTypeDef timerInitStructure; timerInitStructure.TIM_Prescaler = 84; timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up; timerInitStructure.TIM_Period = 0x8FFFFFFF; @@ -107,9 +107,9 @@ int main(void) { tend = TIM_GetCounter(TIM2); - //Sit and spin until we can get more samples into the dac + //Sit and spin until we can get more samples into the dac while(dac1_write((short*)outbuf,DAC_DUC_BUF_SZ)<0); } - + } diff --git a/codec2-dev/stm32/src/fdmdv_dump_rt.c b/codec2-dev/stm32/src/fdmdv_dump_rt.c index d4926cf2..52ca9771 100644 --- a/codec2-dev/stm32/src/fdmdv_dump_rt.c +++ b/codec2-dev/stm32/src/fdmdv_dump_rt.c @@ -70,7 +70,7 @@ int main(void) { short dac16k[FREEDV_NSAMPLES_16K]; short adc8k[FREEDV_NSAMPLES]; short dac8k[FDMDV_OS_TAPS_8K+FREEDV_NSAMPLES]; - + int nin, nout, i, j, frames, lines; COMP *symb, *psymb; @@ -105,7 +105,7 @@ int main(void) { /* ADC1 is the demod in signal from the radio rx, DAC2 is the SM1000 speaker */ - nin = freedv_nin(f); + nin = freedv_nin(f); nout = nin; f->total_bit_errors = 0; @@ -113,7 +113,7 @@ int main(void) { GPIOE->ODR = (1 << 3); fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], nin); nout = freedv_rx(f, &dac8k[FDMDV_OS_TAPS_8K], adc8k); - fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], nout); + fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], nout); dac2_write(dac16k, 2*nout); led_ptt(0); led_rt(f->fdmdv_stats.sync); led_err(f->total_bit_errors); GPIOE->ODR &= ~(1 << 3); @@ -128,14 +128,14 @@ int main(void) { psymb += (f->fdmdv_stats.Nc+1); lines++; } - + if (frames >= STOP_LOG_FRAMES) { FILE *ft = fopen("scatter.txt", "wt"); assert(ft != NULL); printf("Writing scatter file....\n"); for(j=0; jfdmdv_stats.Nc; i++) { - fprintf(ft, "%f\t%f\t", + fprintf(ft, "%f\t%f\t", (double)symb[j*(f->fdmdv_stats.Nc+1)+i].real, (double)symb[j*(f->fdmdv_stats.Nc+1)+i].imag); printf("line: %d\n", j); @@ -148,7 +148,7 @@ int main(void) { } #endif } - + } /* while(1) ... */ } diff --git a/codec2-dev/stm32/src/fdmdv_profile.c b/codec2-dev/stm32/src/fdmdv_profile.c index ee4f8b8b..2bb72b7f 100644 --- a/codec2-dev/stm32/src/fdmdv_profile.c +++ b/codec2-dev/stm32/src/fdmdv_profile.c @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) { assert(sync_bit == 0); channel_in(tx_fdm, 2*FDMDV_NOM_SAMPLES_PER_FRAME); - PROFILE_SAMPLE_AND_LOG(demod_start, mod_start, " mod"); + PROFILE_SAMPLE_AND_LOG(demod_start, mod_start, " mod"); for(j=0; j<2; j++) { channel_out(rx_fdm, nin); @@ -131,13 +131,13 @@ int main(int argc, char *argv[]) { fdmdv_put_test_bits(fdmdv, &test_frame_sync, error_pattern, &bit_errors, &ntest_bits, &codec_bits[bits_per_fdmdv_frame]); } } - PROFILE_SAMPLE_AND_LOG2(demod_start, " demod"); - PROFILE_SAMPLE_AND_LOG2(mod_start, " mod & demod"); + PROFILE_SAMPLE_AND_LOG2(demod_start, " demod"); + PROFILE_SAMPLE_AND_LOG2(mod_start, " mod & demod"); fdmdv_get_demod_stats(fdmdv, &stats); - printf("frame: %d sync: %d reliable_sync_bit: %d %d SNR: %3.2f test_frame_sync: %d\n", - i, stats.sync, reliable_sync_bit[0], reliable_sync_bit[1], (double)stats.snr_est, + printf("frame: %d sync: %d reliable_sync_bit: %d %d SNR: %3.2f test_frame_sync: %d\n", + i, stats.sync, reliable_sync_bit[0], reliable_sync_bit[1], (double)stats.snr_est, test_frame_sync); machdep_profile_print_logged_samples(); } diff --git a/codec2-dev/stm32/src/fft_test.c b/codec2-dev/stm32/src/fft_test.c index e511a845..a357cc58 100644 --- a/codec2-dev/stm32/src/fft_test.c +++ b/codec2-dev/stm32/src/fft_test.c @@ -1,55 +1,55 @@ -/* ---------------------------------------------------------------------- -* Copyright (C) 2010 ARM Limited. All rights reserved. -* -* $Date: 29. November 2010 -* $Revision: V1.0.3 -* -* Project: CMSIS DSP Library -* Title: arm_fft_bin_example_f32.c -* -* Description: Example code demonstrating calculation of Max energy bin of -* frequency domain of input signal. -* -* Target Processor: Cortex-M4/Cortex-M3 +/* ---------------------------------------------------------------------- +* Copyright (C) 2010 ARM Limited. All rights reserved. * +* $Date: 29. November 2010 +* $Revision: V1.0.3 * -* Version 1.0.3 2010/11/29 -* Re-organized the CMSIS folders and updated documentation. -* -* Version 1.0.1 2010/10/05 KK -* Production release and review comments incorporated. +* Project: CMSIS DSP Library +* Title: arm_fft_bin_example_f32.c +* +* Description: Example code demonstrating calculation of Max energy bin of +* frequency domain of input signal. +* +* Target Processor: Cortex-M4/Cortex-M3 +* +* +* Version 1.0.3 2010/11/29 +* Re-organized the CMSIS folders and updated documentation. +* +* Version 1.0.1 2010/10/05 KK +* Production release and review comments incorporated. * * Version 1.0.0 2010/09/20 KK * Production release and review comments incorporated. -* ------------------------------------------------------------------- */ - -/** - * @ingroup groupExamples - */ - -/** - * @defgroup FrequencyBin Frequency Bin Example - * +* ------------------------------------------------------------------- */ + +/** + * @ingroup groupExamples + */ + +/** + * @defgroup FrequencyBin Frequency Bin Example + * * \par Description * \par - * Demonstrates the calculation of the maximum energy bin in the frequency - * domain of the input signal with the use of Complex FFT, Complex - * Magnitude, and Maximum functions. - * + * Demonstrates the calculation of the maximum energy bin in the frequency + * domain of the input signal with the use of Complex FFT, Complex + * Magnitude, and Maximum functions. + * * \par Algorithm: * \par - * The input test signal contains a 10 kHz signal with uniformly distributed white noise. - * Calculating the FFT of the input signal will give us the maximum energy of the - * bin corresponding to the input frequency of 10 kHz. - * + * The input test signal contains a 10 kHz signal with uniformly distributed white noise. + * Calculating the FFT of the input signal will give us the maximum energy of the + * bin corresponding to the input frequency of 10 kHz. + * * \par Block Diagram: * \image html FFTBin.gif "Block Diagram" * \par - * The figure below shows the time domain signal of 10 kHz signal with + * The figure below shows the time domain signal of 10 kHz signal with * uniformly distributed white noise, and the next figure shows the input - * in the frequency domain. The bin with maximum energy corresponds to 10 kHz signal. + * in the frequency domain. The bin with maximum energy corresponds to 10 kHz signal. * \par - * \image html FFTBinInput.gif "Input signal in Time domain" + * \image html FFTBinInput.gif "Input signal in Time domain" * \image html FFTBinOutput.gif "Input signal in Frequency domain" * * \par Variables Description: @@ -61,7 +61,7 @@ * \li \c doBitReverse Flag for selection of normal order or bit reversed order * \li \c refIndex reference index value at which maximum energy of bin ocuurs * \li \c testIndex calculated index value at which maximum energy of bin ocuurs - * + * * \par CMSIS DSP Software Library Functions Used: * \par * - arm_cfft_radix4_init_f32() @@ -69,108 +69,108 @@ * - arm_cmplx_mag_f32() * - arm_max_f32() * - * Refer + * Refer * \link arm_fft_bin_example_f32.c \endlink - * - */ - - -/** \example arm_fft_bin_example_f32.c - */ - - -#include "arm_math.h" + * + */ + + +/** \example arm_fft_bin_example_f32.c + */ + + +#include "arm_math.h" #include "gdb_stdio.h" #include "machdep.h" #include "kiss_fft.h" - + #define TEST_LENGTH_SAMPLES 1024 - -/* ------------------------------------------------------------------- -* External Input and Output buffer Declarations for FFT Bin Example -* ------------------------------------------------------------------- */ -extern float32_t testInput_f32_10khz[TEST_LENGTH_SAMPLES]; -static float32_t testOutput[TEST_LENGTH_SAMPLES/2]; -static float32_t kiss_complex_out[TEST_LENGTH_SAMPLES]; - -/* ------------------------------------------------------------------ -* Global variables for FFT Bin Example -* ------------------------------------------------------------------- */ -uint32_t fftSize = TEST_LENGTH_SAMPLES/2; -uint32_t ifftFlag = 0; -uint32_t doBitReverse = 1; - -/* Reference index at which max energy of bin ocuurs */ -uint32_t refIndex = 213, testIndex = 0; - -/* ---------------------------------------------------------------------- -* Max magnitude FFT Bin test -* ------------------------------------------------------------------- */ - + +/* ------------------------------------------------------------------- +* External Input and Output buffer Declarations for FFT Bin Example +* ------------------------------------------------------------------- */ +extern float32_t testInput_f32_10khz[TEST_LENGTH_SAMPLES]; +static float32_t testOutput[TEST_LENGTH_SAMPLES/2]; +static float32_t kiss_complex_out[TEST_LENGTH_SAMPLES]; + +/* ------------------------------------------------------------------ +* Global variables for FFT Bin Example +* ------------------------------------------------------------------- */ +uint32_t fftSize = TEST_LENGTH_SAMPLES/2; +uint32_t ifftFlag = 0; +uint32_t doBitReverse = 1; + +/* Reference index at which max energy of bin ocuurs */ +uint32_t refIndex = 213, testIndex = 0; + +/* ---------------------------------------------------------------------- +* Max magnitude FFT Bin test +* ------------------------------------------------------------------- */ + void SystemInit(void); -int main(void) -{ - - arm_status status; - arm_cfft_radix2_instance_f32 S; - float32_t maxValue; +int main(void) +{ + + arm_status status; + arm_cfft_radix2_instance_f32 S; + float32_t maxValue; unsigned int fft_start, kiss_fft_start; kiss_fft_cfg fft_fwd_cfg; SystemInit(); machdep_profile_init(); fft_fwd_cfg = kiss_fft_alloc(fftSize, 0, NULL, NULL); - kiss_fft_start = machdep_profile_sample(); - kiss_fft(fft_fwd_cfg, (kiss_fft_cpx *)testInput_f32_10khz, + kiss_fft_start = machdep_profile_sample(); + kiss_fft(fft_fwd_cfg, (kiss_fft_cpx *)testInput_f32_10khz, (kiss_fft_cpx *)kiss_complex_out); - machdep_profile_sample_and_log(kiss_fft_start, " kiss_fft"); - - status = ARM_MATH_SUCCESS; - - /* Initialize the CFFT/CIFFT module */ - status = arm_cfft_radix2_init_f32(&S, fftSize, ifftFlag, doBitReverse); - - /* Process the data through the CFFT/CIFFT module */ - fft_start = machdep_profile_sample(); - arm_cfft_radix2_f32(&S, testInput_f32_10khz); - machdep_profile_sample_and_log(fft_start, " fft"); + machdep_profile_sample_and_log(kiss_fft_start, " kiss_fft"); + + status = ARM_MATH_SUCCESS; + + /* Initialize the CFFT/CIFFT module */ + status = arm_cfft_radix2_init_f32(&S, fftSize, ifftFlag, doBitReverse); + + /* Process the data through the CFFT/CIFFT module */ + fft_start = machdep_profile_sample(); + arm_cfft_radix2_f32(&S, testInput_f32_10khz); + machdep_profile_sample_and_log(fft_start, " fft"); machdep_profile_print_logged_samples(); - /* Process the data through the Complex Magnitude Module for - calculating the magnitude at each bin */ - arm_cmplx_mag_f32(testInput_f32_10khz, testOutput,fftSize); - - /* Calculates maxValue and returns corresponding BIN value */ - arm_max_f32(testOutput, fftSize, &maxValue, &testIndex); - - if(testIndex != refIndex) - { - status = ARM_MATH_TEST_FAILURE; - } - - /* ---------------------------------------------------------------------- - ** Loop here if the signals fail the PASS check. - ** This denotes a test failure - ** ------------------------------------------------------------------- */ - - if( status != ARM_MATH_SUCCESS) - { - while(1); - } + /* Process the data through the Complex Magnitude Module for + calculating the magnitude at each bin */ + arm_cmplx_mag_f32(testInput_f32_10khz, testOutput,fftSize); + + /* Calculates maxValue and returns corresponding BIN value */ + arm_max_f32(testOutput, fftSize, &maxValue, &testIndex); + + if(testIndex != refIndex) + { + status = ARM_MATH_TEST_FAILURE; + } + + /* ---------------------------------------------------------------------- + ** Loop here if the signals fail the PASS check. + ** This denotes a test failure + ** ------------------------------------------------------------------- */ + + if( status != ARM_MATH_SUCCESS) + { + while(1); + } while(1); /* main function does not return */ return 0; -} - - /** \endlink */ - - +} + + /** \endlink */ + + /* * Dummy function to avoid compiler error */ void _init() { } - + diff --git a/codec2-dev/stm32/src/freedv_rx_profile.c b/codec2-dev/stm32/src/freedv_rx_profile.c index f91fc4fe..52ad6d22 100644 --- a/codec2-dev/stm32/src/freedv_rx_profile.c +++ b/codec2-dev/stm32/src/freedv_rx_profile.c @@ -97,7 +97,7 @@ int main(int argc, char *argv[]) { adc16k[i] = 0.0; for(i=0; i=F48C80R_LEN) ptr_48c80r-=F48C80R_LEN; } @@ -154,7 +154,7 @@ void upconv_48c_80r(COMP comp_48[],int real_80[],int count){ /*This loop computes the FIR filter. It only computes from either the re or the im delay line, depending on comp->re phase It also skips all 'zeros' in the delay line */ for(k=js5;kreal conversion by hand @@ -261,11 +261,11 @@ void upconv_8c_80r(COMP comp_8[],float real_80[],int count){ int2r = int1r + int2r; //Integrator stage 2 re int3r = int2r + int3r; //Integrator stage 3 re int4r = int3r + int4r; //Integrator stage 4 re - int5r = int4r + int5r; + int5r = int4r + int5r; int2i = int1i + int2i; //Integrator stage 2 im int3i = int2i + int3i; //Integrator stage 3 im int4i = int3i + int4i; //Integrator stage 4 im - int5i = int4i + int5i; + int5i = int4i + int5i; switch(w8c80r&0x3){ //Do comp->real conversion by hand case 0:ret=(float)(-int5i>>7);break; case 1:ret=(float)(int5r>>7);break; @@ -277,7 +277,7 @@ void upconv_8c_80r(COMP comp_8[],float real_80[],int count){ w8c80r++; } } - } + } } #ifdef __UNITTEST__ @@ -329,12 +329,12 @@ int main(void) { //Impulse to give us an idea of our filter bands in[0].imag=0.70710678118; in[0].real=0.70710678118; - + //interpolate from 8k comp to 80k real upconv_48c_80r(in,s,NOUT_BUFS); for(i=0;i>B2SHFT); @@ -98,12 +98,12 @@ void iir_tuner(float dec_50[], unsigned short adc_buf[]) { o_2 = o_1; o_1 = n; #else - z=y+BETA2*z_2; + z=y+BETA2*z_2; dec_50[j] = z; z_2 = z_1; z_1 = y; #endif - + } } @@ -121,7 +121,7 @@ void iir_tuner_dec_50_to_10(float dec_10[], float dec_50[], int n) { acc += dec_50[i-j]*fir_50_to_10[j]; dec_10[k] = acc; } - + } @@ -171,7 +171,7 @@ int main(void) { for(i=0, j=0; iODR &= ~(1 << 13); //printf("Codec 2 dec\n"); codec2_decode(codec2, outbuf, bits); - + //printf("write to DAC\n"); while(dac1_write(dummy_buf, nsam*2) == -1); /* runs at Fs = 16kHz */ //printf("."); @@ -112,8 +112,8 @@ static void c2speedtest(int mode, char inputfile[]) } void gpio_init() { - RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN; // enable the clock to GPIOD - GPIOD->MODER = (1 << 26); // set pin 13 to be general + RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN; // enable the clock to GPIOD + GPIOD->MODER = (1 << 26); // set pin 13 to be general // purpose output } diff --git a/codec2-dev/stm32/src/sfx.c b/codec2-dev/stm32/src/sfx.c index 293522e0..f80c8d15 100644 --- a/codec2-dev/stm32/src/sfx.c +++ b/codec2-dev/stm32/src/sfx.c @@ -3,7 +3,7 @@ * * This implements a state machine for playing back various monophonic * sound effects such as morse code symbols, clicks and alert tones. - * + * * Author Stuart Longland * Copyright (C) 2015 FreeDV project. * diff --git a/codec2-dev/stm32/src/sfx.h b/codec2-dev/stm32/src/sfx.h index 3ac8d5a9..97450186 100644 --- a/codec2-dev/stm32/src/sfx.h +++ b/codec2-dev/stm32/src/sfx.h @@ -5,7 +5,7 @@ * * This implements a state machine for playing back various monophonic * sound effects such as morse code symbols, clicks and alert tones. - * + * * Author Stuart Longland * Copyright (C) 2015 FreeDV project. * diff --git a/codec2-dev/stm32/src/sine.c b/codec2-dev/stm32/src/sine.c index 254a61ec..be4df00a 100644 --- a/codec2-dev/stm32/src/sine.c +++ b/codec2-dev/stm32/src/sine.c @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - + FILE........: sine.c - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: 19/8/2010 - + Sinusoidal analysis and synthesis functions. - + \*---------------------------------------------------------------------------*/ /* @@ -26,9 +26,9 @@ */ /*---------------------------------------------------------------------------*\ - - INCLUDES - + + INCLUDES + \*---------------------------------------------------------------------------*/ #include @@ -42,25 +42,25 @@ #define HPF_BETA 0.125 /*---------------------------------------------------------------------------*\ - - HEADERS - + + HEADERS + \*---------------------------------------------------------------------------*/ -void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax, +void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax, float pstep); /*---------------------------------------------------------------------------*\ - - FUNCTIONS - + + FUNCTIONS + \*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*\ - - FUNCTION....: make_analysis_window - AUTHOR......: David Rowe - DATE CREATED: 11/5/94 + + FUNCTION....: make_analysis_window + AUTHOR......: David Rowe + DATE CREATED: 11/5/94 Init function that generates the time domain analysis window and it's DFT. @@ -73,15 +73,15 @@ void make_analysis_window(kiss_fft_cfg fft_fwd_cfg, float w[], COMP W[]) COMP temp; int i,j; - /* + /* Generate Hamming window centered on M-sample pitch analysis window - + 0 M/2 M-1 |-------------|-------------| |-------|-------| NW samples - All our analysis/synthsis is centred on the M/2 sample. + All our analysis/synthsis is centred on the M/2 sample. */ m = 0.0; @@ -93,7 +93,7 @@ void make_analysis_window(kiss_fft_cfg fft_fwd_cfg, float w[], COMP W[]) } for(i=M/2+NW/2; iWo - 5; pstep = 1.0; hs_pitch_refinement(model,Sw,pmin,pmax,pstep); - + /* Fine refinement */ - + pmax = TWO_PI/model->Wo + 1; pmin = TWO_PI/model->Wo - 1; pstep = 0.25; hs_pitch_refinement(model,Sw,pmin,pmax,pstep); - + /* Limit range */ - + if (model->Wo < TWO_PI/P_MAX) model->Wo = TWO_PI/P_MAX; if (model->Wo > TWO_PI/P_MIN) @@ -265,20 +265,20 @@ void two_stage_pitch_refinement(MODEL *model, COMP Sw[]) } /*---------------------------------------------------------------------------*\ - - FUNCTION....: hs_pitch_refinement - AUTHOR......: David Rowe - DATE CREATED: 27/5/94 - - Harmonic sum pitch refinement function. - - pmin pitch search range minimum - pmax pitch search range maximum - step pitch search step size - model current pitch estimate in model.Wo - - model refined pitch estimate in model.Wo - + + FUNCTION....: hs_pitch_refinement + AUTHOR......: David Rowe + DATE CREATED: 27/5/94 + + Harmonic sum pitch refinement function. + + pmin pitch search range minimum + pmax pitch search range maximum + step pitch search step size + model current pitch estimate in model.Wo + + model refined pitch estimate in model.Wo + \*---------------------------------------------------------------------------*/ void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax, float pstep) @@ -291,9 +291,9 @@ void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax, float float Em; /* mamimum energy */ float r, one_on_r; /* number of rads/bin */ float p; /* current pitch */ - + /* Initialisation */ - + model->L = PI/model->Wo; /* use initial pitch est. for L */ Wom = model->Wo; Em = 0.0; @@ -310,9 +310,9 @@ void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax, float for(m=1; m<=model->L; m++) { b = (int)(m*Wo*one_on_r + 0.5); E += Sw[b].real*Sw[b].real + Sw[b].imag*Sw[b].imag; - } + } /* Compare to see if this is a maximum */ - + if (E > Em) { Em = E; Wom = Wo; @@ -323,13 +323,13 @@ void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax, float } /*---------------------------------------------------------------------------*\ - - FUNCTION....: estimate_amplitudes - AUTHOR......: David Rowe - DATE CREATED: 27/5/94 - - Estimates the complex amplitudes of the harmonics. - + + FUNCTION....: estimate_amplitudes + AUTHOR......: David Rowe + DATE CREATED: 27/5/94 + + Estimates the complex amplitudes of the harmonics. + \*---------------------------------------------------------------------------*/ void estimate_amplitudes(MODEL *model, COMP Sw[], COMP W[], int est_phase) @@ -375,14 +375,14 @@ void estimate_amplitudes(MODEL *model, COMP Sw[], COMP W[], int est_phase) } /*---------------------------------------------------------------------------*\ - - est_voicing_mbe() - + + est_voicing_mbe() + Returns the error of the MBE cost function for a fiven F0. Note: I think a lot of the operations below can be simplified as W[].imag = 0 and has been normalised such that den always equals 1. - + \*---------------------------------------------------------------------------*/ float est_voicing_mbe( @@ -399,7 +399,7 @@ float est_voicing_mbe( int offset; /* centers Hw[] about current harmonic */ float den; /* denominator of Am expression */ float error; /* accumulated error between original and synthesised */ - float Wo; + float Wo; float sig, snr; float elow, ehigh, eratio; float sixty; @@ -451,16 +451,16 @@ float est_voicing_mbe( error += Ew[m].imag*Ew[m].imag; } } - + snr = 10.0*log10f(sig/error); if (snr > V_THRESH) model->voiced = 1; else model->voiced = 0; - + /* post processing, helps clean up some voicing errors ------------------*/ - /* + /* Determine the ratio of low freqency to high frequency energy, voiced speech tends to be dominated by low frequency energy, unvoiced by high frequency. This measure can be used to @@ -506,10 +506,10 @@ float est_voicing_mbe( } /*---------------------------------------------------------------------------*\ - - FUNCTION....: make_synthesis_window - AUTHOR......: David Rowe - DATE CREATED: 11/5/94 + + FUNCTION....: make_synthesis_window + AUTHOR......: David Rowe + DATE CREATED: 11/5/94 Init function that generates the trapezoidal (Parzen) sythesis window. @@ -538,19 +538,19 @@ void make_synthesis_window(float Pn[]) } /*---------------------------------------------------------------------------*\ - - FUNCTION....: synthesise - AUTHOR......: David Rowe - DATE CREATED: 20/2/95 - + + FUNCTION....: synthesise + AUTHOR......: David Rowe + DATE CREATED: 20/2/95 + Synthesise a speech signal in the frequency domain from the sinusodal model parameters. Uses overlap-add with a trapezoidal window to smoothly interpolate betwen frames. - + \*---------------------------------------------------------------------------*/ void synthesise( - kiss_fft_cfg fft_inv_cfg, + kiss_fft_cfg fft_inv_cfg, float Sn_[], /* time domain synthesised signal */ MODEL *model, /* ptr to model parameters for this frame */ float Pn[], /* time domain Parzen window */ @@ -579,7 +579,7 @@ void synthesise( gives better results for synthesis frames greater than 10ms. Inverse FFT synthesis using a 512 pt FFT works well for 10ms window. I think (but am not sure) that the problem is related to the quantisation of - the harmonic frequencies to the FFT bin size, e.g. there is a + the harmonic frequencies to the FFT bin size, e.g. there is a 8000/512 Hz step between FFT bins. For some reason this makes the speech from longer frame > 10ms sound poor. The effect can also be seen when synthesising test signals like single sine waves, some @@ -621,7 +621,7 @@ void synthesise( } for(i=N-1,j=0; i<2*N; i++,j++) Sw_[j].real += 2.0*model->A[l]*cos(j*model->Wo*l + model->phi[l]); - } + } #endif /* Overlap add to previous samples */ diff --git a/codec2-dev/stm32/src/sine.h b/codec2-dev/stm32/src/sine.h index da7dc28e..3a3ce46d 100644 --- a/codec2-dev/stm32/src/sine.h +++ b/codec2-dev/stm32/src/sine.h @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - + FILE........: sine.h - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: 1/11/94 - + Header file for sinusoidal analysis and synthesis functions. - + \*---------------------------------------------------------------------------*/ /* @@ -37,7 +37,7 @@ float hpf(float x, float states[]); void dft_speech(kiss_fft_cfg fft_fwd_cfg, COMP Sw[], float Sn[], float w[]); void two_stage_pitch_refinement(MODEL *model, COMP Sw[]); void estimate_amplitudes(MODEL *model, COMP Sw[], COMP W[], int est_phase); -float est_voicing_mbe(MODEL *model, COMP Sw[], COMP W[], COMP Sw_[],COMP Ew[], +float est_voicing_mbe(MODEL *model, COMP Sw[], COMP W[], COMP Sw_[],COMP Ew[], float prev_Wo); void make_synthesis_window(float Pn[]); void synthesise(kiss_fft_cfg fft_inv_cfg, float Sn_[], MODEL *model, float Pn[], int shift); diff --git a/codec2-dev/stm32/src/sm1000_leds_switches.c b/codec2-dev/stm32/src/sm1000_leds_switches.c index e630cf07..aa633711 100644 --- a/codec2-dev/stm32/src/sm1000_leds_switches.c +++ b/codec2-dev/stm32/src/sm1000_leds_switches.c @@ -47,27 +47,27 @@ void sm1000_leds_switches_init(void) { /* output pins */ GPIO_InitStruct.GPIO_Pin = LED_PWR | LED_PTT | LED_RT | LED_ERR | _CPTT; - GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz; - GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; - GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIOD, &GPIO_InitStruct); + GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; + GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz; + GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; + GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; + GPIO_Init(GPIOD, &GPIO_InitStruct); /* input pins */ GPIO_InitStruct.GPIO_Pin = SWITCH_PTT | SWITCH_SELECT | SWITCH_BACK; - GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz; - GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; /* we have our own external pull ups */ - GPIO_Init(GPIOD, &GPIO_InitStruct); + GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN; + GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz; + GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; /* we have our own external pull ups */ + GPIO_Init(GPIOD, &GPIO_InitStruct); GPIO_InitStruct.GPIO_Pin = EXT_PTT; - GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz; - GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; /* use internal pull up */ - GPIO_Init(GPIOD, &GPIO_InitStruct); + GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN; + GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz; + GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; /* use internal pull up */ + GPIO_Init(GPIOD, &GPIO_InitStruct); + - } void led_pwr(int state) { diff --git a/codec2-dev/stm32/src/sm1000_main.c b/codec2-dev/stm32/src/sm1000_main.c index b9d548dc..391406e7 100644 --- a/codec2-dev/stm32/src/sm1000_main.c +++ b/codec2-dev/stm32/src/sm1000_main.c @@ -109,11 +109,11 @@ int main(void) { ss.mode = ANALOG; while(1) { - + iterate_select_state_machine(&ss); if (switch_ptt() || (ext_ptt() == 0)) { - + /* Transmit -------------------------------------------------------------------------*/ /* ADC2 is the SM1000 microphone, DAC1 is the modulator signal we send to radio tx */ @@ -134,20 +134,20 @@ int main(void) { if (ss.mode == ANALOG) { for(i=0; iODR = (1 << 3); fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], nin); nout = freedv_rx(f, &dac8k[FDMDV_OS_TAPS_8K], adc8k); - fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], nout); + fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], nout); dac2_write(dac16k, 2*nout); led_rt(freedv_get_sync(f)); led_err(freedv_get_total_bit_errors(f)); GPIOE->ODR &= ~(1 << 3); @@ -244,4 +244,4 @@ void iterate_select_state_machine(SWITCH_STATE *ss) { } ss->state = next_state; } - + diff --git a/codec2-dev/stm32/src/sounds.c b/codec2-dev/stm32/src/sounds.c index b79b641e..d0ca8d67 100644 --- a/codec2-dev/stm32/src/sounds.c +++ b/codec2-dev/stm32/src/sounds.c @@ -2,7 +2,7 @@ * Sound effect library. * * This provides some sound effects for the SM1000 UI. - * + * * Author Stuart Longland * Copyright (C) 2015 FreeDV project. * diff --git a/codec2-dev/stm32/src/sounds.h b/codec2-dev/stm32/src/sounds.h index a2e8a012..34f8fad0 100644 --- a/codec2-dev/stm32/src/sounds.h +++ b/codec2-dev/stm32/src/sounds.h @@ -4,7 +4,7 @@ * Sound effect library. * * This provides some sound effects for the SM1000 UI. - * + * * Author Stuart Longland * Copyright (C) 2015 FreeDV project. * diff --git a/codec2-dev/stm32/src/stm32f4_adc.c b/codec2-dev/stm32/src/stm32f4_adc.c index cecdbe1d..5e5014ed 100644 --- a/codec2-dev/stm32/src/stm32f4_adc.c +++ b/codec2-dev/stm32/src/stm32f4_adc.c @@ -33,7 +33,7 @@ #include "stm32f4xx_adc.h" #include "stm32f4xx_gpio.h" #include "stm32f4xx_rcc.h" - + #include "codec2_fifo.h" #include "stm32f4_adc.h" #include "debugblinky.h" @@ -66,13 +66,13 @@ void adc_open(int fifo_sz) { /* n signed 16 bit samples in buf[] if return != -1 */ -int adc1_read(short buf[], int n) { +int adc1_read(short buf[], int n) { return fifo_read(adc1_fifo, buf, n); } /* n signed 16 bit samples in buf[] if return != -1 */ -int adc2_read(short buf[], int n) { +int adc2_read(short buf[], int n) { return fifo_read(adc2_fifo, buf, n); } @@ -83,31 +83,31 @@ static void tim2_config(void) /* TIM2 Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); - + /* -------------------------------------------------------- - + TIM2 input clock (TIM2CLK) is set to 2 * APB1 clock (PCLK1), since APB1 prescaler is different from 1 (see system_stm32f4xx.c and Fig 13 clock tree figure in DM0031020.pdf). - Sample rate Fs = 2*PCLK1/TIM_ClockDivision + Sample rate Fs = 2*PCLK1/TIM_ClockDivision = (HCLK/2)/TIM_ClockDivision - + ----------------------------------------------------------- */ /* Time base configuration */ - TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); - TIM_TimeBaseStructure.TIM_Period = 5250; - TIM_TimeBaseStructure.TIM_Prescaler = 0; - TIM_TimeBaseStructure.TIM_ClockDivision = 0; - TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); + TIM_TimeBaseStructure.TIM_Period = 5250; + TIM_TimeBaseStructure.TIM_Prescaler = 0; + TIM_TimeBaseStructure.TIM_ClockDivision = 0; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); /* TIM2 TRGO selection */ TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update); - + /* TIM2 enable counter */ TIM_Cmd(TIM2, ENABLE); @@ -115,8 +115,8 @@ static void tim2_config(void) void adc_configure(){ - ADC_InitTypeDef ADC_init_structure; - GPIO_InitTypeDef GPIO_initStructre; + ADC_InitTypeDef ADC_init_structure; + GPIO_InitTypeDef GPIO_initStructre; DMA_InitTypeDef DMA_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; @@ -126,19 +126,19 @@ void adc_configure(){ RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_GPIOAEN,ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); - // Analog pin configuration ADC1->PA1, ADC2->PA2 + // Analog pin configuration ADC1->PA1, ADC2->PA2 - GPIO_initStructre.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2; - GPIO_initStructre.GPIO_Mode = GPIO_Mode_AN; - GPIO_initStructre.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIOA,&GPIO_initStructre); + GPIO_initStructre.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2; + GPIO_initStructre.GPIO_Mode = GPIO_Mode_AN; + GPIO_initStructre.GPIO_PuPd = GPIO_PuPd_NOPULL; + GPIO_Init(GPIOA,&GPIO_initStructre); // ADC structure configuration ADC_DeInit(); ADC_init_structure.ADC_DataAlign = ADC_DataAlign_Left; ADC_init_structure.ADC_Resolution = ADC_Resolution_12b; - ADC_init_structure.ADC_ContinuousConvMode = DISABLE; + ADC_init_structure.ADC_ContinuousConvMode = DISABLE; ADC_init_structure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_TRGO; ADC_init_structure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising; ADC_init_structure.ADC_NbrOfConversion = 2; @@ -149,12 +149,12 @@ void adc_configure(){ ADC_RegularChannelConfig(ADCx,ADC_Channel_1,1,ADC_SampleTime_144Cycles); ADC_RegularChannelConfig(ADCx,ADC_Channel_2,2,ADC_SampleTime_144Cycles); - //ADC_VBATCmd(ENABLE); + //ADC_VBATCmd(ENABLE); /* DMA configuration **************************************/ DMA_DeInit(DMA_STREAMx); - DMA_InitStructure.DMA_Channel = DMA_CHANNELx; + DMA_InitStructure.DMA_Channel = DMA_CHANNELx; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADCx_DR_ADDRESS; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)adc_buf; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; @@ -165,7 +165,7 @@ void adc_configure(){ DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; - DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; + DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; @@ -193,7 +193,7 @@ void adc_configure(){ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); + NVIC_Init(&NVIC_InitStructure); // Enable and start ADC conversion @@ -236,7 +236,7 @@ void DMA2_Stream0_IRQHandler(void) { /* Clear DMA Stream Transfer Complete interrupt pending bit */ - DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_HTIF0); + DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_HTIF0); } /* Transfer complete interrupt */ @@ -264,7 +264,7 @@ void DMA2_Stream0_IRQHandler(void) { /* Clear DMA Stream Transfer Complete interrupt pending bit */ - DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0); + DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0); } GPIOE->ODR &= ~(1 << 0); diff --git a/codec2-dev/stm32/src/stm32f4_adc_tuner.c b/codec2-dev/stm32/src/stm32f4_adc_tuner.c index 9d74130b..30caf803 100644 --- a/codec2-dev/stm32/src/stm32f4_adc_tuner.c +++ b/codec2-dev/stm32/src/stm32f4_adc_tuner.c @@ -35,7 +35,7 @@ #include "stm32f4xx_adc.h" #include "stm32f4xx_gpio.h" #include "stm32f4xx_rcc.h" - + #include "codec2_fifo.h" #include "stm32f4_adc_tuner.h" #include "debugblinky.h" @@ -69,7 +69,7 @@ void adc_open(int fifo_sz) { /* n signed 16 bit samples in buf[] if return != -1 */ -int adc1_read(short buf[], int n) { +int adc1_read(short buf[], int n) { return fifo_read(adc1_fifo, buf, n); } @@ -85,16 +85,16 @@ static void tim2_config(void) /* TIM2 Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); - + /* -------------------------------------------------------- - + TIM2 input clock (TIM2CLK) is set to 2 * APB1 clock (PCLK1), since APB1 prescaler is different from 1 (see system_stm32f4xx.c and Fig 13 clock tree figure in DM0031020.pdf). Sample rate Fs = 2*PCLK1/)TIM_ClockDivision+1) = (HCLK/2)/(TIM_ClockDivision+1) - + Note from David: The +1 was discovered empirically, still not sure if it's right. @@ -102,17 +102,17 @@ static void tim2_config(void) /* Time base configuration */ - TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); - TIM_TimeBaseStructure.TIM_Period = 41; - TIM_TimeBaseStructure.TIM_Prescaler = 0; - TIM_TimeBaseStructure.TIM_ClockDivision = 0; - TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); + TIM_TimeBaseStructure.TIM_Period = 41; + TIM_TimeBaseStructure.TIM_Prescaler = 0; + TIM_TimeBaseStructure.TIM_ClockDivision = 0; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); /* TIM2 TRGO selection */ TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update); - + /* TIM2 enable counter */ TIM_Cmd(TIM2, ENABLE); @@ -120,8 +120,8 @@ static void tim2_config(void) void adc_configure() { - ADC_InitTypeDef ADC_init_structure; - GPIO_InitTypeDef GPIO_initStructre; + ADC_InitTypeDef ADC_init_structure; + GPIO_InitTypeDef GPIO_initStructre; DMA_InitTypeDef DMA_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; @@ -133,17 +133,17 @@ void adc_configure() { // Analog pin configuration ADC1->PA1 - GPIO_initStructre.GPIO_Pin = GPIO_Pin_1; - GPIO_initStructre.GPIO_Mode = GPIO_Mode_AN; - GPIO_initStructre.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIOA,&GPIO_initStructre); + GPIO_initStructre.GPIO_Pin = GPIO_Pin_1; + GPIO_initStructre.GPIO_Mode = GPIO_Mode_AN; + GPIO_initStructre.GPIO_PuPd = GPIO_PuPd_NOPULL; + GPIO_Init(GPIOA,&GPIO_initStructre); // ADC structure configuration ADC_DeInit(); ADC_init_structure.ADC_DataAlign = ADC_DataAlign_Left; ADC_init_structure.ADC_Resolution = ADC_Resolution_12b; - ADC_init_structure.ADC_ContinuousConvMode = DISABLE; + ADC_init_structure.ADC_ContinuousConvMode = DISABLE; ADC_init_structure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_TRGO; ADC_init_structure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising; ADC_init_structure.ADC_NbrOfConversion = 1; @@ -156,7 +156,7 @@ void adc_configure() { /* DMA configuration **************************************/ DMA_DeInit(DMA_STREAMx); - DMA_InitStructure.DMA_Channel = DMA_CHANNELx; + DMA_InitStructure.DMA_Channel = DMA_CHANNELx; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADCx_DR_ADDRESS; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)adc_buf; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; @@ -167,7 +167,7 @@ void adc_configure() { DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; - DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; + DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; @@ -195,7 +195,7 @@ void adc_configure() { NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); + NVIC_Init(&NVIC_InitStructure); // Enable and start ADC conversion @@ -249,10 +249,10 @@ void DMA2_Stream0_IRQHandler(void) { } else fifo_write(adc1_fifo, (short*)adc_buf, ADC_TUNER_BUF_SZ/2); - + /* Clear DMA Stream Transfer Complete interrupt pending bit */ - DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_HTIF0); + DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_HTIF0); } /* Transfer complete interrupt */ @@ -271,10 +271,10 @@ void DMA2_Stream0_IRQHandler(void) { } else fifo_write(adc1_fifo, (short*)&adc_buf[ADC_TUNER_BUF_SZ/2], ADC_TUNER_BUF_SZ/2); - + /* Clear DMA Stream Transfer Complete interrupt pending bit */ - DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0); + DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0); } GPIOE->ODR &= ~(1 << 0); diff --git a/codec2-dev/stm32/src/stm32f4_dac.c b/codec2-dev/stm32/src/stm32f4_dac.c index cba9ea79..f78004da 100644 --- a/codec2-dev/stm32/src/stm32f4_dac.c +++ b/codec2-dev/stm32/src/stm32f4_dac.c @@ -34,7 +34,7 @@ #include "stm32f4_dac.h" #include "debugblinky.h" -/* write to these registers for 12 bit left aligned data, as per data sheet +/* write to these registers for 12 bit left aligned data, as per data sheet make sure 4 least sig bits set to 0 */ #define DAC_DHR12R1_ADDRESS 0x40007408 @@ -79,7 +79,7 @@ void dac_open(int fifo_size) { /* DMA1 clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); /* GPIOA clock enable (to be used with DAC) */ - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); /* DAC Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); @@ -93,7 +93,7 @@ void dac_open(int fifo_size) { /* Timer and DAC 1 & 2 Configuration ----------------------------------------*/ - tim6_config(); + tim6_config(); dac1_config(); dac2_config(); @@ -103,11 +103,11 @@ void dac_open(int fifo_size) { /* Call these puppies to send samples to the DACs. For your convenience they accept signed 16 bit samples. */ -int dac1_write(short buf[], int n) { +int dac1_write(short buf[], int n) { return fifo_write(dac1_fifo, buf, n); } -int dac2_write(short buf[], int n) { +int dac2_write(short buf[], int n) { return fifo_write(dac2_fifo, buf, n); } @@ -125,31 +125,31 @@ static void tim6_config(void) /* TIM6 Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE); - + /* -------------------------------------------------------- - + TIM6 input clock (TIM6CLK) is set to 2 * APB1 clock (PCLK1), since APB1 prescaler is different from 1 (see system_stm32f4xx.c and Fig 13 clock tree figure in DM0031020.pdf). - Sample rate Fs = 2*PCLK1/TIM_ClockDivision + Sample rate Fs = 2*PCLK1/TIM_ClockDivision = (HCLK/2)/TIM_ClockDivision - + ----------------------------------------------------------- */ /* Time base configuration */ - TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); - TIM_TimeBaseStructure.TIM_Period = 5250; - TIM_TimeBaseStructure.TIM_Prescaler = 0; - TIM_TimeBaseStructure.TIM_ClockDivision = 0; - TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); + TIM_TimeBaseStructure.TIM_Period = 5250; + TIM_TimeBaseStructure.TIM_Prescaler = 0; + TIM_TimeBaseStructure.TIM_ClockDivision = 0; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure); /* TIM6 TRGO selection */ TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update); - + /* TIM6 enable counter */ TIM_Cmd(TIM6, ENABLE); @@ -160,19 +160,19 @@ static void dac1_config(void) DAC_InitTypeDef DAC_InitStructure; DMA_InitTypeDef DMA_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; - + /* DAC channel 1 Configuration */ - /* + /* This line fixed a bug that cost me 5 days, bad wave amplitude value, and some STM32F4 periph library bugs caused triangle wave geneartion to be enable resulting in a low level tone on the SM1000, that we thought was caused by analog issues like layour or power supply biasing */ - DAC_StructInit(&DAC_InitStructure); + DAC_StructInit(&DAC_InitStructure); - DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO; + DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; DAC_Init(DAC_Channel_1, &DAC_InitStructure); @@ -181,7 +181,7 @@ static void dac1_config(void) /* Table 35 page 219 of the monster data sheet */ DMA_DeInit(DMA1_Stream5); - DMA_InitStructure.DMA_Channel = DMA_Channel_7; + DMA_InitStructure.DMA_Channel = DMA_Channel_7; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)DAC_DHR12R1_ADDRESS; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)dac1_buf; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; @@ -192,7 +192,7 @@ static void dac1_config(void) DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; - DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; + DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; @@ -208,7 +208,7 @@ static void dac1_config(void) NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); + NVIC_Init(&NVIC_InitStructure); /* Enable DMA1_Stream5 */ @@ -228,7 +228,7 @@ static void dac2_config(void) DAC_InitTypeDef DAC_InitStructure; DMA_InitTypeDef DMA_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; - + /* DAC channel 2 Configuration (see notes in dac1_config() above) */ DAC_StructInit(&DAC_InitStructure); @@ -240,7 +240,7 @@ static void dac2_config(void) /* DMA1_Stream6 channel7 configuration **************************************/ DMA_DeInit(DMA1_Stream6); - DMA_InitStructure.DMA_Channel = DMA_Channel_7; + DMA_InitStructure.DMA_Channel = DMA_Channel_7; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)DAC_DHR12R2_ADDRESS; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)dac2_buf; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; @@ -251,7 +251,7 @@ static void dac2_config(void) DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; - DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; + DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; @@ -267,7 +267,7 @@ static void dac2_config(void) NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); + NVIC_Init(&NVIC_InitStructure); /* Enable DMA1_Stream6 */ @@ -319,7 +319,7 @@ void DMA1_Stream5_IRQHandler(void) { /* Clear DMA Stream Transfer Complete interrupt pending bit */ - DMA_ClearITPendingBit(DMA1_Stream5, DMA_IT_HTIF5); + DMA_ClearITPendingBit(DMA1_Stream5, DMA_IT_HTIF5); } /* Transfer complete interrupt - refill 2nd half */ @@ -341,7 +341,7 @@ void DMA1_Stream5_IRQHandler(void) { /* Clear DMA Stream Transfer Complete interrupt pending bit */ - DMA_ClearITPendingBit(DMA1_Stream5, DMA_IT_TCIF5); + DMA_ClearITPendingBit(DMA1_Stream5, DMA_IT_TCIF5); } GPIOE->ODR &= ~(1 << 1); @@ -376,7 +376,7 @@ void DMA1_Stream6_IRQHandler(void) { /* Clear DMA Stream Transfer Complete interrupt pending bit */ - DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_HTIF6); + DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_HTIF6); } /* Transfer complete interrupt - refill 2nd half */ @@ -398,7 +398,7 @@ void DMA1_Stream6_IRQHandler(void) { /* Clear DMA Stream Transfer Complete interrupt pending bit */ - DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_TCIF6); + DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_TCIF6); } GPIOE->ODR &= ~(1 << 2); diff --git a/codec2-dev/stm32/src/stm32f4_dacduc.c b/codec2-dev/stm32/src/stm32f4_dacduc.c index da2dc459..2c519095 100644 --- a/codec2-dev/stm32/src/stm32f4_dacduc.c +++ b/codec2-dev/stm32/src/stm32f4_dacduc.c @@ -32,8 +32,8 @@ #include "codec2_fifo.h" #include "stm32f4_dacduc.h" #include "debugblinky.h" - -/* write to these registers for 12 bit left aligned data, as per data sheet + +/* write to these registers for 12 bit left aligned data, as per data sheet make sure 4 least sig bits set to 0 */ #define DAC_DHR12R1_ADDRESS 0x40007408 @@ -80,7 +80,7 @@ void fast_dac_open(int dac1_fifo_size,int dac2_fifo_size) { /* DMA1 clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); /* GPIOA clock enable (to be used with DAC) */ - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); /* DAC Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); @@ -94,7 +94,7 @@ void fast_dac_open(int dac1_fifo_size,int dac2_fifo_size) { /* Timer and DAC 1 & 2 Configuration ----------------------------------------*/ tim7_config(); - tim6_config(); + tim6_config(); dac1_config(); dac2_config(); @@ -105,11 +105,11 @@ void fast_dac_open(int dac1_fifo_size,int dac2_fifo_size) { /* Call these puppies to send samples to the DACs. For your convenience they accept signed 16 bit samples. */ -int dac1_write(short buf[], int n) { +int dac1_write(short buf[], int n) { return fifo_write(dac1_fifo, buf, n); } -int dac2_write(short buf[], int n) { +int dac2_write(short buf[], int n) { return fifo_write(dac2_fifo, buf, n); } @@ -119,31 +119,31 @@ static void tim6_config(void) /* TIM6 Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE); - + /* -------------------------------------------------------- - + TIM6 input clock (TIM6CLK) is set to 2 * APB1 clock (PCLK1), since APB1 prescaler is different from 1 (see system_stm32f4xx.c and Fig 13 clock tree figure in DM0031020.pdf). - Sample rate Fs = 2*PCLK1/TIM_ClockDivision + Sample rate Fs = 2*PCLK1/TIM_ClockDivision = (HCLK/2)/TIM_ClockDivision - + ----------------------------------------------------------- */ /* Time base configuration */ - TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); - TIM_TimeBaseStructure.TIM_Period = 5250; - TIM_TimeBaseStructure.TIM_Prescaler = 0; - TIM_TimeBaseStructure.TIM_ClockDivision = 0; - TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); + TIM_TimeBaseStructure.TIM_Period = 5250; + TIM_TimeBaseStructure.TIM_Prescaler = 0; + TIM_TimeBaseStructure.TIM_ClockDivision = 0; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure); /* TIM6 TRGO selection */ TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update); - + /* TIM6 enable counter */ TIM_Cmd(TIM6, ENABLE); @@ -159,32 +159,32 @@ void tim7_config(void) /* TIM7 Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE); - + /* -------------------------------------------------------- - + TIM7 input clock (TIM7CLK) is set to 2 * APB1 clock (PCLK1), since APB1 prescaler is different from 1 (see system_stm32f4xx.c and Fig 13 clock tree figure in DM0031020.pdf). - Sample rate Fs = 2*PCLK1/TIM_ClockDivision + Sample rate Fs = 2*PCLK1/TIM_ClockDivision = (HCLK/2)/TIM_ClockDivision - + ----------------------------------------------------------- */ /* Time base configuration */ - TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); - TIM_TimeBaseStructure.TIM_Period = 41; - TIM_TimeBaseStructure.TIM_Prescaler = 0; - TIM_TimeBaseStructure.TIM_ClockDivision = 0; - TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); + TIM_TimeBaseStructure.TIM_Period = 41; + TIM_TimeBaseStructure.TIM_Prescaler = 0; + TIM_TimeBaseStructure.TIM_ClockDivision = 0; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM7, &TIM_TimeBaseStructure); /* TIM7 TRGO selection */ TIM_SelectOutputTrigger(TIM7, TIM_TRGOSource_Update); - + /* TIM7 enable counter */ TIM_Cmd(TIM7, ENABLE); @@ -195,19 +195,19 @@ static void dac1_config(void) DAC_InitTypeDef DAC_InitStructure; DMA_InitTypeDef DMA_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; - + /* DAC channel 1 Configuration */ - /* + /* This line fixed a bug that cost me 5 days, bad wave amplitude value, and some STM32F4 periph library bugs caused triangle wave geneartion to be enable resulting in a low level tone on the SM1000, that we thought was caused by analog issues like layour or power supply biasing */ - DAC_StructInit(&DAC_InitStructure); + DAC_StructInit(&DAC_InitStructure); - DAC_InitStructure.DAC_Trigger = DAC_Trigger_T7_TRGO; + DAC_InitStructure.DAC_Trigger = DAC_Trigger_T7_TRGO; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; /*External buffering is needed to get nice square samples at Fs=2Mhz. See DM00129215.pdf */ @@ -218,7 +218,7 @@ static void dac1_config(void) /* Table 35 page 219 of the monster data sheet */ DMA_DeInit(DMA1_Stream5); - DMA_InitStructure.DMA_Channel = DMA_Channel_7; + DMA_InitStructure.DMA_Channel = DMA_Channel_7; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)DAC_DHR12R1_ADDRESS; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)dac1_buf; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; @@ -229,7 +229,7 @@ static void dac1_config(void) DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; - DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; + DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; @@ -245,7 +245,7 @@ static void dac1_config(void) NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); + NVIC_Init(&NVIC_InitStructure); /* Enable DMA1_Stream5 */ @@ -265,7 +265,7 @@ static void dac2_config(void) DAC_InitTypeDef DAC_InitStructure; DMA_InitTypeDef DMA_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; - + /* DAC channel 2 Configuration (see notes in dac1_config() above) */ DAC_StructInit(&DAC_InitStructure); @@ -277,7 +277,7 @@ static void dac2_config(void) /* DMA1_Stream6 channel7 configuration **************************************/ DMA_DeInit(DMA1_Stream6); - DMA_InitStructure.DMA_Channel = DMA_Channel_7; + DMA_InitStructure.DMA_Channel = DMA_Channel_7; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)DAC_DHR12R2_ADDRESS; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)dac2_buf; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; @@ -288,7 +288,7 @@ static void dac2_config(void) DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; - DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; + DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; @@ -304,7 +304,7 @@ static void dac2_config(void) NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); + NVIC_Init(&NVIC_InitStructure); /* Enable DMA1_Stream6 */ @@ -341,7 +341,7 @@ void DMA1_Stream5_IRQHandler(void) { fifo_read(dac1_fifo, (short*)dac1_buf, DAC_DUC_BUF_SZ/2); /* Clear DMA Stream Transfer Complete interrupt pending bit */ - DMA_ClearITPendingBit(DMA1_Stream5, DMA_IT_HTIF5); + DMA_ClearITPendingBit(DMA1_Stream5, DMA_IT_HTIF5); } /* Transfer complete interrupt - refill 2nd half */ @@ -351,7 +351,7 @@ void DMA1_Stream5_IRQHandler(void) { fifo_read(dac1_fifo, (short*)(dac1_buf+DAC_DUC_BUF_SZ/2), DAC_DUC_BUF_SZ/2); /* Clear DMA Stream Transfer Complete interrupt pending bit */ - DMA_ClearITPendingBit(DMA1_Stream5, DMA_IT_TCIF5); + DMA_ClearITPendingBit(DMA1_Stream5, DMA_IT_TCIF5); } GPIOE->ODR &= ~(1 << 1); @@ -386,7 +386,7 @@ void DMA1_Stream6_IRQHandler(void) { /* Clear DMA Stream Transfer Complete interrupt pending bit */ - DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_HTIF6); + DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_HTIF6); } /* Transfer complete interrupt - refill 2nd half */ @@ -408,7 +408,7 @@ void DMA1_Stream6_IRQHandler(void) { /* Clear DMA Stream Transfer Complete interrupt pending bit */ - DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_TCIF6); + DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_TCIF6); } GPIOE->ODR &= ~(1 << 2); diff --git a/codec2-dev/stm32/src/stm32f4_machdep.c b/codec2-dev/stm32/src/stm32f4_machdep.c index 5dd39c4c..76b8fb63 100644 --- a/codec2-dev/stm32/src/stm32f4_machdep.c +++ b/codec2-dev/stm32/src/stm32f4_machdep.c @@ -31,10 +31,10 @@ #include "machdep.h" #include "gdb_stdio.h" -volatile unsigned int *DWT_CYCCNT = (volatile unsigned int *)0xE0001004; +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 @@ -43,12 +43,12 @@ 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; @@ -83,4 +83,4 @@ void machdep_profile_print_logged_samples(void) gdb_stdio_printf("%s", buf); *buf = 0; } - + diff --git a/codec2-dev/stm32/src/stm32f4_pwm.c b/codec2-dev/stm32/src/stm32f4_pwm.c index 2d467e00..acbaab98 100644 --- a/codec2-dev/stm32/src/stm32f4_pwm.c +++ b/codec2-dev/stm32/src/stm32f4_pwm.c @@ -35,7 +35,7 @@ #include "stm32f4xx_gpio.h" #include "stm32f4xx_rcc.h" - + #define TIM1_CCR3_ADDRESS 0x4001003C //#define TIM1_CCR3_ADDRESS 0x4001223C #define SINE_SAMPLES 32 @@ -78,7 +78,7 @@ static void TIM_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; DMA_InitTypeDef DMA_InitStructure; - + /* GPIOA and GPIOB clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB, ENABLE); @@ -89,7 +89,7 @@ static void TIM_Config(void) GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ; - GPIO_Init(GPIOA, &GPIO_InitStructure); + GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_TIM1); /* GPIOB Configuration: Channel 3N as alternate function push-pull */ @@ -103,7 +103,7 @@ static void TIM_Config(void) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 , ENABLE); DMA_DeInit(DMA2_Stream6); - DMA_InitStructure.DMA_Channel = DMA_Channel_6; + DMA_InitStructure.DMA_Channel = DMA_Channel_6; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(TIM1_CCR3_ADDRESS) ; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)aSRC_Buffer; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; @@ -131,13 +131,13 @@ void Timer1Config() { TIM_Config(); /* TIM1 example ------------------------------------------------- - - TIM1 input clock (TIM1CLK) is set to 2 * APB2 clock (PCLK2), since APB2 - prescaler is different from 1. - TIM1CLK = 2 * PCLK2 - PCLK2 = HCLK / 2 + + TIM1 input clock (TIM1CLK) is set to 2 * APB2 clock (PCLK2), since APB2 + prescaler is different from 1. + TIM1CLK = 2 * PCLK2 + PCLK2 = HCLK / 2 => TIM1CLK = 2 * (HCLK / 2) = HCLK = SystemCoreClock - + TIM1CLK = SystemCoreClock, Prescaler = 0, TIM1 counter clock = SystemCoreClock SystemCoreClock is set to 168 MHz for STM32F4xx devices. @@ -146,16 +146,16 @@ void Timer1Config() { - TIM1_Period = (SystemCoreClock / F) - 1 The number of this repetitive requests is defined by the TIM1 Repetion counter, - each 3 Update Requests, the TIM1 Channel 3 Duty Cycle changes to the next new + each 3 Update Requests, the TIM1 Channel 3 Duty Cycle changes to the next new value defined by the aSRC_Buffer. - - Note: + + Note: SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file. Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate() function to update SystemCoreClock variable value. Otherwise, any configuration - based on this variable will be incorrect. + based on this variable will be incorrect. -----------------------------------------------------------------------------*/ - + /* Compute the value to be set in ARR regiter to generate signal frequency at FS */ #ifdef TMP @@ -170,7 +170,7 @@ void Timer1Config() { #else uhTimerPeriod = (SystemCoreClock / 28000000) - 1; aSRC_Buffer[0] = uhTimerPeriod/2 + 1; - + #endif /* TIM1 clock enable */ @@ -224,13 +224,13 @@ void Timer1Config() { //TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable); #endif - + /* TIM1 counter enable */ TIM_Cmd(TIM1, ENABLE); - + /* DMA enable*/ //DMA_Cmd(DMA2_Stream6, ENABLE); - + /* TIM1 Update DMA Request enable */ //TIM_DMACmd(TIM1, TIM_DMA_CC3, ENABLE); diff --git a/codec2-dev/stm32/src/system_stm32f4xx.c b/codec2-dev/stm32/src/system_stm32f4xx.c index 08f36260..b26dd207 100644 --- a/codec2-dev/stm32/src/system_stm32f4xx.c +++ b/codec2-dev/stm32/src/system_stm32f4xx.c @@ -147,7 +147,7 @@ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ -#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field. +#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /******************************************************************************/ @@ -465,16 +465,16 @@ void SystemInit_ExtMemCtl(void) +-------------------+--------------------+------------------+------------------+ + SRAM pins assignment + +-------------------+--------------------+------------------+------------------+ - | PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 | - | PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 | - | PD4 <-> FSMC_NOE | PE3 <-> FSMC_A19 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 | - | PD5 <-> FSMC_NWE | PE4 <-> FSMC_A20 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 | - | PD8 <-> FSMC_D13 | PE7 <-> FSMC_D4 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 | - | PD9 <-> FSMC_D14 | PE8 <-> FSMC_D5 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 | - | PD10 <-> FSMC_D15 | PE9 <-> FSMC_D6 | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 | + | PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 | + | PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 | + | PD4 <-> FSMC_NOE | PE3 <-> FSMC_A19 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 | + | PD5 <-> FSMC_NWE | PE4 <-> FSMC_A20 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 | + | PD8 <-> FSMC_D13 | PE7 <-> FSMC_D4 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 | + | PD9 <-> FSMC_D14 | PE8 <-> FSMC_D5 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 | + | PD10 <-> FSMC_D15 | PE9 <-> FSMC_D6 | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 | | PD11 <-> FSMC_A16 | PE10 <-> FSMC_D7 | PF13 <-> FSMC_A7 |------------------+ - | PD12 <-> FSMC_A17 | PE11 <-> FSMC_D8 | PF14 <-> FSMC_A8 | - | PD13 <-> FSMC_A18 | PE12 <-> FSMC_D9 | PF15 <-> FSMC_A9 | + | PD12 <-> FSMC_A17 | PE11 <-> FSMC_D8 | PF14 <-> FSMC_A8 | + | PD13 <-> FSMC_A18 | PE12 <-> FSMC_D9 | PF15 <-> FSMC_A9 | | PD14 <-> FSMC_D0 | PE13 <-> FSMC_D10 |------------------+ | PD15 <-> FSMC_D1 | PE14 <-> FSMC_D11 | | | PE15 <-> FSMC_D12 | @@ -555,7 +555,7 @@ void SystemInit_ExtMemCtl(void) FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM; FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; - FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; + FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; diff --git a/codec2-dev/stm32/src/timer_ut.c b/codec2-dev/stm32/src/timer_ut.c index 967c87df..1e9dcc4b 100644 --- a/codec2-dev/stm32/src/timer_ut.c +++ b/codec2-dev/stm32/src/timer_ut.c @@ -31,7 +31,7 @@ #include "stm32f4xx_gpio.h" #include "stm32f4xx_rcc.h" - + #include "gdb_stdio.h" #define TIM1_CCR3_ADDRESS 0x4001223C @@ -61,7 +61,7 @@ int main(void){ static void TIM_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; - + /* GPIOA and GPIOB clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB, ENABLE); @@ -73,7 +73,7 @@ static void TIM_Config(void) GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ; - GPIO_Init(GPIOA, &GPIO_InitStructure); + GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_TIM1); /* GPIOB Configuration: Channel 3N as alternate function push-pull */ @@ -91,13 +91,13 @@ void Timer1Config() { TIM_Config(); /* TIM1 example ------------------------------------------------- - - TIM1 input clock (TIM1CLK) is set to 2 * APB2 clock (PCLK2), since APB2 - prescaler is different from 1. - TIM1CLK = 2 * PCLK2 - PCLK2 = HCLK / 2 + + TIM1 input clock (TIM1CLK) is set to 2 * APB2 clock (PCLK2), since APB2 + prescaler is different from 1. + TIM1CLK = 2 * PCLK2 + PCLK2 = HCLK / 2 => TIM1CLK = 2 * (HCLK / 2) = HCLK = SystemCoreClock - + TIM1CLK = SystemCoreClock, Prescaler = 0, TIM1 counter clock = SystemCoreClock SystemCoreClock is set to 168 MHz for STM32F4xx devices. @@ -106,16 +106,16 @@ void Timer1Config() { - TIM1_Period = (SystemCoreClock / F) - 1 The number of this repetitive requests is defined by the TIM1 Repetion counter, - each 3 Update Requests, the TIM1 Channel 3 Duty Cycle changes to the next new + each 3 Update Requests, the TIM1 Channel 3 Duty Cycle changes to the next new value defined by the aSRC_Buffer. - - Note: + + Note: SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file. Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate() function to update SystemCoreClock variable value. Otherwise, any configuration - based on this variable will be incorrect. + based on this variable will be incorrect. -----------------------------------------------------------------------------*/ - + /* Compute the value to be set in ARR regiter to generate signal frequency at FS Hz */ uhTimerPeriod = (SystemCoreClock / FS ) - 1; /* Compute CCR1 value to generate a duty cycle at 50% */ @@ -158,7 +158,7 @@ void Timer1Config() { /* Enable preload feature */ TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable); - + /* Automatic Output enable, Break, dead time and lock configuration*/ TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable; TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable; @@ -172,7 +172,7 @@ void Timer1Config() { /* TIM1 counter enable */ TIM_Cmd(TIM1, ENABLE); - + /* Main Output Enable */ TIM_CtrlPWMOutputs(TIM1, ENABLE); } diff --git a/codec2-dev/stm32/src/tone.h b/codec2-dev/stm32/src/tone.h index a8ed89a9..b7441ca4 100644 --- a/codec2-dev/stm32/src/tone.h +++ b/codec2-dev/stm32/src/tone.h @@ -16,7 +16,7 @@ * The samples are retrieved by repeatedly calling tone_next. This * advances 'time' and decrements 'remain'. The tone is complete when * 'remain' is zero. - * + * * Author Stuart Longland * Copyright (C) 2015 FreeDV project. * diff --git a/codec2-dev/stm32/src/tuner_ut.c b/codec2-dev/stm32/src/tuner_ut.c index 0bd590d2..9c752c0e 100644 --- a/codec2-dev/stm32/src/tuner_ut.c +++ b/codec2-dev/stm32/src/tuner_ut.c @@ -59,7 +59,7 @@ int main(void) { bufs = FS*REC_TIME_SECS/N; fifo_sz = ((4*N/ADC_TUNER_N)+1)*ADC_TUNER_N; printf("Starting! bufs: %d %d\n", bufs, fifo_sz); - + //dac_open(DAC_BUF_SZ); adc_open(fifo_sz); sm1000_leds_switches_init(); diff --git a/codec2-dev/stm32/src/usb_vcp_ut.c b/codec2-dev/stm32/src/usb_vcp_ut.c index 74aa59e4..87ad9b8b 100644 --- a/codec2-dev/stm32/src/usb_vcp_ut.c +++ b/codec2-dev/stm32/src/usb_vcp_ut.c @@ -14,7 +14,7 @@ When I fired up Minicom, it echoed characters: $ sudo minicom -D /dev/ttyACM0 - + \*---------------------------------------------------------------------------*/ #include diff --git a/codec2-dev/stm32/stlink/elfsym.c b/codec2-dev/stm32/stlink/elfsym.c index 1a62981b..f2d6ab51 100644 --- a/codec2-dev/stm32/stlink/elfsym.c +++ b/codec2-dev/stm32/stlink/elfsym.c @@ -28,7 +28,7 @@ int elfsym_open(char file[]) { int fd; /* File Descriptor */ char *base_ptr; /* ptr to our object in memory */ struct stat elf_stats; /* fstat struct */ - + if((fd = open(file, O_RDWR)) == ERR) { printf("couldnt open %s\n", file); return ERR; @@ -92,7 +92,7 @@ unsigned int elfsym_get_symbol_address(int fd, char symbol_name[]) while((scn = elf_nextscn(elf, scn)) != 0) { gelf_getshdr(scn, &shdr); - + // When we find a section header marked SHT_SYMTAB stop and get symbols edata = NULL; if(shdr.sh_type == SHT_SYMTAB) { @@ -104,10 +104,10 @@ unsigned int elfsym_get_symbol_address(int fd, char symbol_name[]) symbol_count = shdr.sh_size / shdr.sh_entsize; // loop through to grab all symbols - for(i = 0; i < symbol_count; i++) { + for(i = 0; i < symbol_count; i++) { // libelf grabs the symbol data using gelf_getsym() gelf_getsym(edata, i, &sym); - + if (strcmp(symbol_name, elf_strptr(elf, shdr.sh_link, sym.st_name)) == 0) { symbol_address = sym.st_value; diff --git a/codec2-dev/stm32/usb_conf/usb_bsp.h b/codec2-dev/stm32/usb_conf/usb_bsp.h index 0584e9b9..736f3d02 100644 --- a/codec2-dev/stm32/usb_conf/usb_bsp.h +++ b/codec2-dev/stm32/usb_conf/usb_bsp.h @@ -30,46 +30,46 @@ /** @addtogroup USB_OTG_DRIVER * @{ */ - + /** @defgroup USB_BSP - * @brief This file is the + * @brief This file is the * @{ - */ + */ /** @defgroup USB_BSP_Exported_Defines * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_BSP_Exported_Types * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_BSP_Exported_Macros * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_BSP_Exported_Variables * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_BSP_Exported_FunctionsPrototype * @{ - */ + */ void BSP_Init(void); void USB_OTG_BSP_Init (USB_OTG_CORE_HANDLE *pdev); @@ -82,16 +82,16 @@ void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE *pdev,uint8_t state); #endif /** * @} - */ + */ #endif //__USB_BSP__H__ /** * @} - */ + */ /** * @} - */ + */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_conf/usb_conf.h b/codec2-dev/stm32/usb_conf/usb_conf.h index 736e6492..3d246b21 100644 --- a/codec2-dev/stm32/usb_conf/usb_conf.h +++ b/codec2-dev/stm32/usb_conf/usb_conf.h @@ -30,15 +30,15 @@ /** @addtogroup USB_OTG_DRIVER * @{ */ - + /** @defgroup USB_CONF * @brief USB low level driver configuration file * @{ - */ + */ /** @defgroup USB_CONF_Exported_Defines * @{ - */ + */ /* USB Core and PHY interface configuration. Tip: To avoid modifying these defines each time you need to change the USB @@ -66,7 +66,7 @@ #endif /* USE_I2C_PHY */ -#ifdef USE_USB_OTG_FS +#ifdef USE_USB_OTG_FS #define USB_OTG_FS_CORE #endif @@ -76,35 +76,35 @@ /******************************************************************************* * FIFO Size Configuration in Device mode -* -* (i) Receive data FIFO size = RAM for setup packets + +* +* (i) Receive data FIFO size = RAM for setup packets + * OUT endpoint control information + * data OUT packets + miscellaneous * Space = ONE 32-bits words * --> RAM for setup packets = 10 spaces -* (n is the nbr of CTRL EPs the device core supports) +* (n is the nbr of CTRL EPs the device core supports) * --> OUT EP CTRL info = 1 space -* (one space for status information written to the FIFO along with each +* (one space for status information written to the FIFO along with each * received packet) -* --> data OUT packets = (Largest Packet Size / 4) + 1 spaces +* --> data OUT packets = (Largest Packet Size / 4) + 1 spaces * (MINIMUM to receive packets) -* --> OR data OUT packets = at least 2*(Largest Packet Size / 4) + 1 spaces +* --> OR data OUT packets = at least 2*(Largest Packet Size / 4) + 1 spaces * (if high-bandwidth EP is enabled or multiple isochronous EPs) * --> miscellaneous = 1 space per OUT EP -* (one space for transfer complete status information also pushed to the +* (one space for transfer complete status information also pushed to the * FIFO with each endpoint's last packet) * -* (ii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for +* (ii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for * that particular IN EP. More space allocated in the IN EP Tx FIFO results * in a better performance on the USB and can hide latencies on the AHB. * * (iii) TXn min size = 16 words. (n : Transmit FIFO index) -* (iv) When a TxFIFO is not used, the Configuration should be as follows: +* (iv) When a TxFIFO is not used, the Configuration should be as follows: * case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes) * --> Txm can use the space allocated for Txn. * case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes) * --> Txn should be configured with the minimum space of 16 words -* (v) The FIFO is used optimally when used TxFIFOs are allocated in the top +* (v) The FIFO is used optimally when used TxFIFOs are allocated in the top * of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones. *******************************************************************************/ @@ -126,7 +126,7 @@ * then the space must be at least two times the maximum packet size for * that channel. *******************************************************************************/ - + /****************** USB OTG HS CONFIGURATION **********************************/ #ifdef USB_OTG_HS_CORE #define RX_FIFO_HS_SIZE 512 @@ -207,24 +207,24 @@ /****************** C Compilers dependant keywords ****************************/ /* In HS mode and when the DMA is used, all variables and data structures dealing - with the DMA during the transaction process should be 4-bytes aligned */ + with the DMA during the transaction process should be 4-bytes aligned */ #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined (__GNUC__) /* GNU Compiler */ #define __ALIGN_END __attribute__ ((aligned (4))) - #define __ALIGN_BEGIN - #else + #define __ALIGN_BEGIN + #else #define __ALIGN_END #if defined (__CC_ARM) /* ARM Compiler */ - #define __ALIGN_BEGIN __align(4) + #define __ALIGN_BEGIN __align(4) #elif defined (__ICCARM__) /* IAR Compiler */ - #define __ALIGN_BEGIN + #define __ALIGN_BEGIN #elif defined (__TASKING__) /* TASKING Compiler */ - #define __ALIGN_BEGIN __align(4) - #endif /* __CC_ARM */ - #endif /* __GNUC__ */ + #define __ALIGN_BEGIN __align(4) + #endif /* __CC_ARM */ + #endif /* __GNUC__ */ #else #define __ALIGN_BEGIN - #define __ALIGN_END + #define __ALIGN_END #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* __packed keyword used to decrease the data type alignment to 1-byte */ @@ -232,7 +232,7 @@ #define __packed __packed #elif defined (__ICCARM__) /* IAR Compiler */ #define __packed __packed -#elif defined ( __GNUC__ ) /* GNU Compiler */ +#elif defined ( __GNUC__ ) /* GNU Compiler */ #define __packed __attribute__ ((__packed__)) #elif defined (__TASKING__) /* TASKING Compiler */ #define __packed __unaligned @@ -240,37 +240,37 @@ /** * @} - */ + */ /** @defgroup USB_CONF_Exported_Types * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_CONF_Exported_Macros * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_CONF_Exported_Variables * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_CONF_Exported_FunctionsPrototype * @{ - */ + */ /** * @} - */ + */ #endif //__USB_CONF__H__ @@ -278,10 +278,10 @@ /** * @} - */ + */ /** * @} - */ + */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_conf/usbd_conf.h b/codec2-dev/stm32/usb_conf/usbd_conf.h index 0ecf0b34..cb08d455 100644 --- a/codec2-dev/stm32/usb_conf/usbd_conf.h +++ b/codec2-dev/stm32/usb_conf/usbd_conf.h @@ -25,14 +25,14 @@ /** @defgroup USB_CONF_Exported_Defines * @{ - */ + */ #define USBD_CFG_MAX_NUM 1 #define USBD_ITF_MAX_NUM 1 -#define USB_MAX_STR_DESC_SIZ 100 +#define USB_MAX_STR_DESC_SIZ 100 /** @defgroup USB_VCP_Class_Layer_Parameter * @{ - */ + */ #define CDC_IN_EP 0x81 /* EP1 for data IN */ #define CDC_OUT_EP 0x01 /* EP1 for data OUT */ #define CDC_CMD_EP 0x82 /* EP2 for CDC commands */ @@ -43,50 +43,50 @@ #define CDC_CMD_PACKET_SZE 8 /* Control Endpoint Packet size */ #define CDC_IN_FRAME_INTERVAL 40 /* Number of micro-frames between IN transfers */ - #define APP_RX_DATA_SIZE 2048 /* Total size of IN buffer: + #define APP_RX_DATA_SIZE 2048 /* Total size of IN buffer: APP_RX_DATA_SIZE*8/MAX_BAUDARATE*1000 should be > CDC_IN_FRAME_INTERVAL*8 */ #else #define CDC_DATA_MAX_PACKET_SIZE 64 /* Endpoint IN & OUT Packet size */ #define CDC_CMD_PACKET_SZE 8 /* Control Endpoint Packet size */ #define CDC_IN_FRAME_INTERVAL 5 /* Number of frames between IN transfers */ - #define APP_RX_DATA_SIZE 2048 /* Total size of IN buffer: + #define APP_RX_DATA_SIZE 2048 /* Total size of IN buffer: APP_RX_DATA_SIZE*8/MAX_BAUDARATE*1000 should be > CDC_IN_FRAME_INTERVAL */ #endif /* USE_USB_OTG_HS */ #define APP_FOPS VCP_fops /** * @} - */ + */ /** @defgroup USB_CONF_Exported_Types * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_CONF_Exported_Macros * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_CONF_Exported_Variables * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_CONF_Exported_FunctionsPrototype * @{ - */ + */ /** * @} - */ + */ #endif //__USBD_CONF__H__ diff --git a/codec2-dev/stm32/usb_conf/usbd_desc.c b/codec2-dev/stm32/usb_conf/usbd_desc.c index 36930303..c2526337 100644 --- a/codec2-dev/stm32/usb_conf/usbd_desc.c +++ b/codec2-dev/stm32/usb_conf/usbd_desc.c @@ -17,7 +17,7 @@ * *

© COPYRIGHT 2011 STMicroelectronics

****************************************************************************** - */ + */ /* Includes ------------------------------------------------------------------*/ #include @@ -32,22 +32,22 @@ */ -/** @defgroup USBD_DESC +/** @defgroup USBD_DESC * @brief USBD descriptors module * @{ - */ + */ /** @defgroup USBD_DESC_Private_TypesDefinitions * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_DESC_Private_Defines * @{ - */ + */ #define USBD_VID 0x0483 @@ -55,7 +55,7 @@ /** @defgroup USB_String_Descriptors * @{ - */ + */ #define USBD_LANGID_STRING 0x409 #define USBD_MANUFACTURER_STRING "STMicroelectronics" @@ -72,36 +72,36 @@ #define USBD_INTERFACE_FS_STRING "VCP Interface" /** * @} - */ + */ /** @defgroup USBD_DESC_Private_Macros * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_DESC_Private_Variables * @{ - */ + */ USBD_DEVICE USR_desc = { USBD_USR_DeviceDescriptor, - USBD_USR_LangIDStrDescriptor, + USBD_USR_LangIDStrDescriptor, USBD_USR_ManufacturerStrDescriptor, USBD_USR_ProductStrDescriptor, USBD_USR_SerialStrDescriptor, USBD_USR_ConfigStrDescriptor, USBD_USR_InterfaceStrDescriptor, - + }; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 + #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* USB Standard Device Descriptor */ @@ -129,7 +129,7 @@ __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END = #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 + #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* USB Standard Device Descriptor */ @@ -149,36 +149,36 @@ __ALIGN_BEGIN uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALI #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 + #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* USB Standard Device Descriptor */ __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END = { - USB_SIZ_STRING_LANGID, - USB_DESC_TYPE_STRING, + USB_SIZ_STRING_LANGID, + USB_DESC_TYPE_STRING, LOBYTE(USBD_LANGID_STRING), - HIBYTE(USBD_LANGID_STRING), + HIBYTE(USBD_LANGID_STRING), }; /** * @} - */ + */ /** @defgroup USBD_DESC_Private_FunctionPrototypes * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_DESC_Private_Functions * @{ - */ + */ /** -* @brief USBD_USR_DeviceDescriptor +* @brief USBD_USR_DeviceDescriptor * return the device descriptor * @param speed : current device speed * @param length : pointer to data length variable @@ -191,7 +191,7 @@ uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length) } /** -* @brief USBD_USR_LangIDStrDescriptor +* @brief USBD_USR_LangIDStrDescriptor * return the LangID string descriptor * @param speed : current device speed * @param length : pointer to data length variable @@ -199,13 +199,13 @@ uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length) */ uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length) { - *length = sizeof(USBD_LangIDDesc); + *length = sizeof(USBD_LangIDDesc); return USBD_LangIDDesc; } /** -* @brief USBD_USR_ProductStrDescriptor +* @brief USBD_USR_ProductStrDescriptor * return the product string descriptor * @param speed : current device speed * @param length : pointer to data length variable @@ -213,23 +213,23 @@ uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length) */ uint8_t * USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length) { - + if(speed == 0) - { + { USBD_GetString ((uint8_t*)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length); } else { USBD_GetString ((uint8_t*)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length); } - + assert(*length < USB_MAX_STR_DESC_SIZ); return USBD_StrDesc; } /** -* @brief USBD_USR_ManufacturerStrDescriptor +* @brief USBD_USR_ManufacturerStrDescriptor * return the manufacturer string descriptor * @param speed : current device speed * @param length : pointer to data length variable @@ -243,7 +243,7 @@ uint8_t * USBD_USR_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length) } /** -* @brief USBD_USR_SerialStrDescriptor +* @brief USBD_USR_SerialStrDescriptor * return the serial number string descriptor * @param speed : current device speed * @param length : pointer to data length variable @@ -252,7 +252,7 @@ uint8_t * USBD_USR_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length) uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length) { if(speed == USB_OTG_SPEED_HIGH) - { + { USBD_GetString ((uint8_t*)USBD_SERIALNUMBER_HS_STRING, USBD_StrDesc, length); } else @@ -264,7 +264,7 @@ uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length) } /** -* @brief USBD_USR_ConfigStrDescriptor +* @brief USBD_USR_ConfigStrDescriptor * return the configuration string descriptor * @param speed : current device speed * @param length : pointer to data length variable @@ -273,7 +273,7 @@ uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length) uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length) { if(speed == USB_OTG_SPEED_HIGH) - { + { USBD_GetString ((uint8_t*)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length); } else @@ -281,12 +281,12 @@ uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length) USBD_GetString ((uint8_t*)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length); } assert(*length < USB_MAX_STR_DESC_SIZ); - return USBD_StrDesc; + return USBD_StrDesc; } /** -* @brief USBD_USR_InterfaceStrDescriptor +* @brief USBD_USR_InterfaceStrDescriptor * return the interface string descriptor * @param speed : current device speed * @param length : pointer to data length variable @@ -303,22 +303,22 @@ uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length) USBD_GetString ((uint8_t*)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length); } assert(*length < USB_MAX_STR_DESC_SIZ); - return USBD_StrDesc; + return USBD_StrDesc; } /** * @} - */ + */ /** * @} - */ + */ /** * @} - */ + */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_conf/usbd_desc.h b/codec2-dev/stm32/usb_conf/usbd_desc.h index ed999dc6..30c6f978 100644 --- a/codec2-dev/stm32/usb_conf/usbd_desc.h +++ b/codec2-dev/stm32/usb_conf/usbd_desc.h @@ -6,18 +6,18 @@ * @date 19-September-2011 * @brief header file for the usbd_desc.c file ****************************************************************************** - * @attention + * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * *

© COPYRIGHT 2011 STMicroelectronics

****************************************************************************** - */ + */ /* Define to prevent recursive inclusion -------------------------------------*/ @@ -30,11 +30,11 @@ /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ - + /** @defgroup USB_DESC * @brief general defines for the usb device library file * @{ - */ + */ /** @defgroup USB_DESC_Exported_Defines * @{ @@ -49,7 +49,7 @@ /** * @} - */ + */ /** @defgroup USBD_DESC_Exported_TypesDefinitions @@ -57,33 +57,33 @@ */ /** * @} - */ + */ /** @defgroup USBD_DESC_Exported_Macros * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_DESC_Exported_Variables * @{ - */ + */ extern uint8_t USBD_DeviceDesc [USB_SIZ_DEVICE_DESC]; extern uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ]; -extern uint8_t USBD_OtherSpeedCfgDesc[USB_LEN_CFG_DESC]; +extern uint8_t USBD_OtherSpeedCfgDesc[USB_LEN_CFG_DESC]; extern uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC]; extern uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID]; -extern USBD_DEVICE USR_desc; +extern USBD_DEVICE USR_desc; /** * @} - */ + */ /** @defgroup USBD_DESC_Exported_FunctionsPrototype * @{ - */ + */ uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length); @@ -95,20 +95,20 @@ uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length); uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length); #ifdef USB_SUPPORT_USER_STRING_DESC -uint8_t * USBD_USR_USRStringDesc (uint8_t speed, uint8_t idx , uint16_t *length); -#endif /* USB_SUPPORT_USER_STRING_DESC */ - +uint8_t * USBD_USR_USRStringDesc (uint8_t speed, uint8_t idx , uint16_t *length); +#endif /* USB_SUPPORT_USER_STRING_DESC */ + /** * @} - */ + */ #endif /* __USBD_DESC_H */ /** * @} - */ + */ /** * @} -*/ +*/ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_conf/usbd_usr.c b/codec2-dev/stm32/usb_conf/usbd_usr.c index 395400d2..24c5f17c 100644 --- a/codec2-dev/stm32/usb_conf/usbd_usr.c +++ b/codec2-dev/stm32/usb_conf/usbd_usr.c @@ -17,7 +17,7 @@ * *

© COPYRIGHT 2011 STMicroelectronics

****************************************************************************** - */ + */ #include "usbd_usr.h" #include "usbd_ioreq.h" @@ -29,25 +29,25 @@ USBD_Usr_cb_TypeDef USR_cb = USBD_USR_DeviceConfigured, USBD_USR_DeviceSuspended, USBD_USR_DeviceResumed, - + USBD_USR_DeviceConnected, USBD_USR_DeviceDisconnected, }; /** -* @brief USBD_USR_Init +* @brief USBD_USR_Init * Displays the message on LCD for host lib initialization * @param None * @retval None */ void USBD_USR_Init(void) -{ +{ } /** -* @brief USBD_USR_DeviceReset +* @brief USBD_USR_DeviceReset * Displays the message on LCD on device Reset Event * @param speed : device speed * @retval None @@ -56,14 +56,14 @@ void USBD_USR_DeviceReset(uint8_t speed ) { switch (speed) { - case USB_OTG_SPEED_HIGH: + case USB_OTG_SPEED_HIGH: break; - case USB_OTG_SPEED_FULL: + case USB_OTG_SPEED_FULL: break; default: break; - + } } @@ -101,7 +101,7 @@ void USBD_USR_DeviceDisconnected (void) } /** -* @brief USBD_USR_DeviceSuspended +* @brief USBD_USR_DeviceSuspended * Displays the message on LCD on device suspend Event * @param None * @retval None @@ -113,7 +113,7 @@ void USBD_USR_DeviceSuspended(void) /** -* @brief USBD_USR_DeviceResumed +* @brief USBD_USR_DeviceResumed * Displays the message on LCD on device resume Event * @param None * @retval None diff --git a/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_core.c b/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_core.c index 8d1f15d3..41b5fef8 100644 --- a/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_core.c +++ b/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_core.c @@ -4,21 +4,21 @@ * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 - * @brief This file provides the high layer firmware functions to manage the + * @brief This file provides the high layer firmware functions to manage the * following functionalities of the USB CDC Class: * - Initialization and Configuration of high and low layer * - Enumeration as CDC Device (and enumeration for each implemented memory interface) * - OUT/IN data transfer * - Command IN transfer (class requests management) * - Error management - * + * * @verbatim - * - * =================================================================== + * + * =================================================================== * CDC Class Driver Description - * =================================================================== + * =================================================================== * This driver manages the "Universal Serial Bus Class Definitions for Communications Devices - * Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus + * Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus * Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007" * This driver implements the following aspects of the specification: * - Device descriptor management @@ -33,17 +33,17 @@ * For the Abstract Control Model, this core allows only transmitting the requests to * lower layer dispatcher (ie. usbd_cdc_vcp.c/.h) which should manage each request and * perform relative actions. - * + * * These aspects may be enriched or modified for a specific user application. - * - * This driver doesn't implement the following aspects of the specification + * + * This driver doesn't implement the following aspects of the specification * (but it is possible to manage these features with some modifications on this driver): * - Any class-specific aspect relative to communication classes should be managed by user application. * - All communication classes other than PSTN are not managed - * + * * @endverbatim - * - ****************************************************************************** + * + ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS @@ -55,7 +55,7 @@ * *

© COPYRIGHT 2011 STMicroelectronics

****************************************************************************** - */ + */ /* Includes ------------------------------------------------------------------*/ #include "usbd_cdc_core.h" @@ -68,33 +68,33 @@ */ -/** @defgroup usbd_cdc +/** @defgroup usbd_cdc * @brief usbd core module * @{ - */ + */ /** @defgroup usbd_cdc_Private_TypesDefinitions * @{ - */ + */ /** * @} - */ + */ /** @defgroup usbd_cdc_Private_Defines * @{ - */ + */ /** * @} - */ + */ /** @defgroup usbd_cdc_Private_Macros * @{ - */ + */ /** * @} - */ + */ /** @defgroup usbd_cdc_Private_FunctionPrototypes @@ -117,58 +117,58 @@ static uint8_t usbd_cdc_SOF (void *pdev); *********************************************/ static void Handle_USBAsynchXfer (void *pdev); static uint8_t *USBD_cdc_GetCfgDesc (uint8_t speed, uint16_t *length); -#ifdef USE_USB_OTG_HS +#ifdef USE_USB_OTG_HS static uint8_t *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length); #endif /** * @} - */ + */ /** @defgroup usbd_cdc_Private_Variables * @{ - */ + */ extern CDC_IF_Prop_TypeDef APP_FOPS; extern uint8_t USBD_DeviceDesc [USB_SIZ_DEVICE_DESC]; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 + #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc [USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 + #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc [USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 + #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN static __IO uint32_t usbd_cdc_AltSet __ALIGN_END = 0; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 + #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t USB_Rx_Buffer [CDC_DATA_MAX_PACKET_SIZE] __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 + #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ -__ALIGN_BEGIN uint8_t APP_Rx_Buffer [APP_RX_DATA_SIZE] __ALIGN_END ; +__ALIGN_BEGIN uint8_t APP_Rx_Buffer [APP_RX_DATA_SIZE] __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 + #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t CmdBuff[CDC_CMD_PACKET_SZE] __ALIGN_END ; @@ -183,7 +183,7 @@ static uint32_t cdcCmd = 0xFF; static uint32_t cdcLen = 0; /* CDC interface class callbacks structure */ -USBD_Class_cb_TypeDef USBD_CDC_cb = +USBD_Class_cb_TypeDef USBD_CDC_cb = { usbd_cdc_Init, usbd_cdc_DeInit, @@ -194,16 +194,16 @@ USBD_Class_cb_TypeDef USBD_CDC_cb = usbd_cdc_DataOut, usbd_cdc_SOF, NULL, - NULL, + NULL, USBD_cdc_GetCfgDesc, -#ifdef USE_USB_OTG_HS +#ifdef USE_USB_OTG_HS USBD_cdc_GetOtherCfgDesc, /* use same cobfig as per FS */ #endif /* USE_USB_OTG_HS */ }; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 + #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* USB CDC device Configuration Descriptor */ @@ -219,9 +219,9 @@ __ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ 0xC0, /* bmAttributes: self powered */ 0x32, /* MaxPower 0 mA */ - + /*---------------------------------------------------------------------------*/ - + /*Interface Descriptor */ 0x09, /* bLength: Interface Descriptor size */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */ @@ -233,34 +233,34 @@ __ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = 0x02, /* bInterfaceSubClass: Abstract Control Model */ 0x01, /* bInterfaceProtocol: Common AT commands */ 0x00, /* iInterface: */ - + /*Header Functional Descriptor*/ 0x05, /* bLength: Endpoint Descriptor size */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x00, /* bDescriptorSubtype: Header Func Desc */ 0x10, /* bcdCDC: spec release number */ 0x01, - + /*Call Management Functional Descriptor*/ 0x05, /* bFunctionLength */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x01, /* bDescriptorSubtype: Call Management Func Desc */ 0x00, /* bmCapabilities: D0+D1 */ 0x01, /* bDataInterface: 1 */ - + /*ACM Functional Descriptor*/ 0x04, /* bFunctionLength */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ 0x02, /* bmCapabilities */ - + /*Union Functional Descriptor*/ 0x05, /* bFunctionLength */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x06, /* bDescriptorSubtype: Union func desc */ 0x00, /* bMasterInterface: Communication class interface */ 0x01, /* bSlaveInterface0: Data Class Interface */ - + /*Endpoint 2 Descriptor*/ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ @@ -273,9 +273,9 @@ __ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = #else 0xFF, /* bInterval: */ #endif /* USE_USB_OTG_HS */ - + /*---------------------------------------------------------------------------*/ - + /*Data class interface descriptor*/ 0x09, /* bLength: Endpoint Descriptor size */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */ @@ -286,7 +286,7 @@ __ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = 0x00, /* bInterfaceSubClass: */ 0x00, /* bInterfaceProtocol: */ 0x00, /* iInterface: */ - + /*Endpoint OUT Descriptor*/ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ @@ -295,7 +295,7 @@ __ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = LOBYTE(CDC_DATA_MAX_PACKET_SIZE), /* wMaxPacketSize: */ HIBYTE(CDC_DATA_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ - + /*Endpoint IN Descriptor*/ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ @@ -309,21 +309,21 @@ __ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = #ifdef USE_USB_OTG_HS #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 + #pragma data_alignment=4 #endif -#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ +#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = -{ +{ 0x09, /* bLength: Configuation Descriptor size */ - USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, + USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, USB_CDC_CONFIG_DESC_SIZ, 0x00, 0x02, /* bNumInterfaces: 2 interfaces */ 0x01, /* bConfigurationValue: */ 0x04, /* iConfiguration: */ 0xC0, /* bmAttributes: */ - 0x32, /* MaxPower 100 mA */ - + 0x32, /* MaxPower 100 mA */ + /*Interface Descriptor */ 0x09, /* bLength: Interface Descriptor size */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */ @@ -335,34 +335,34 @@ __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_EN 0x02, /* bInterfaceSubClass: Abstract Control Model */ 0x01, /* bInterfaceProtocol: Common AT commands */ 0x00, /* iInterface: */ - + /*Header Functional Descriptor*/ 0x05, /* bLength: Endpoint Descriptor size */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x00, /* bDescriptorSubtype: Header Func Desc */ 0x10, /* bcdCDC: spec release number */ 0x01, - + /*Call Management Functional Descriptor*/ 0x05, /* bFunctionLength */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x01, /* bDescriptorSubtype: Call Management Func Desc */ 0x00, /* bmCapabilities: D0+D1 */ 0x01, /* bDataInterface: 1 */ - + /*ACM Functional Descriptor*/ 0x04, /* bFunctionLength */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ 0x02, /* bmCapabilities */ - + /*Union Functional Descriptor*/ 0x05, /* bFunctionLength */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x06, /* bDescriptorSubtype: Union func desc */ 0x00, /* bMasterInterface: Communication class interface */ 0x01, /* bSlaveInterface0: Data Class Interface */ - + /*Endpoint 2 Descriptor*/ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ @@ -371,9 +371,9 @@ __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_EN LOBYTE(CDC_CMD_PACKET_SZE), /* wMaxPacketSize: */ HIBYTE(CDC_CMD_PACKET_SZE), 0xFF, /* bInterval: */ - + /*---------------------------------------------------------------------------*/ - + /*Data class interface descriptor*/ 0x09, /* bLength: Endpoint Descriptor size */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */ @@ -384,7 +384,7 @@ __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_EN 0x00, /* bInterfaceSubClass: */ 0x00, /* bInterfaceProtocol: */ 0x00, /* iInterface: */ - + /*Endpoint OUT Descriptor*/ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ @@ -393,7 +393,7 @@ __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_EN 0x40, /* wMaxPacketSize: */ 0x00, 0x00, /* bInterval: ignore for Bulk transfer */ - + /*Endpoint IN Descriptor*/ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ @@ -407,11 +407,11 @@ __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_EN /** * @} - */ + */ /** @defgroup usbd_cdc_Private_Functions * @{ - */ + */ /** * @brief usbd_cdc_Init @@ -420,7 +420,7 @@ __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_EN * @param cfgidx: Configuration index * @retval status */ -static uint8_t usbd_cdc_Init (void *pdev, +static uint8_t usbd_cdc_Init (void *pdev, uint8_t cfgidx) { uint8_t *pbuf; @@ -430,23 +430,23 @@ static uint8_t usbd_cdc_Init (void *pdev, CDC_IN_EP, CDC_DATA_IN_PACKET_SIZE, USB_OTG_EP_BULK); - + /* Open EP OUT */ DCD_EP_Open(pdev, CDC_OUT_EP, CDC_DATA_OUT_PACKET_SIZE, USB_OTG_EP_BULK); - + /* Open Command IN EP */ DCD_EP_Open(pdev, CDC_CMD_EP, CDC_CMD_PACKET_SZE, USB_OTG_EP_INT); - + pbuf = (uint8_t *)USBD_DeviceDesc; pbuf[4] = DEVICE_CLASS_CDC; pbuf[5] = DEVICE_SUBCLASS_CDC; - + /* Initialize the Interface physical components */ APP_FOPS.pIf_Init(); @@ -455,7 +455,7 @@ static uint8_t usbd_cdc_Init (void *pdev, CDC_OUT_EP, (uint8_t*)(USB_Rx_Buffer), CDC_DATA_OUT_PACKET_SIZE); - + return USBD_OK; } @@ -466,24 +466,24 @@ static uint8_t usbd_cdc_Init (void *pdev, * @param cfgidx: Configuration index * @retval status */ -static uint8_t usbd_cdc_DeInit (void *pdev, +static uint8_t usbd_cdc_DeInit (void *pdev, uint8_t cfgidx) { /* Open EP IN */ DCD_EP_Close(pdev, CDC_IN_EP); - + /* Open EP OUT */ DCD_EP_Close(pdev, CDC_OUT_EP); - + /* Open Command IN EP */ DCD_EP_Close(pdev, CDC_CMD_EP); /* Restore default state of the Interface physical components */ APP_FOPS.pIf_DeInit(); - + return USBD_OK; } @@ -494,12 +494,12 @@ static uint8_t usbd_cdc_DeInit (void *pdev, * @param req: usb requests * @retval status */ -static uint8_t usbd_cdc_Setup (void *pdev, +static uint8_t usbd_cdc_Setup (void *pdev, USB_SETUP_REQ *req) { uint16_t len; uint8_t *pbuf; - + switch (req->bmRequest & USB_REQ_TYPE_MASK) { /* CDC Class Requests -------------------------------*/ @@ -512,24 +512,24 @@ static uint8_t usbd_cdc_Setup (void *pdev, { /* Get the data to be sent to Host from interface layer */ APP_FOPS.pIf_Ctrl(req->bRequest, CmdBuff, req->wLength); - + /* Send the data to the host */ - USBD_CtlSendData (pdev, + USBD_CtlSendData (pdev, CmdBuff, - req->wLength); + req->wLength); } else /* Host-to-Device requeset */ { /* Set the value of the current command to be processed */ cdcCmd = req->bRequest; cdcLen = req->wLength; - + /* Prepare the reception of the buffer over EP0 - Next step: the received data will be managed in usbd_cdc_EP0_TxSent() + Next step: the received data will be managed in usbd_cdc_EP0_TxSent() function. */ USBD_CtlPrepareRx (pdev, CmdBuff, - req->wLength); + req->wLength); } } else /* No Data request */ @@ -537,41 +537,41 @@ static uint8_t usbd_cdc_Setup (void *pdev, /* Transfer the command to the interface layer */ APP_FOPS.pIf_Ctrl(req->bRequest, NULL, 0); } - + return USBD_OK; - + default: USBD_CtlError (pdev, req); return USBD_FAIL; - - - + + + /* Standard Requests -------------------------------*/ case USB_REQ_TYPE_STANDARD: switch (req->bRequest) { - case USB_REQ_GET_DESCRIPTOR: + case USB_REQ_GET_DESCRIPTOR: if( (req->wValue >> 8) == CDC_DESCRIPTOR_TYPE) { #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED - pbuf = usbd_cdc_Desc; + pbuf = usbd_cdc_Desc; #else pbuf = usbd_cdc_CfgDesc + 9 + (9 * USBD_ITF_MAX_NUM); -#endif +#endif len = MIN(USB_CDC_DESC_SIZ , req->wLength); } - - USBD_CtlSendData (pdev, + + USBD_CtlSendData (pdev, pbuf, len); break; - + case USB_REQ_GET_INTERFACE : USBD_CtlSendData (pdev, (uint8_t *)&usbd_cdc_AltSet, 1); break; - + case USB_REQ_SET_INTERFACE : if ((uint8_t)(req->wValue) < USBD_ITF_MAX_NUM) { @@ -595,16 +595,16 @@ static uint8_t usbd_cdc_Setup (void *pdev, * @retval status */ static uint8_t usbd_cdc_EP0_RxReady (void *pdev) -{ +{ if (cdcCmd != NO_CMD) { /* Process the data */ APP_FOPS.pIf_Ctrl(cdcCmd, CmdBuff, cdcLen); - + /* Reset the command variable to default value */ cdcCmd = NO_CMD; } - + return USBD_OK; } @@ -622,36 +622,36 @@ static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum) if (USB_Tx_State == 1) { - if (APP_Rx_length == 0) + if (APP_Rx_length == 0) { USB_Tx_State = 0; } - else + else { if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE){ USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = CDC_DATA_IN_PACKET_SIZE; - + APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE; - APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE; + APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE; } - else + else { USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = APP_Rx_length; - + APP_Rx_ptr_out += APP_Rx_length; APP_Rx_length = 0; } - + /* Prepare the available data buffer to be sent on IN endpoint */ DCD_EP_Tx (pdev, CDC_IN_EP, (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr], USB_Tx_length); } - } - + } + return USBD_OK; } @@ -663,16 +663,16 @@ static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum) * @retval status */ static uint8_t usbd_cdc_DataOut (void *pdev, uint8_t epnum) -{ +{ uint16_t USB_Rx_Cnt; - + /* Get the received data buffer and update the counter */ USB_Rx_Cnt = ((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].xfer_count; - - /* USB data will be immediately processed, this allow next USB traffic being + + /* USB data will be immediately processed, this allow next USB traffic being NAKed till the end of the application Xfer */ APP_FOPS.pIf_DataRx(USB_Rx_Buffer, USB_Rx_Cnt); - + /* Prepare Out endpoint to receive next packet */ DCD_EP_PrepareRx(pdev, CDC_OUT_EP, @@ -690,18 +690,18 @@ static uint8_t usbd_cdc_DataOut (void *pdev, uint8_t epnum) * @retval status */ static uint8_t usbd_cdc_SOF (void *pdev) -{ +{ static uint32_t FrameCount = 0; - + if (FrameCount++ == CDC_IN_FRAME_INTERVAL) { /* Reset the frame counter */ FrameCount = 0; - + /* Check the data to be sent through IN pipe */ Handle_USBAsynchXfer(pdev); } - + return USBD_OK; } @@ -715,62 +715,62 @@ static void Handle_USBAsynchXfer (void *pdev) { uint16_t USB_Tx_ptr; uint16_t USB_Tx_length; - + if(USB_Tx_State != 1) { if (APP_Rx_ptr_out == APP_RX_DATA_SIZE) { APP_Rx_ptr_out = 0; } - - if(APP_Rx_ptr_out == APP_Rx_ptr_in) + + if(APP_Rx_ptr_out == APP_Rx_ptr_in) { - USB_Tx_State = 0; + USB_Tx_State = 0; return; } - + if(APP_Rx_ptr_out > APP_Rx_ptr_in) /* rollback */ - { + { APP_Rx_length = APP_RX_DATA_SIZE - APP_Rx_ptr_out; - + } - else + else { APP_Rx_length = APP_Rx_ptr_in - APP_Rx_ptr_out; - + } #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED APP_Rx_length &= ~0x03; #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ - + if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE) { USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = CDC_DATA_IN_PACKET_SIZE; - - APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE; + + APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE; APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE; } else { USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = APP_Rx_length; - + APP_Rx_ptr_out += APP_Rx_length; APP_Rx_length = 0; } - USB_Tx_State = 1; + USB_Tx_State = 1; DCD_EP_Tx (pdev, CDC_IN_EP, (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr], USB_Tx_length); - } - + } + } /** - * @brief USBD_cdc_GetCfgDesc + * @brief USBD_cdc_GetCfgDesc * Return configuration descriptor * @param speed : current device speed * @param length : pointer data length @@ -783,13 +783,13 @@ static uint8_t *USBD_cdc_GetCfgDesc (uint8_t speed, uint16_t *length) } /** - * @brief USBD_cdc_GetCfgDesc + * @brief USBD_cdc_GetCfgDesc * Return configuration descriptor * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ -#ifdef USE_USB_OTG_HS +#ifdef USE_USB_OTG_HS static uint8_t *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length) { *length = sizeof (usbd_cdc_OtherCfgDesc); @@ -798,14 +798,14 @@ static uint8_t *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length) #endif /** * @} - */ + */ /** * @} - */ + */ /** * @} - */ + */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_core.h b/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_core.h index 926f42e1..43af2682 100644 --- a/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_core.h +++ b/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_core.h @@ -17,7 +17,7 @@ * *

© COPYRIGHT 2011 STMicroelectronics

****************************************************************************** - */ + */ /* Includes ------------------------------------------------------------------*/ @@ -29,16 +29,16 @@ /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ - + /** @defgroup usbd_cdc * @brief This file is the Header file for USBD_cdc.c * @{ - */ + */ /** @defgroup usbd_cdc_Exported_Defines * @{ - */ + */ #define USB_CDC_CONFIG_DESC_SIZ (67) #define USB_CDC_DESC_SIZ (67-9) @@ -57,7 +57,7 @@ #define STANDARD_ENDPOINT_DESC_SIZE 0x09 #define CDC_DATA_IN_PACKET_SIZE *(uint16_t *)(((USB_OTG_CORE_HANDLE *)pdev)->dev.pConfig_descriptor + 57) - + #define CDC_DATA_OUT_PACKET_SIZE *(uint16_t *)(((USB_OTG_CORE_HANDLE *)pdev)->dev.pConfig_descriptor + 64) /*---------------------------------------------------------------------*/ @@ -80,7 +80,7 @@ /** * @} - */ + */ /** @defgroup USBD_CORE_Exported_TypesDefinitions @@ -88,8 +88,8 @@ */ typedef struct _CDC_IF_PROP { - uint16_t (*pIf_Init) (void); - uint16_t (*pIf_DeInit) (void); + uint16_t (*pIf_Init) (void); + uint16_t (*pIf_DeInit) (void); uint16_t (*pIf_Ctrl) (uint32_t Cmd, uint8_t* Buf, uint32_t Len); uint16_t (*pIf_DataTx) (uint8_t* Buf, uint32_t Len); uint16_t (*pIf_DataRx) (uint8_t* Buf, uint32_t Len); @@ -97,41 +97,41 @@ typedef struct _CDC_IF_PROP CDC_IF_Prop_TypeDef; /** * @} - */ + */ /** @defgroup USBD_CORE_Exported_Macros * @{ - */ - + */ + /** * @} - */ + */ /** @defgroup USBD_CORE_Exported_Variables * @{ - */ + */ extern USBD_Class_cb_TypeDef USBD_CDC_cb; /** * @} - */ + */ /** @defgroup USB_CORE_Exported_Functions * @{ */ /** * @} - */ + */ #endif // __USB_CDC_CORE_H_ /** * @} - */ + */ /** * @} - */ - + */ + /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_vcp.c b/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_vcp.c index 84ae6489..5f96919a 100644 --- a/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_vcp.c +++ b/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_vcp.c @@ -19,8 +19,8 @@ ****************************************************************************** */ -#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED -#pragma data_alignment = 4 +#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED +#pragma data_alignment = 4 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* Includes ------------------------------------------------------------------*/ @@ -38,7 +38,7 @@ LINE_CODING linecoding = { USART_InitTypeDef USART_InitStructure; -/* These are external variables imported from CDC core to be used for IN +/* These are external variables imported from CDC core to be used for IN transfer management. */ extern uint8_t APP_Rx_Buffer[]; /* Write CDC received data in this buffer. These data will be sent over USB IN endpoint diff --git a/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_vcp.h b/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_vcp.h index 98c4d823..78f2c03f 100644 --- a/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_vcp.h +++ b/codec2-dev/stm32/usb_lib/cdc/usbd_cdc_vcp.h @@ -31,7 +31,7 @@ #include /* Exported typef ------------------------------------------------------------*/ -/* The following structures groups all needed parameters to be configured for the +/* The following structures groups all needed parameters to be configured for the ComPort. These parameters can modified on the fly by the host through CDC class command class requests. */ typedef struct diff --git a/codec2-dev/stm32/usb_lib/core/usbd_core.c b/codec2-dev/stm32/usb_lib/core/usbd_core.c index 2a51d3ae..4b5781fe 100644 --- a/codec2-dev/stm32/usb_lib/core/usbd_core.c +++ b/codec2-dev/stm32/usb_lib/core/usbd_core.c @@ -3,7 +3,7 @@ * @file usbd_core.c * @author MCD Application Team * @version V1.0.0 - * @date 22-July-2011 + * @date 22-July-2011 * @brief This file provides all the USBD core functions. ****************************************************************************** * @attention @@ -17,7 +17,7 @@ * *

© COPYRIGHT 2011 STMicroelectronics

****************************************************************************** - */ + */ /* Includes ------------------------------------------------------------------*/ #include "usbd_core.h" @@ -31,41 +31,41 @@ */ -/** @defgroup USBD_CORE +/** @defgroup USBD_CORE * @brief usbd core module * @{ -*/ +*/ /** @defgroup USBD_CORE_Private_TypesDefinitions * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USBD_CORE_Private_Defines * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USBD_CORE_Private_Macros * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USBD_CORE_Private_FunctionPrototypes * @{ -*/ +*/ static uint8_t USBD_SetupStage(USB_OTG_CORE_HANDLE *pdev); static uint8_t USBD_DataOutStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum); static uint8_t USBD_DataInStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum); @@ -81,15 +81,15 @@ static uint8_t USBD_IsoINIncomplete(USB_OTG_CORE_HANDLE *pdev); static uint8_t USBD_IsoOUTIncomplete(USB_OTG_CORE_HANDLE *pdev); /** * @} -*/ +*/ /** @defgroup USBD_CORE_Private_Variables * @{ -*/ +*/ -USBD_DCD_INT_cb_TypeDef USBD_DCD_INT_cb = +USBD_DCD_INT_cb_TypeDef USBD_DCD_INT_cb = { USBD_DataOutStage, USBD_DataInStage, @@ -101,19 +101,19 @@ USBD_DCD_INT_cb_TypeDef USBD_DCD_INT_cb = USBD_IsoINIncomplete, USBD_IsoOUTIncomplete, #ifdef VBUS_SENSING_ENABLED -USBD_DevConnected, -USBD_DevDisconnected, -#endif +USBD_DevConnected, +USBD_DevDisconnected, +#endif }; USBD_DCD_INT_cb_TypeDef *USBD_DCD_INT_fops = &USBD_DCD_INT_cb; /** * @} -*/ +*/ /** @defgroup USBD_CORE_Private_Functions * @{ -*/ +*/ /** * @brief USBD_Init @@ -126,32 +126,32 @@ USBD_DCD_INT_cb_TypeDef *USBD_DCD_INT_fops = &USBD_DCD_INT_cb; */ void USBD_Init(USB_OTG_CORE_HANDLE *pdev, USB_OTG_CORE_ID_TypeDef coreID, - USBD_DEVICE *pDevice, - USBD_Class_cb_TypeDef *class_cb, + USBD_DEVICE *pDevice, + USBD_Class_cb_TypeDef *class_cb, USBD_Usr_cb_TypeDef *usr_cb) { /* Hardware Init */ - USB_OTG_BSP_Init(pdev); - + USB_OTG_BSP_Init(pdev); + USBD_DeInit(pdev); - + /*Register class and user callbacks */ pdev->dev.class_cb = class_cb; - pdev->dev.usr_cb = usr_cb; - pdev->dev.usr_device = pDevice; - + pdev->dev.usr_cb = usr_cb; + pdev->dev.usr_device = pDevice; + /* set USB OTG core params */ DCD_Init(pdev , coreID); - + /* Upon Init call usr callback */ pdev->dev.usr_cb->Init(); - + /* Enable Interrupts */ USB_OTG_BSP_EnableInterrupt(pdev); } /** -* @brief USBD_DeInit +* @brief USBD_DeInit * Re-Initialize th deviuce library * @param pdev: device instance * @retval status: status @@ -159,12 +159,12 @@ void USBD_Init(USB_OTG_CORE_HANDLE *pdev, USBD_Status USBD_DeInit(USB_OTG_CORE_HANDLE *pdev) { /* Software Init */ - + return USBD_OK; } /** -* @brief USBD_SetupStage +* @brief USBD_SetupStage * Handle the setup stage * @param pdev: device instance * @retval status @@ -172,32 +172,32 @@ USBD_Status USBD_DeInit(USB_OTG_CORE_HANDLE *pdev) static uint8_t USBD_SetupStage(USB_OTG_CORE_HANDLE *pdev) { USB_SETUP_REQ req; - + USBD_ParseSetupRequest(pdev , &req); - - switch (req.bmRequest & 0x1F) + + switch (req.bmRequest & 0x1F) { - case USB_REQ_RECIPIENT_DEVICE: + case USB_REQ_RECIPIENT_DEVICE: USBD_StdDevReq (pdev, &req); break; - - case USB_REQ_RECIPIENT_INTERFACE: + + case USB_REQ_RECIPIENT_INTERFACE: USBD_StdItfReq(pdev, &req); break; - - case USB_REQ_RECIPIENT_ENDPOINT: - USBD_StdEPReq(pdev, &req); + + case USB_REQ_RECIPIENT_ENDPOINT: + USBD_StdEPReq(pdev, &req); break; - - default: + + default: DCD_EP_Stall(pdev , req.bmRequest & 0x80); break; - } + } return USBD_OK; } /** -* @brief USBD_DataOutStage +* @brief USBD_DataOutStage * Handle data out stage * @param pdev: device instance * @param epnum: endpoint index @@ -206,8 +206,8 @@ static uint8_t USBD_SetupStage(USB_OTG_CORE_HANDLE *pdev) static uint8_t USBD_DataOutStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum) { USB_OTG_EP *ep; - - if(epnum == 0) + + if(epnum == 0) { ep = &pdev->dev.out_ep[0]; if ( pdev->dev.device_state == USB_OTG_EP0_DATA_OUT) @@ -215,13 +215,13 @@ static uint8_t USBD_DataOutStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum) if(ep->rem_data_len > ep->maxpacket) { ep->rem_data_len -= ep->maxpacket; - + if(pdev->cfg.dma_enable == 1) { /* in slave mode this, is handled by the RxSTSQLvl ISR */ - ep->xfer_buff += ep->maxpacket; - } - USBD_CtlContinueRx (pdev, + ep->xfer_buff += ep->maxpacket; + } + USBD_CtlContinueRx (pdev, ep->xfer_buff, MIN(ep->rem_data_len ,ep->maxpacket)); } @@ -230,7 +230,7 @@ static uint8_t USBD_DataOutStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum) if((pdev->dev.class_cb->EP0_RxReady != NULL)&& (pdev->dev.device_status == USB_OTG_CONFIGURED)) { - pdev->dev.class_cb->EP0_RxReady(pdev); + pdev->dev.class_cb->EP0_RxReady(pdev); } USBD_CtlSendStatus(pdev); } @@ -239,13 +239,13 @@ static uint8_t USBD_DataOutStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum) else if((pdev->dev.class_cb->DataOut != NULL)&& (pdev->dev.device_status == USB_OTG_CONFIGURED)) { - pdev->dev.class_cb->DataOut(pdev, epnum); - } + pdev->dev.class_cb->DataOut(pdev, epnum); + } return USBD_OK; } /** -* @brief USBD_DataInStage +* @brief USBD_DataInStage * Handle data in stage * @param pdev: device instance * @param epnum: endpoint index @@ -254,8 +254,8 @@ static uint8_t USBD_DataOutStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum) static uint8_t USBD_DataInStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum) { USB_OTG_EP *ep; - - if(epnum == 0) + + if(epnum == 0) { ep = &pdev->dev.in_ep[0]; if ( pdev->dev.device_state == USB_OTG_EP0_DATA_IN) @@ -268,8 +268,8 @@ static uint8_t USBD_DataInStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum) /* in slave mode this, is handled by the TxFifoEmpty ISR */ ep->xfer_buff += ep->maxpacket; } - USBD_CtlContinueSendData (pdev, - ep->xfer_buff, + USBD_CtlContinueSendData (pdev, + ep->xfer_buff, ep->rem_data_len); } else @@ -278,7 +278,7 @@ static uint8_t USBD_DataInStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum) (ep->total_data_len >= ep->maxpacket) && (ep->total_data_len < ep->ctl_data_len )) { - + USBD_CtlContinueSendData(pdev , NULL, 0); ep->ctl_data_len = 0; } @@ -287,23 +287,23 @@ static uint8_t USBD_DataInStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum) if((pdev->dev.class_cb->EP0_TxSent != NULL)&& (pdev->dev.device_status == USB_OTG_CONFIGURED)) { - pdev->dev.class_cb->EP0_TxSent(pdev); - } + pdev->dev.class_cb->EP0_TxSent(pdev); + } USBD_CtlReceiveStatus(pdev); } } } } - else if((pdev->dev.class_cb->DataIn != NULL)&& + else if((pdev->dev.class_cb->DataIn != NULL)&& (pdev->dev.device_status == USB_OTG_CONFIGURED)) { - pdev->dev.class_cb->DataIn(pdev, epnum); - } + pdev->dev.class_cb->DataIn(pdev, epnum); + } return USBD_OK; } /** -* @brief USBD_Reset +* @brief USBD_Reset * Handle Reset event * @param pdev: device instance * @retval status @@ -316,22 +316,22 @@ static uint8_t USBD_Reset(USB_OTG_CORE_HANDLE *pdev) 0x00, USB_OTG_MAX_EP0_SIZE, EP_TYPE_CTRL); - + /* Open EP0 IN */ DCD_EP_Open(pdev, 0x80, USB_OTG_MAX_EP0_SIZE, EP_TYPE_CTRL); - + /* Upon Reset call usr call back */ pdev->dev.device_status = USB_OTG_DEFAULT; pdev->dev.usr_cb->DeviceReset(pdev->cfg.speed); - + return USBD_OK; } /** -* @brief USBD_Resume +* @brief USBD_Resume * Handle Resume event * @param pdev: device instance * @retval status @@ -340,14 +340,14 @@ static uint8_t USBD_Reset(USB_OTG_CORE_HANDLE *pdev) static uint8_t USBD_Resume(USB_OTG_CORE_HANDLE *pdev) { /* Upon Resume call usr call back */ - pdev->dev.usr_cb->DeviceResumed(); - pdev->dev.device_status = USB_OTG_CONFIGURED; + pdev->dev.usr_cb->DeviceResumed(); + pdev->dev.device_status = USB_OTG_CONFIGURED; return USBD_OK; } /** -* @brief USBD_Suspend +* @brief USBD_Suspend * Handle Suspend event * @param pdev: device instance * @retval status @@ -355,16 +355,16 @@ static uint8_t USBD_Resume(USB_OTG_CORE_HANDLE *pdev) static uint8_t USBD_Suspend(USB_OTG_CORE_HANDLE *pdev) { - + pdev->dev.device_status = USB_OTG_SUSPENDED; /* Upon Resume call usr call back */ - pdev->dev.usr_cb->DeviceSuspended(); + pdev->dev.usr_cb->DeviceSuspended(); return USBD_OK; } /** -* @brief USBD_SOF +* @brief USBD_SOF * Handle SOF event * @param pdev: device instance * @retval status @@ -374,12 +374,12 @@ static uint8_t USBD_SOF(USB_OTG_CORE_HANDLE *pdev) { if(pdev->dev.class_cb->SOF) { - pdev->dev.class_cb->SOF(pdev); + pdev->dev.class_cb->SOF(pdev); } return USBD_OK; } /** -* @brief USBD_SetCfg +* @brief USBD_SetCfg * Configure device and start the interface * @param pdev: device instance * @param cfgidx: configuration index @@ -388,15 +388,15 @@ static uint8_t USBD_SOF(USB_OTG_CORE_HANDLE *pdev) USBD_Status USBD_SetCfg(USB_OTG_CORE_HANDLE *pdev, uint8_t cfgidx) { - pdev->dev.class_cb->Init(pdev, cfgidx); - + pdev->dev.class_cb->Init(pdev, cfgidx); + /* Upon set config call usr call back */ pdev->dev.usr_cb->DeviceConfigured(); - return USBD_OK; + return USBD_OK; } /** -* @brief USBD_ClrCfg +* @brief USBD_ClrCfg * Clear current configuration * @param pdev: device instance * @param cfgidx: configuration index @@ -404,37 +404,37 @@ USBD_Status USBD_SetCfg(USB_OTG_CORE_HANDLE *pdev, uint8_t cfgidx) */ USBD_Status USBD_ClrCfg(USB_OTG_CORE_HANDLE *pdev, uint8_t cfgidx) { - pdev->dev.class_cb->DeInit(pdev, cfgidx); + pdev->dev.class_cb->DeInit(pdev, cfgidx); return USBD_OK; } /** -* @brief USBD_IsoINIncomplete +* @brief USBD_IsoINIncomplete * Handle iso in incomplete event * @param pdev: device instance * @retval status */ static uint8_t USBD_IsoINIncomplete(USB_OTG_CORE_HANDLE *pdev) { - pdev->dev.class_cb->IsoINIncomplete(pdev); + pdev->dev.class_cb->IsoINIncomplete(pdev); return USBD_OK; } /** -* @brief USBD_IsoOUTIncomplete +* @brief USBD_IsoOUTIncomplete * Handle iso out incomplete event * @param pdev: device instance * @retval status */ static uint8_t USBD_IsoOUTIncomplete(USB_OTG_CORE_HANDLE *pdev) { - pdev->dev.class_cb->IsoOUTIncomplete(pdev); + pdev->dev.class_cb->IsoOUTIncomplete(pdev); return USBD_OK; } #ifdef VBUS_SENSING_ENABLED /** -* @brief USBD_DevConnected +* @brief USBD_DevConnected * Handle device connection event * @param pdev: device instance * @retval status @@ -446,7 +446,7 @@ static uint8_t USBD_DevConnected(USB_OTG_CORE_HANDLE *pdev) } /** -* @brief USBD_DevDisconnected +* @brief USBD_DevDisconnected * Handle device disconnection event * @param pdev: device instance * @retval status @@ -460,17 +460,17 @@ static uint8_t USBD_DevDisconnected(USB_OTG_CORE_HANDLE *pdev) #endif /** * @} -*/ +*/ /** * @} -*/ +*/ /** * @} -*/ +*/ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_lib/core/usbd_core.h b/codec2-dev/stm32/usb_lib/core/usbd_core.h index fb20acf6..1fc83669 100644 --- a/codec2-dev/stm32/usb_lib/core/usbd_core.h +++ b/codec2-dev/stm32/usb_lib/core/usbd_core.h @@ -6,7 +6,7 @@ * @date 22-July-2011 * @brief Header file for usbd_core.c ****************************************************************************** - * @attention + * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE @@ -17,7 +17,7 @@ * *

© COPYRIGHT 2011 STMicroelectronics

****************************************************************************** - */ + */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USBD_CORE_H @@ -31,16 +31,16 @@ /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ - + /** @defgroup USBD_CORE * @brief This file is the Header file for usbd_core.c file * @{ - */ + */ /** @defgroup USBD_CORE_Exported_Defines * @{ - */ + */ typedef enum { USBD_OK = 0, @@ -49,43 +49,43 @@ typedef enum { }USBD_Status; /** * @} - */ + */ /** @defgroup USBD_CORE_Exported_TypesDefinitions * @{ */ - + /** * @} - */ + */ /** @defgroup USBD_CORE_Exported_Macros * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_CORE_Exported_Variables * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_CORE_Exported_FunctionsPrototype * @{ - */ + */ void USBD_Init(USB_OTG_CORE_HANDLE *pdev, - USB_OTG_CORE_ID_TypeDef coreID, - USBD_DEVICE *pDevice, - USBD_Class_cb_TypeDef *class_cb, + USB_OTG_CORE_ID_TypeDef coreID, + USBD_DEVICE *pDevice, + USBD_Class_cb_TypeDef *class_cb, USBD_Usr_cb_TypeDef *usr_cb); USBD_Status USBD_DeInit(USB_OTG_CORE_HANDLE *pdev); @@ -96,17 +96,17 @@ USBD_Status USBD_SetCfg(USB_OTG_CORE_HANDLE *pdev, uint8_t cfgidx); /** * @} - */ + */ #endif /* __USBD_CORE_H */ /** * @} - */ + */ /** * @} -*/ +*/ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_lib/core/usbd_def.h b/codec2-dev/stm32/usb_lib/core/usbd_def.h index a8c86710..40620c95 100644 --- a/codec2-dev/stm32/usb_lib/core/usbd_def.h +++ b/codec2-dev/stm32/usb_lib/core/usbd_def.h @@ -4,20 +4,20 @@ * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 - * @brief general defines for the usb device library + * @brief general defines for the usb device library ****************************************************************************** - * @attention + * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * *

© COPYRIGHT 2011 STMicroelectronics

****************************************************************************** - */ + */ /* Define to prevent recursive inclusion -------------------------------------*/ @@ -29,15 +29,15 @@ /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ - + /** @defgroup USB_DEF * @brief general defines for the usb device library file * @{ - */ + */ /** @defgroup USB_DEF_Exported_Defines * @{ - */ + */ #ifndef NULL #define NULL 0 @@ -50,12 +50,12 @@ #define USB_LEN_EP_DESC 0x07 #define USB_LEN_OTG_DESC 0x03 -#define USBD_IDX_LANGID_STR 0x00 -#define USBD_IDX_MFC_STR 0x01 +#define USBD_IDX_LANGID_STR 0x00 +#define USBD_IDX_MFC_STR 0x01 #define USBD_IDX_PRODUCT_STR 0x02 -#define USBD_IDX_SERIAL_STR 0x03 -#define USBD_IDX_CONFIG_STR 0x04 -#define USBD_IDX_INTERFACE_STR 0x05 +#define USBD_IDX_SERIAL_STR 0x03 +#define USBD_IDX_CONFIG_STR 0x04 +#define USBD_IDX_INTERFACE_STR 0x05 #define USB_REQ_TYPE_STANDARD 0x00 #define USB_REQ_TYPE_CLASS 0x20 @@ -97,7 +97,7 @@ /** * @} - */ + */ /** @defgroup USBD_DEF_Exported_TypesDefinitions @@ -105,13 +105,13 @@ */ /** * @} - */ + */ /** @defgroup USBD_DEF_Exported_Macros * @{ - */ + */ #define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \ (((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8)) @@ -119,31 +119,31 @@ #define HIBYTE(x) ((uint8_t)((x & 0xFF00) >>8)) /** * @} - */ + */ /** @defgroup USBD_DEF_Exported_Variables * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_DEF_Exported_FunctionsPrototype * @{ - */ + */ /** * @} - */ + */ #endif /* __USBD_DEF_H */ /** * @} - */ + */ /** * @} -*/ +*/ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_lib/core/usbd_ioreq.c b/codec2-dev/stm32/usb_lib/core/usbd_ioreq.c index 6964766b..ea7cacfa 100644 --- a/codec2-dev/stm32/usb_lib/core/usbd_ioreq.c +++ b/codec2-dev/stm32/usb_lib/core/usbd_ioreq.c @@ -17,7 +17,7 @@ * *

© COPYRIGHT 2011 STMicroelectronics

****************************************************************************** - */ + */ /* Includes ------------------------------------------------------------------*/ #include "usbd_ioreq.h" @@ -26,56 +26,56 @@ */ -/** @defgroup USBD_IOREQ +/** @defgroup USBD_IOREQ * @brief control I/O requests module * @{ - */ + */ /** @defgroup USBD_IOREQ_Private_TypesDefinitions * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_IOREQ_Private_Defines * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_IOREQ_Private_Macros * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_IOREQ_Private_Variables * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_IOREQ_Private_FunctionPrototypes * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_IOREQ_Private_Functions * @{ - */ + */ /** * @brief USBD_CtlSendData @@ -85,18 +85,18 @@ * @param len: length of data to be sent * @retval status */ -USBD_Status USBD_CtlSendData (USB_OTG_CORE_HANDLE *pdev, +USBD_Status USBD_CtlSendData (USB_OTG_CORE_HANDLE *pdev, uint8_t *pbuf, uint16_t len) { USBD_Status ret = USBD_OK; - + pdev->dev.in_ep[0].total_data_len = len; pdev->dev.in_ep[0].rem_data_len = len; pdev->dev.device_state = USB_OTG_EP0_DATA_IN; DCD_EP_Tx (pdev, 0, pbuf, len); - + return ret; } @@ -108,15 +108,15 @@ USBD_Status USBD_CtlSendData (USB_OTG_CORE_HANDLE *pdev, * @param len: length of data to be sent * @retval status */ -USBD_Status USBD_CtlContinueSendData (USB_OTG_CORE_HANDLE *pdev, +USBD_Status USBD_CtlContinueSendData (USB_OTG_CORE_HANDLE *pdev, uint8_t *pbuf, uint16_t len) { USBD_Status ret = USBD_OK; - + DCD_EP_Tx (pdev, 0, pbuf, len); - - + + return ret; } @@ -129,20 +129,20 @@ USBD_Status USBD_CtlContinueSendData (USB_OTG_CORE_HANDLE *pdev, * @retval status */ USBD_Status USBD_CtlPrepareRx (USB_OTG_CORE_HANDLE *pdev, - uint8_t *pbuf, + uint8_t *pbuf, uint16_t len) { USBD_Status ret = USBD_OK; - + pdev->dev.out_ep[0].total_data_len = len; pdev->dev.out_ep[0].rem_data_len = len; pdev->dev.device_state = USB_OTG_EP0_DATA_OUT; - + DCD_EP_PrepareRx (pdev, 0, pbuf, len); - + return ret; } @@ -155,15 +155,15 @@ USBD_Status USBD_CtlPrepareRx (USB_OTG_CORE_HANDLE *pdev, * @param len: length of data to be received * @retval status */ -USBD_Status USBD_CtlContinueRx (USB_OTG_CORE_HANDLE *pdev, - uint8_t *pbuf, +USBD_Status USBD_CtlContinueRx (USB_OTG_CORE_HANDLE *pdev, + uint8_t *pbuf, uint16_t len) { USBD_Status ret = USBD_OK; - + DCD_EP_PrepareRx (pdev, - 0, - pbuf, + 0, + pbuf, len); return ret; } @@ -179,11 +179,11 @@ USBD_Status USBD_CtlSendStatus (USB_OTG_CORE_HANDLE *pdev) pdev->dev.device_state = USB_OTG_EP0_STATUS_IN; DCD_EP_Tx (pdev, 0, - NULL, - 0); - - USB_OTG_EP0_OutStart(pdev); - + NULL, + 0); + + USB_OTG_EP0_OutStart(pdev); + return ret; } @@ -196,14 +196,14 @@ USBD_Status USBD_CtlSendStatus (USB_OTG_CORE_HANDLE *pdev) USBD_Status USBD_CtlReceiveStatus (USB_OTG_CORE_HANDLE *pdev) { USBD_Status ret = USBD_OK; - pdev->dev.device_state = USB_OTG_EP0_STATUS_OUT; + pdev->dev.device_state = USB_OTG_EP0_STATUS_OUT; DCD_EP_PrepareRx ( pdev, 0, NULL, - 0); + 0); USB_OTG_EP0_OutStart(pdev); - + return ret; } @@ -222,16 +222,16 @@ uint16_t USBD_GetRxCount (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum) /** * @} - */ + */ /** * @} - */ + */ /** * @} - */ + */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_lib/core/usbd_ioreq.h b/codec2-dev/stm32/usb_lib/core/usbd_ioreq.h index ca755f2b..6858eba6 100644 --- a/codec2-dev/stm32/usb_lib/core/usbd_ioreq.h +++ b/codec2-dev/stm32/usb_lib/core/usbd_ioreq.h @@ -17,7 +17,7 @@ * *

© COPYRIGHT 2011 STMicroelectronics

****************************************************************************** - */ + */ /* Define to prevent recursive inclusion -------------------------------------*/ @@ -31,18 +31,18 @@ /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ - + /** @defgroup USBD_IOREQ * @brief header file for the usbd_ioreq.c file * @{ - */ + */ /** @defgroup USBD_IOREQ_Exported_Defines * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_IOREQ_Exported_Types @@ -52,64 +52,64 @@ /** * @} - */ + */ /** @defgroup USBD_IOREQ_Exported_Macros * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_IOREQ_Exported_Variables * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype * @{ - */ + */ -USBD_Status USBD_CtlSendData (USB_OTG_CORE_HANDLE *pdev, +USBD_Status USBD_CtlSendData (USB_OTG_CORE_HANDLE *pdev, uint8_t *buf, uint16_t len); -USBD_Status USBD_CtlContinueSendData (USB_OTG_CORE_HANDLE *pdev, +USBD_Status USBD_CtlContinueSendData (USB_OTG_CORE_HANDLE *pdev, uint8_t *pbuf, uint16_t len); -USBD_Status USBD_CtlPrepareRx (USB_OTG_CORE_HANDLE *pdev, - uint8_t *pbuf, +USBD_Status USBD_CtlPrepareRx (USB_OTG_CORE_HANDLE *pdev, + uint8_t *pbuf, uint16_t len); -USBD_Status USBD_CtlContinueRx (USB_OTG_CORE_HANDLE *pdev, - uint8_t *pbuf, +USBD_Status USBD_CtlContinueRx (USB_OTG_CORE_HANDLE *pdev, + uint8_t *pbuf, uint16_t len); USBD_Status USBD_CtlSendStatus (USB_OTG_CORE_HANDLE *pdev); USBD_Status USBD_CtlReceiveStatus (USB_OTG_CORE_HANDLE *pdev); -uint16_t USBD_GetRxCount (USB_OTG_CORE_HANDLE *pdev , +uint16_t USBD_GetRxCount (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum); /** * @} - */ + */ #endif /* __USBD_IOREQ_H_ */ /** * @} - */ + */ /** * @} -*/ +*/ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_lib/core/usbd_req.c b/codec2-dev/stm32/usb_lib/core/usbd_req.c index f08d26c6..40fca32f 100644 --- a/codec2-dev/stm32/usb_lib/core/usbd_req.c +++ b/codec2-dev/stm32/usb_lib/core/usbd_req.c @@ -3,7 +3,7 @@ * @file usbd_req.c * @author MCD Application Team * @version V1.0.0 - * @date 22-July-2011 + * @date 22-July-2011 * @brief This file provides the standard USB requests following chapter 9. ****************************************************************************** * @attention @@ -17,7 +17,7 @@ * *

© COPYRIGHT 2011 STMicroelectronics

****************************************************************************** - */ + */ /* Includes ------------------------------------------------------------------*/ #include "usbd_req.h" @@ -30,105 +30,105 @@ */ -/** @defgroup USBD_REQ +/** @defgroup USBD_REQ * @brief USB standard requests module * @{ - */ + */ /** @defgroup USBD_REQ_Private_TypesDefinitions * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_REQ_Private_Defines * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_REQ_Private_Macros * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_REQ_Private_Variables * @{ - */ + */ #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 + #pragma data_alignment=4 #endif -#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ -__ALIGN_BEGIN uint32_t USBD_ep_status __ALIGN_END = 0; +#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ +__ALIGN_BEGIN uint32_t USBD_ep_status __ALIGN_END = 0; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 + #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint32_t USBD_default_cfg __ALIGN_END = 0; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 + #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ -__ALIGN_BEGIN uint32_t USBD_cfg_status __ALIGN_END = 0; +__ALIGN_BEGIN uint32_t USBD_cfg_status __ALIGN_END = 0; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 + #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ] __ALIGN_END ; /** * @} - */ + */ /** @defgroup USBD_REQ_Private_FunctionPrototypes * @{ - */ -static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE *pdev, + */ +static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); -static void USBD_SetAddress(USB_OTG_CORE_HANDLE *pdev, +static void USBD_SetAddress(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); -static void USBD_SetConfig(USB_OTG_CORE_HANDLE *pdev, +static void USBD_SetConfig(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); -static void USBD_GetConfig(USB_OTG_CORE_HANDLE *pdev, +static void USBD_GetConfig(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); -static void USBD_GetStatus(USB_OTG_CORE_HANDLE *pdev, +static void USBD_GetStatus(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); -static void USBD_SetFeature(USB_OTG_CORE_HANDLE *pdev, +static void USBD_SetFeature(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); -static void USBD_ClrFeature(USB_OTG_CORE_HANDLE *pdev, +static void USBD_ClrFeature(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); static uint8_t USBD_GetLen(uint8_t *buf); /** * @} - */ + */ /** @defgroup USBD_REQ_Private_Functions * @{ - */ + */ /** @@ -140,45 +140,45 @@ static uint8_t USBD_GetLen(uint8_t *buf); */ USBD_Status USBD_StdDevReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { - USBD_Status ret = USBD_OK; - - switch (req->bRequest) + USBD_Status ret = USBD_OK; + + switch (req->bRequest) { - case USB_REQ_GET_DESCRIPTOR: - + case USB_REQ_GET_DESCRIPTOR: + USBD_GetDescriptor (pdev, req) ; break; - - case USB_REQ_SET_ADDRESS: + + case USB_REQ_SET_ADDRESS: USBD_SetAddress(pdev, req); break; - - case USB_REQ_SET_CONFIGURATION: + + case USB_REQ_SET_CONFIGURATION: USBD_SetConfig (pdev , req); break; - - case USB_REQ_GET_CONFIGURATION: + + case USB_REQ_GET_CONFIGURATION: USBD_GetConfig (pdev , req); break; - - case USB_REQ_GET_STATUS: + + case USB_REQ_GET_STATUS: USBD_GetStatus (pdev , req); break; - - - case USB_REQ_SET_FEATURE: - USBD_SetFeature (pdev , req); + + + case USB_REQ_SET_FEATURE: + USBD_SetFeature (pdev , req); break; - - case USB_REQ_CLEAR_FEATURE: + + case USB_REQ_CLEAR_FEATURE: USBD_ClrFeature (pdev , req); break; - - default: + + default: USBD_CtlError(pdev , req); break; } - + return ret; } @@ -191,27 +191,27 @@ USBD_Status USBD_StdDevReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) */ USBD_Status USBD_StdItfReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { - USBD_Status ret = USBD_OK; - - switch (pdev->dev.device_status) + USBD_Status ret = USBD_OK; + + switch (pdev->dev.device_status) { case USB_OTG_CONFIGURED: - - if (LOBYTE(req->wIndex) <= USBD_ITF_MAX_NUM) + + if (LOBYTE(req->wIndex) <= USBD_ITF_MAX_NUM) { - pdev->dev.class_cb->Setup (pdev, req); - + pdev->dev.class_cb->Setup (pdev, req); + if((req->wLength == 0)&& (ret == USBD_OK)) { USBD_CtlSendStatus(pdev); } - } - else - { + } + else + { USBD_CtlError(pdev , req); } break; - + default: USBD_CtlError(pdev , req); break; @@ -228,122 +228,122 @@ USBD_Status USBD_StdItfReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) */ USBD_Status USBD_StdEPReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { - + uint8_t ep_addr; - USBD_Status ret = USBD_OK; - - ep_addr = LOBYTE(req->wIndex); - - switch (req->bRequest) + USBD_Status ret = USBD_OK; + + ep_addr = LOBYTE(req->wIndex); + + switch (req->bRequest) { - + case USB_REQ_SET_FEATURE : - - switch (pdev->dev.device_status) + + switch (pdev->dev.device_status) { - case USB_OTG_ADDRESSED: - if ((ep_addr != 0x00) && (ep_addr != 0x80)) + case USB_OTG_ADDRESSED: + if ((ep_addr != 0x00) && (ep_addr != 0x80)) { DCD_EP_Stall(pdev , ep_addr); } - break; - - case USB_OTG_CONFIGURED: + break; + + case USB_OTG_CONFIGURED: if (req->wValue == USB_FEATURE_EP_HALT) { - if ((ep_addr != 0x00) && (ep_addr != 0x80)) - { + if ((ep_addr != 0x00) && (ep_addr != 0x80)) + { DCD_EP_Stall(pdev , ep_addr); - + } } - pdev->dev.class_cb->Setup (pdev, req); + pdev->dev.class_cb->Setup (pdev, req); USBD_CtlSendStatus(pdev); - + break; - - default: + + default: USBD_CtlError(pdev , req); - break; + break; } break; - + case USB_REQ_CLEAR_FEATURE : - - switch (pdev->dev.device_status) + + switch (pdev->dev.device_status) { - case USB_OTG_ADDRESSED: - if ((ep_addr != 0x00) && (ep_addr != 0x80)) + case USB_OTG_ADDRESSED: + if ((ep_addr != 0x00) && (ep_addr != 0x80)) { DCD_EP_Stall(pdev , ep_addr); } - break; - - case USB_OTG_CONFIGURED: + break; + + case USB_OTG_CONFIGURED: if (req->wValue == USB_FEATURE_EP_HALT) { - if ((ep_addr != 0x00) && (ep_addr != 0x80)) - { + if ((ep_addr != 0x00) && (ep_addr != 0x80)) + { DCD_EP_ClrStall(pdev , ep_addr); pdev->dev.class_cb->Setup (pdev, req); } USBD_CtlSendStatus(pdev); } break; - - default: + + default: USBD_CtlError(pdev , req); - break; + break; } break; - - case USB_REQ_GET_STATUS: - switch (pdev->dev.device_status) + + case USB_REQ_GET_STATUS: + switch (pdev->dev.device_status) { - case USB_OTG_ADDRESSED: - if ((ep_addr != 0x00) && (ep_addr != 0x80)) + case USB_OTG_ADDRESSED: + if ((ep_addr != 0x00) && (ep_addr != 0x80)) { DCD_EP_Stall(pdev , ep_addr); } - break; - - case USB_OTG_CONFIGURED: - - + break; + + case USB_OTG_CONFIGURED: + + if ((ep_addr & 0x80)== 0x80) { if(pdev->dev.in_ep[ep_addr & 0x7F].is_stall) { - USBD_ep_status = 0x0001; + USBD_ep_status = 0x0001; } else { - USBD_ep_status = 0x0000; + USBD_ep_status = 0x0000; } } else if ((ep_addr & 0x80)== 0x00) { if(pdev->dev.out_ep[ep_addr].is_stall) { - USBD_ep_status = 0x0001; + USBD_ep_status = 0x0001; } - - else + + else { - USBD_ep_status = 0x0000; - } + USBD_ep_status = 0x0000; + } } USBD_CtlSendData (pdev, (uint8_t *)&USBD_ep_status, 2); break; - - default: + + default: USBD_CtlError(pdev , req); break; } break; - + default: break; } @@ -356,22 +356,22 @@ USBD_Status USBD_StdEPReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) * @param req: usb request * @retval status */ -static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE *pdev, +static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { uint16_t len; uint8_t *pbuf; - + switch (req->wValue >> 8) { case USB_DESC_TYPE_DEVICE: pbuf = pdev->dev.usr_device->GetDeviceDescriptor(pdev->cfg.speed, &len); - if ((req->wLength == 64) ||( pdev->dev.device_status == USB_OTG_DEFAULT)) - { + if ((req->wLength == 64) ||( pdev->dev.device_status == USB_OTG_DEFAULT)) + { len = 8; } break; - + case USB_DESC_TYPE_CONFIGURATION: pbuf = (uint8_t *)pdev->dev.class_cb->GetConfigDescriptor(pdev->cfg.speed, &len); #ifdef USB_OTG_HS_CORE @@ -380,59 +380,59 @@ static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE *pdev, { pbuf = (uint8_t *)pdev->dev.class_cb->GetOtherConfigDescriptor(pdev->cfg.speed, &len); } -#endif +#endif pbuf[1] = USB_DESC_TYPE_CONFIGURATION; - pdev->dev.pConfig_descriptor = pbuf; + pdev->dev.pConfig_descriptor = pbuf; break; - + case USB_DESC_TYPE_STRING: switch ((uint8_t)(req->wValue)) { case USBD_IDX_LANGID_STR: - pbuf = pdev->dev.usr_device->GetLangIDStrDescriptor(pdev->cfg.speed, &len); + pbuf = pdev->dev.usr_device->GetLangIDStrDescriptor(pdev->cfg.speed, &len); break; - + case USBD_IDX_MFC_STR: pbuf = pdev->dev.usr_device->GetManufacturerStrDescriptor(pdev->cfg.speed, &len); break; - + case USBD_IDX_PRODUCT_STR: pbuf = pdev->dev.usr_device->GetProductStrDescriptor(pdev->cfg.speed, &len); break; - + case USBD_IDX_SERIAL_STR: pbuf = pdev->dev.usr_device->GetSerialStrDescriptor(pdev->cfg.speed, &len); break; - + case USBD_IDX_CONFIG_STR: pbuf = pdev->dev.usr_device->GetConfigurationStrDescriptor(pdev->cfg.speed, &len); break; - + case USBD_IDX_INTERFACE_STR: pbuf = pdev->dev.usr_device->GetInterfaceStrDescriptor(pdev->cfg.speed, &len); break; - + default: #ifdef USB_SUPPORT_USER_STRING_DESC pbuf = pdev->dev.class_cb->GetUsrStrDescriptor(pdev->cfg.speed, (req->wValue) , &len); break; -#else +#else USBD_CtlError(pdev , req); return; -#endif /* USBD_CtlError(pdev , req); */ +#endif /* USBD_CtlError(pdev , req); */ } break; - case USB_DESC_TYPE_DEVICE_QUALIFIER: + case USB_DESC_TYPE_DEVICE_QUALIFIER: #ifdef USB_OTG_HS_CORE - if(pdev->cfg.speed == USB_OTG_SPEED_HIGH ) + if(pdev->cfg.speed == USB_OTG_SPEED_HIGH ) { - + pbuf = (uint8_t *)pdev->dev.class_cb->GetConfigDescriptor(pdev->cfg.speed, &len); - + USBD_DeviceQualifierDesc[4]= pbuf[14]; USBD_DeviceQualifierDesc[5]= pbuf[15]; USBD_DeviceQualifierDesc[6]= pbuf[16]; - + pbuf = USBD_DeviceQualifierDesc; len = USB_LEN_DEV_QUALIFIER_DESC; break; @@ -445,16 +445,16 @@ static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE *pdev, #else USBD_CtlError(pdev , req); return; -#endif +#endif case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION: -#ifdef USB_OTG_HS_CORE +#ifdef USB_OTG_HS_CORE - if(pdev->cfg.speed == USB_OTG_SPEED_HIGH ) + if(pdev->cfg.speed == USB_OTG_SPEED_HIGH ) { pbuf = (uint8_t *)pdev->dev.class_cb->GetOtherConfigDescriptor(pdev->cfg.speed, &len); pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION; - break; + break; } else { @@ -464,24 +464,24 @@ static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE *pdev, #else USBD_CtlError(pdev , req); return; -#endif +#endif + - - default: + default: USBD_CtlError(pdev , req); return; } - + if((len != 0)&& (req->wLength != 0)) { - + len = MIN(len , req->wLength); - - USBD_CtlSendData (pdev, + + USBD_CtlSendData (pdev, pbuf, len); } - + } /** @@ -491,39 +491,39 @@ static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE *pdev, * @param req: usb request * @retval status */ -static void USBD_SetAddress(USB_OTG_CORE_HANDLE *pdev, +static void USBD_SetAddress(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { - uint8_t dev_addr; - - if ((req->wIndex == 0) && (req->wLength == 0)) + uint8_t dev_addr; + + if ((req->wIndex == 0) && (req->wLength == 0)) { - dev_addr = (uint8_t)(req->wValue) & 0x7F; - - if (pdev->dev.device_status == USB_OTG_CONFIGURED) + dev_addr = (uint8_t)(req->wValue) & 0x7F; + + if (pdev->dev.device_status == USB_OTG_CONFIGURED) { USBD_CtlError(pdev , req); - } - else + } + else { pdev->dev.device_address = dev_addr; - DCD_EP_SetAddress(pdev, dev_addr); - USBD_CtlSendStatus(pdev); - - if (dev_addr != 0) + DCD_EP_SetAddress(pdev, dev_addr); + USBD_CtlSendStatus(pdev); + + if (dev_addr != 0) { pdev->dev.device_status = USB_OTG_ADDRESSED; - } - else + } + else { - pdev->dev.device_status = USB_OTG_DEFAULT; + pdev->dev.device_status = USB_OTG_DEFAULT; } } - } - else + } + else { - USBD_CtlError(pdev , req); - } + USBD_CtlError(pdev , req); + } } /** @@ -533,50 +533,50 @@ static void USBD_SetAddress(USB_OTG_CORE_HANDLE *pdev, * @param req: usb request * @retval status */ -static void USBD_SetConfig(USB_OTG_CORE_HANDLE *pdev, +static void USBD_SetConfig(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { - + static uint8_t cfgidx; - - cfgidx = (uint8_t)(req->wValue); - - if (cfgidx > USBD_CFG_MAX_NUM ) - { - USBD_CtlError(pdev , req); - } - else + + cfgidx = (uint8_t)(req->wValue); + + if (cfgidx > USBD_CFG_MAX_NUM ) { - switch (pdev->dev.device_status) + USBD_CtlError(pdev , req); + } + else + { + switch (pdev->dev.device_status) { case USB_OTG_ADDRESSED: - if (cfgidx) - { + if (cfgidx) + { pdev->dev.device_config = cfgidx; pdev->dev.device_status = USB_OTG_CONFIGURED; USBD_SetCfg(pdev , cfgidx); USBD_CtlSendStatus(pdev); } - else + else { USBD_CtlSendStatus(pdev); } break; - + case USB_OTG_CONFIGURED: - if (cfgidx == 0) - { + if (cfgidx == 0) + { pdev->dev.device_status = USB_OTG_ADDRESSED; - pdev->dev.device_config = cfgidx; + pdev->dev.device_config = cfgidx; USBD_ClrCfg(pdev , cfgidx); USBD_CtlSendStatus(pdev); - - } - else if (cfgidx != pdev->dev.device_config) + + } + else if (cfgidx != pdev->dev.device_config) { /* Clear old configuration */ USBD_ClrCfg(pdev , pdev->dev.device_config); - + /* set new configuration */ pdev->dev.device_config = cfgidx; USBD_SetCfg(pdev , cfgidx); @@ -587,9 +587,9 @@ static void USBD_SetConfig(USB_OTG_CORE_HANDLE *pdev, USBD_CtlSendStatus(pdev); } break; - - default: - USBD_CtlError(pdev , req); + + default: + USBD_CtlError(pdev , req); break; } } @@ -602,32 +602,32 @@ static void USBD_SetConfig(USB_OTG_CORE_HANDLE *pdev, * @param req: usb request * @retval status */ -static void USBD_GetConfig(USB_OTG_CORE_HANDLE *pdev, +static void USBD_GetConfig(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { - - if (req->wLength != 1) - { + + if (req->wLength != 1) + { USBD_CtlError(pdev , req); } - else + else { - switch (pdev->dev.device_status ) + switch (pdev->dev.device_status ) { - case USB_OTG_ADDRESSED: - - USBD_CtlSendData (pdev, + case USB_OTG_ADDRESSED: + + USBD_CtlSendData (pdev, (uint8_t *)&USBD_default_cfg, 1); break; - - case USB_OTG_CONFIGURED: - - USBD_CtlSendData (pdev, + + case USB_OTG_CONFIGURED: + + USBD_CtlSendData (pdev, &pdev->dev.device_config, 1); break; - + default: USBD_CtlError(pdev , req); break; @@ -642,31 +642,31 @@ static void USBD_GetConfig(USB_OTG_CORE_HANDLE *pdev, * @param req: usb request * @retval status */ -static void USBD_GetStatus(USB_OTG_CORE_HANDLE *pdev, +static void USBD_GetStatus(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { - - switch (pdev->dev.device_status) + + switch (pdev->dev.device_status) { case USB_OTG_ADDRESSED: case USB_OTG_CONFIGURED: - - if (pdev->dev.DevRemoteWakeup) + + if (pdev->dev.DevRemoteWakeup) { - USBD_cfg_status = USB_CONFIG_SELF_POWERED | USB_CONFIG_REMOTE_WAKEUP; + USBD_cfg_status = USB_CONFIG_SELF_POWERED | USB_CONFIG_REMOTE_WAKEUP; } else { - USBD_cfg_status = USB_CONFIG_SELF_POWERED; + USBD_cfg_status = USB_CONFIG_SELF_POWERED; } - - USBD_CtlSendData (pdev, + + USBD_CtlSendData (pdev, (uint8_t *)&USBD_cfg_status, 1); break; - + default : - USBD_CtlError(pdev , req); + USBD_CtlError(pdev , req); break; } } @@ -679,44 +679,44 @@ static void USBD_GetStatus(USB_OTG_CORE_HANDLE *pdev, * @param req: usb request * @retval status */ -static void USBD_SetFeature(USB_OTG_CORE_HANDLE *pdev, +static void USBD_SetFeature(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { USB_OTG_DCTL_TypeDef dctl; uint8_t test_mode = 0; - + if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) { - pdev->dev.DevRemoteWakeup = 1; - pdev->dev.class_cb->Setup (pdev, req); + pdev->dev.DevRemoteWakeup = 1; + pdev->dev.class_cb->Setup (pdev, req); USBD_CtlSendStatus(pdev); } - else if ((req->wValue == USB_FEATURE_TEST_MODE) && + else if ((req->wValue == USB_FEATURE_TEST_MODE) && ((req->wIndex & 0xFF) == 0)) { dctl.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DCTL); - + test_mode = req->wIndex >> 8; - switch (test_mode) + switch (test_mode) { case 1: // TEST_J dctl.b.tstctl = 1; break; - - case 2: // TEST_K + + case 2: // TEST_K dctl.b.tstctl = 2; break; - + case 3: // TEST_SE0_NAK dctl.b.tstctl = 3; break; - + case 4: // TEST_PACKET dctl.b.tstctl = 4; break; - + case 5: // TEST_FORCE_ENABLE dctl.b.tstctl = 5; break; @@ -735,21 +735,21 @@ static void USBD_SetFeature(USB_OTG_CORE_HANDLE *pdev, * @param req: usb request * @retval status */ -static void USBD_ClrFeature(USB_OTG_CORE_HANDLE *pdev, +static void USBD_ClrFeature(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { switch (pdev->dev.device_status) { case USB_OTG_ADDRESSED: case USB_OTG_CONFIGURED: - if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) + if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) { - pdev->dev.DevRemoteWakeup = 0; - pdev->dev.class_cb->Setup (pdev, req); + pdev->dev.DevRemoteWakeup = 0; + pdev->dev.class_cb->Setup (pdev, req); USBD_CtlSendStatus(pdev); } break; - + default : USBD_CtlError(pdev , req); break; @@ -757,7 +757,7 @@ static void USBD_ClrFeature(USB_OTG_CORE_HANDLE *pdev, } /** -* @brief USBD_ParseSetupRequest +* @brief USBD_ParseSetupRequest * Copy buffer into setup structure * @param pdev: device instance * @param req: usb request @@ -772,13 +772,13 @@ void USBD_ParseSetupRequest( USB_OTG_CORE_HANDLE *pdev, req->wValue = SWAPBYTE (pdev->dev.setup_packet + 2); req->wIndex = SWAPBYTE (pdev->dev.setup_packet + 4); req->wLength = SWAPBYTE (pdev->dev.setup_packet + 6); - + pdev->dev.in_ep[0].ctl_data_len = req->wLength ; pdev->dev.device_state = USB_OTG_EP0_SETUP; } /** -* @brief USBD_CtlError +* @brief USBD_CtlError * Handle USB low level Error * @param pdev: device instance * @param req: usb request @@ -792,7 +792,7 @@ void USBD_CtlError( USB_OTG_CORE_HANDLE *pdev, { DCD_EP_Stall(pdev , 0x80); } - else + else { if(req->wLength == 0) { @@ -803,7 +803,7 @@ void USBD_CtlError( USB_OTG_CORE_HANDLE *pdev, DCD_EP_Stall(pdev , 0); } } - USB_OTG_EP0_OutStart(pdev); + USB_OTG_EP0_OutStart(pdev); } @@ -818,19 +818,19 @@ void USBD_CtlError( USB_OTG_CORE_HANDLE *pdev, void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len) { uint8_t idx = 0; - - if (desc != NULL) + + if (desc != NULL) { - *len = USBD_GetLen(desc) * 2 + 2; + *len = USBD_GetLen(desc) * 2 + 2; unicode[idx++] = *len; unicode[idx++] = USB_DESC_TYPE_STRING; - - while (*desc != NULL) + + while (*desc != NULL) { unicode[idx++] = *desc++; unicode[idx++] = 0x00; } - } + } } /** @@ -843,7 +843,7 @@ static uint8_t USBD_GetLen(uint8_t *buf) { uint8_t len = 0; - while (*buf != NULL) + while (*buf != NULL) { len++; buf++; @@ -853,16 +853,16 @@ static uint8_t USBD_GetLen(uint8_t *buf) } /** * @} - */ + */ /** * @} - */ + */ /** * @} - */ + */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_lib/core/usbd_req.h b/codec2-dev/stm32/usb_lib/core/usbd_req.h index 9aa9e44a..f73bb45c 100644 --- a/codec2-dev/stm32/usb_lib/core/usbd_req.h +++ b/codec2-dev/stm32/usb_lib/core/usbd_req.h @@ -6,7 +6,7 @@ * @date 22-July-2011 * @brief header file for the usbd_req.c file ****************************************************************************** - * @attention + * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE @@ -17,7 +17,7 @@ * *

© COPYRIGHT 2011 STMicroelectronics

****************************************************************************** - */ + */ /* Define to prevent recursive inclusion -------------------------------------*/ @@ -33,18 +33,18 @@ /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ - + /** @defgroup USBD_REQ * @brief header file for the usbd_ioreq.c file * @{ - */ + */ /** @defgroup USBD_REQ_Exported_Defines * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_REQ_Exported_Types @@ -52,27 +52,27 @@ */ /** * @} - */ + */ /** @defgroup USBD_REQ_Exported_Macros * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_REQ_Exported_Variables * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_REQ_Exported_FunctionsPrototype * @{ - */ + */ USBD_Status USBD_StdDevReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); USBD_Status USBD_StdItfReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); @@ -86,17 +86,17 @@ void USBD_CtlError( USB_OTG_CORE_HANDLE *pdev, void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len); /** * @} - */ + */ #endif /* __USB_REQUEST_H_ */ /** * @} - */ + */ /** * @} -*/ +*/ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_lib/core/usbd_usr.h b/codec2-dev/stm32/usb_lib/core/usbd_usr.h index 44e7b1dd..976cc135 100644 --- a/codec2-dev/stm32/usb_lib/core/usbd_usr.h +++ b/codec2-dev/stm32/usb_lib/core/usbd_usr.h @@ -17,7 +17,7 @@ * *

© COPYRIGHT 2011 STMicroelectronics

****************************************************************************** - */ + */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USBD_USR_H__ @@ -38,12 +38,12 @@ /** @defgroup USBD_USR * @brief This file is the Header file for usbd_usr.c * @{ - */ + */ /** @defgroup USBD_USR_Exported_Types * @{ - */ + */ extern USBD_Usr_cb_TypeDef USR_cb; extern USBD_Usr_cb_TypeDef USR_FS_cb; @@ -53,28 +53,28 @@ extern USBD_Usr_cb_TypeDef USR_HS_cb; /** * @} - */ + */ /** @defgroup USBD_USR_Exported_Defines * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_USR_Exported_Macros * @{ - */ + */ /** * @} - */ + */ /** @defgroup USBD_USR_Exported_Variables * @{ - */ + */ void USBD_USR_Init(void); void USBD_USR_DeviceReset (uint8_t speed); @@ -83,7 +83,7 @@ void USBD_USR_DeviceSuspended(void); void USBD_USR_DeviceResumed(void); void USBD_USR_DeviceConnected(void); -void USBD_USR_DeviceDisconnected(void); +void USBD_USR_DeviceDisconnected(void); void USBD_USR_FS_Init(void); void USBD_USR_FS_DeviceReset (uint8_t speed); @@ -92,7 +92,7 @@ void USBD_USR_FS_DeviceSuspended(void); void USBD_USR_FS_DeviceResumed(void); void USBD_USR_FS_DeviceConnected(void); -void USBD_USR_FS_DeviceDisconnected(void); +void USBD_USR_FS_DeviceDisconnected(void); void USBD_USR_HS_Init(void); void USBD_USR_HS_DeviceReset (uint8_t speed); @@ -101,32 +101,32 @@ void USBD_USR_HS_DeviceSuspended(void); void USBD_USR_HS_DeviceResumed(void); void USBD_USR_HS_DeviceConnected(void); -void USBD_USR_HS_DeviceDisconnected(void); +void USBD_USR_HS_DeviceDisconnected(void); /** * @} - */ + */ /** @defgroup USBD_USR_Exported_FunctionsPrototype * @{ - */ + */ /** * @} - */ + */ #endif /*__USBD_USR_H__*/ /** * @} - */ + */ /** * @} - */ + */ /** * @} - */ + */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_lib/otg/usb_core.c b/codec2-dev/stm32/usb_lib/otg/usb_core.c index 74e432ac..723d9586 100644 --- a/codec2-dev/stm32/usb_lib/otg/usb_core.c +++ b/codec2-dev/stm32/usb_lib/otg/usb_core.c @@ -6,13 +6,13 @@ * @date 22-July-2011 * @brief USB-OTG Core Layer ****************************************************************************** - * @attention + * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE + * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * *

© COPYRIGHT 2011 STMicroelectronics

@@ -28,7 +28,7 @@ * @{ */ -/** @defgroup USB_CORE +/** @defgroup USB_CORE * @brief This file includes the USB-OTG Core Layer * @{ */ @@ -36,49 +36,49 @@ /** @defgroup USB_CORE_Private_Defines * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_CORE_Private_TypesDefinitions * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_CORE_Private_Macros * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_CORE_Private_Variables * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_CORE_Private_FunctionPrototypes * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_CORE_Private_Functions * @{ -*/ +*/ /** * @brief USB_OTG_EnableCommonInt @@ -89,7 +89,7 @@ static void USB_OTG_EnableCommonInt(USB_OTG_CORE_HANDLE *pdev) { USB_OTG_GINTMSK_TypeDef int_mask; - + int_mask.d32 = 0; /* Clear any pending USB_OTG Interrupts */ #ifndef USE_OTG_MODE @@ -99,8 +99,8 @@ static void USB_OTG_EnableCommonInt(USB_OTG_CORE_HANDLE *pdev) USB_OTG_WRITE_REG32( &pdev->regs.GREGS->GINTSTS, 0xFFFFFFFF); /* Enable the interrupts in the INTMSK */ int_mask.b.wkupintr = 1; - int_mask.b.usbsuspend = 1; - + int_mask.b.usbsuspend = 1; + #ifdef USE_OTG_MODE int_mask.b.otgintr = 1; int_mask.b.sessreqintr = 1; @@ -119,7 +119,7 @@ static USB_OTG_STS USB_OTG_CoreReset(USB_OTG_CORE_HANDLE *pdev) USB_OTG_STS status = USB_OTG_OK; __IO USB_OTG_GRSTCTL_TypeDef greset; uint32_t count = 0; - + greset.d32 = 0; /* Wait for AHB master IDLE state. */ do @@ -151,7 +151,7 @@ static USB_OTG_STS USB_OTG_CoreReset(USB_OTG_CORE_HANDLE *pdev) } /** -* @brief USB_OTG_WritePacket : Writes a packet into the Tx FIFO associated +* @brief USB_OTG_WritePacket : Writes a packet into the Tx FIFO associated * with the EP * @param pdev : Selected device * @param src : source pointer @@ -159,9 +159,9 @@ static USB_OTG_STS USB_OTG_CoreReset(USB_OTG_CORE_HANDLE *pdev) * @param bytes : No. of bytes * @retval USB_OTG_STS : status */ -USB_OTG_STS USB_OTG_WritePacket(USB_OTG_CORE_HANDLE *pdev, - uint8_t *src, - uint8_t ch_ep_num, +USB_OTG_STS USB_OTG_WritePacket(USB_OTG_CORE_HANDLE *pdev, + uint8_t *src, + uint8_t ch_ep_num, uint16_t len) { USB_OTG_STS status = USB_OTG_OK; @@ -169,7 +169,7 @@ USB_OTG_STS USB_OTG_WritePacket(USB_OTG_CORE_HANDLE *pdev, { uint32_t count32b= 0 , i= 0; __IO uint32_t *fifo; - + count32b = (len + 3) / 4; fifo = pdev->regs.DFIFO[ch_ep_num]; for (i = 0; i < count32b; i++, src+=4) @@ -188,42 +188,42 @@ USB_OTG_STS USB_OTG_WritePacket(USB_OTG_CORE_HANDLE *pdev, * @param bytes : No. of bytes * @retval None */ -void *USB_OTG_ReadPacket(USB_OTG_CORE_HANDLE *pdev, - uint8_t *dest, +void *USB_OTG_ReadPacket(USB_OTG_CORE_HANDLE *pdev, + uint8_t *dest, uint16_t len) { uint32_t i=0; uint32_t count32b = (len + 3) / 4; - + __IO uint32_t *fifo = pdev->regs.DFIFO[0]; - + for ( i = 0; i < count32b; i++, dest += 4 ) { *(__packed uint32_t *)dest = USB_OTG_READ_REG32(fifo); - + } return ((void *)dest); } /** -* @brief USB_OTG_SelectCore +* @brief USB_OTG_SelectCore * Initialize core registers address. * @param pdev : Selected device * @param coreID : USB OTG Core ID * @retval USB_OTG_STS : status */ -USB_OTG_STS USB_OTG_SelectCore(USB_OTG_CORE_HANDLE *pdev, +USB_OTG_STS USB_OTG_SelectCore(USB_OTG_CORE_HANDLE *pdev, USB_OTG_CORE_ID_TypeDef coreID) { uint32_t i , baseAddress = 0; USB_OTG_STS status = USB_OTG_OK; - + pdev->cfg.dma_enable = 0; - + /* at startup the core is in FS mode */ pdev->cfg.speed = USB_OTG_SPEED_FULL; - pdev->cfg.mps = USB_OTG_FS_MAX_PACKET_SIZE ; - + pdev->cfg.mps = USB_OTG_FS_MAX_PACKET_SIZE ; + /* initialize device cfg following its address */ if (coreID == USB_OTG_FS_CORE_ID) { @@ -232,55 +232,55 @@ USB_OTG_STS USB_OTG_SelectCore(USB_OTG_CORE_HANDLE *pdev, pdev->cfg.host_channels = 8 ; pdev->cfg.dev_endpoints = 4 ; pdev->cfg.TotalFifoSize = 320; /* in 32-bits */ - pdev->cfg.phy_itface = USB_OTG_EMBEDDED_PHY; - -#ifdef USB_OTG_FS_SOF_OUTPUT_ENABLED - pdev->cfg.Sof_output = 1; -#endif - -#ifdef USB_OTG_FS_LOW_PWR_MGMT_SUPPORT - pdev->cfg.low_power = 1; -#endif + pdev->cfg.phy_itface = USB_OTG_EMBEDDED_PHY; + +#ifdef USB_OTG_FS_SOF_OUTPUT_ENABLED + pdev->cfg.Sof_output = 1; +#endif + +#ifdef USB_OTG_FS_LOW_PWR_MGMT_SUPPORT + pdev->cfg.low_power = 1; +#endif } else if (coreID == USB_OTG_HS_CORE_ID) { baseAddress = USB_OTG_HS_BASE_ADDR; - pdev->cfg.coreID = USB_OTG_HS_CORE_ID; + pdev->cfg.coreID = USB_OTG_HS_CORE_ID; pdev->cfg.host_channels = 12 ; pdev->cfg.dev_endpoints = 6 ; pdev->cfg.TotalFifoSize = 1280;/* in 32-bits */ - + #ifdef USB_OTG_ULPI_PHY_ENABLED pdev->cfg.phy_itface = USB_OTG_ULPI_PHY; -#else +#else #ifdef USB_OTG_EMBEDDED_PHY_ENABLED pdev->cfg.phy_itface = USB_OTG_EMBEDDED_PHY; - #else - #ifdef USB_OTG_I2C_PHY_ENABLED - pdev->cfg.phy_itface = USB_OTG_I2C_PHY; + #else + #ifdef USB_OTG_I2C_PHY_ENABLED + pdev->cfg.phy_itface = USB_OTG_I2C_PHY; #endif - #endif -#endif - -#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED - pdev->cfg.dma_enable = 1; + #endif +#endif + +#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED + pdev->cfg.dma_enable = 1; #endif - -#ifdef USB_OTG_HS_SOF_OUTPUT_ENABLED - pdev->cfg.Sof_output = 1; -#endif - -#ifdef USB_OTG_HS_LOW_PWR_MGMT_SUPPORT - pdev->cfg.low_power = 1; -#endif - - } - + +#ifdef USB_OTG_HS_SOF_OUTPUT_ENABLED + pdev->cfg.Sof_output = 1; +#endif + +#ifdef USB_OTG_HS_LOW_PWR_MGMT_SUPPORT + pdev->cfg.low_power = 1; +#endif + + } + pdev->regs.GREGS = (USB_OTG_GREGS *)(baseAddress + \ USB_OTG_CORE_GLOBAL_REGS_OFFSET); pdev->regs.DREGS = (USB_OTG_DREGS *) (baseAddress + \ USB_OTG_DEV_GLOBAL_REG_OFFSET); - + for (i = 0; i < pdev->cfg.dev_endpoints; i++) { pdev->regs.INEP_REGS[i] = (USB_OTG_INEPREGS *) \ @@ -293,7 +293,7 @@ USB_OTG_STS USB_OTG_SelectCore(USB_OTG_CORE_HANDLE *pdev, pdev->regs.HREGS = (USB_OTG_HREGS *)(baseAddress + \ USB_OTG_HOST_GLOBAL_REG_OFFSET); pdev->regs.HPRT0 = (uint32_t *)(baseAddress + USB_OTG_HOST_PORT_REGS_OFFSET); - + for (i = 0; i < pdev->cfg.host_channels; i++) { pdev->regs.HC_REGS[i] = (USB_OTG_HC_REGS *)(baseAddress + \ @@ -306,7 +306,7 @@ USB_OTG_STS USB_OTG_SelectCore(USB_OTG_CORE_HANDLE *pdev, (i * USB_OTG_DATA_FIFO_SIZE)); } pdev->regs.PCGCCTL = (uint32_t *)(baseAddress + USB_OTG_PCGCCTL_OFFSET); - + return status; } @@ -325,61 +325,61 @@ USB_OTG_STS USB_OTG_CoreInit(USB_OTG_CORE_HANDLE *pdev) USB_OTG_GCCFG_TypeDef gccfg; USB_OTG_GI2CCTL_TypeDef i2cctl; USB_OTG_GAHBCFG_TypeDef ahbcfg; - + usbcfg.d32 = 0; gccfg.d32 = 0; ahbcfg.d32 = 0; - - + + if (pdev->cfg.phy_itface == USB_OTG_ULPI_PHY) { gccfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GCCFG); gccfg.b.pwdn = 0; - + if (pdev->cfg.Sof_output) { - gccfg.b.sofouten = 1; + gccfg.b.sofouten = 1; } USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GCCFG, gccfg.d32); - + /* Init The ULPI Interface */ usbcfg.d32 = 0; usbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GUSBCFG); - + usbcfg.b.physel = 0; /* HS Interface */ #ifdef USB_OTG_INTERNAL_VBUS_ENABLED usbcfg.b.ulpi_ext_vbus_drv = 0; /* Use internal VBUS */ #else - #ifdef USB_OTG_EXTERNAL_VBUS_ENABLED + #ifdef USB_OTG_EXTERNAL_VBUS_ENABLED usbcfg.b.ulpi_ext_vbus_drv = 1; /* Use external VBUS */ #endif -#endif - usbcfg.b.term_sel_dl_pulse = 0; /* Data line pulsing using utmi_txvalid */ +#endif + usbcfg.b.term_sel_dl_pulse = 0; /* Data line pulsing using utmi_txvalid */ usbcfg.b.ulpi_utmi_sel = 1; /* ULPI seleInterfacect */ - + usbcfg.b.phyif = 0; /* 8 bits */ usbcfg.b.ddrsel = 0; /* single data rate */ - + usbcfg.b.ulpi_fsls = 0; usbcfg.b.ulpi_clk_sus_m = 0; USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GUSBCFG, usbcfg.d32); - + /* Reset after a PHY select */ USB_OTG_CoreReset(pdev); - + if(pdev->cfg.dma_enable == 1) { - + ahbcfg.b.hburstlen = 5; /* 64 x 32-bits*/ ahbcfg.b.dmaenable = 1; USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GAHBCFG, ahbcfg.d32); - - } + + } } else /* FS interface (embedded Phy or I2C Phy) */ { - + usbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GUSBCFG);; usbcfg.b.physel = 1; /* FS Interface */ USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GUSBCFG, usbcfg.d32); @@ -388,34 +388,34 @@ USB_OTG_STS USB_OTG_CoreInit(USB_OTG_CORE_HANDLE *pdev) /* Enable the I2C interface and deactivate the power down*/ gccfg.d32 = 0; gccfg.b.pwdn = 1; - + if(pdev->cfg.phy_itface == USB_OTG_I2C_PHY) { gccfg.b.i2cifen = 1; - } + } gccfg.b.vbussensingA = 1 ; - gccfg.b.vbussensingB = 1 ; + gccfg.b.vbussensingB = 1 ; #ifndef VBUS_SENSING_ENABLED - gccfg.b.disablevbussensing = 1; -#endif - + gccfg.b.disablevbussensing = 1; +#endif + if(pdev->cfg.Sof_output) { - gccfg.b.sofouten = 1; + gccfg.b.sofouten = 1; } - + USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GCCFG, gccfg.d32); USB_OTG_BSP_mDelay(20); /* Program GUSBCFG.OtgUtmifsSel to I2C*/ usbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GUSBCFG); - + if(pdev->cfg.phy_itface == USB_OTG_I2C_PHY) { usbcfg.b.otgutmifssel = 1; } - + USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GUSBCFG, usbcfg.d32); - + if(pdev->cfg.phy_itface == USB_OTG_I2C_PHY) { /*Program GI2CCTL.I2CEn*/ @@ -425,9 +425,9 @@ USB_OTG_STS USB_OTG_CoreInit(USB_OTG_CORE_HANDLE *pdev) i2cctl.b.dat_se0 = 1; i2cctl.b.addr = 0x2D; USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GI2CCTL, i2cctl.d32); - + USB_OTG_BSP_mDelay(200); - + i2cctl.b.i2cen = 1; USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GI2CCTL, i2cctl.d32); USB_OTG_BSP_mDelay(200); @@ -436,12 +436,12 @@ USB_OTG_STS USB_OTG_CoreInit(USB_OTG_CORE_HANDLE *pdev) /* case the HS core is working in FS mode */ if(pdev->cfg.dma_enable == 1) { - + ahbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GAHBCFG); ahbcfg.b.hburstlen = 5; /* 64 x 32-bits*/ ahbcfg.b.dmaenable = 1; USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GAHBCFG, ahbcfg.d32); - + } /* initialize OTG features */ #ifdef USE_OTG_MODE @@ -463,7 +463,7 @@ USB_OTG_STS USB_OTG_EnableGlobalInt(USB_OTG_CORE_HANDLE *pdev) { USB_OTG_STS status = USB_OTG_OK; USB_OTG_GAHBCFG_TypeDef ahbcfg; - + ahbcfg.d32 = 0; ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */ USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GAHBCFG, 0, ahbcfg.d32); @@ -498,7 +498,7 @@ USB_OTG_STS USB_OTG_FlushTxFifo (USB_OTG_CORE_HANDLE *pdev , uint32_t num ) { USB_OTG_STS status = USB_OTG_OK; __IO USB_OTG_GRSTCTL_TypeDef greset; - + uint32_t count = 0; greset.d32 = 0; greset.b.txfflsh = 1; @@ -529,7 +529,7 @@ USB_OTG_STS USB_OTG_FlushRxFifo( USB_OTG_CORE_HANDLE *pdev ) USB_OTG_STS status = USB_OTG_OK; __IO USB_OTG_GRSTCTL_TypeDef greset; uint32_t count = 0; - + greset.d32 = 0; greset.b.rxfflsh = 1; USB_OTG_WRITE_REG32( &pdev->regs.GREGS->GRSTCTL, greset.d32 ); @@ -558,12 +558,12 @@ USB_OTG_STS USB_OTG_SetCurrentMode(USB_OTG_CORE_HANDLE *pdev , uint8_t mode) { USB_OTG_STS status = USB_OTG_OK; USB_OTG_GUSBCFG_TypeDef usbcfg; - + usbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GUSBCFG); - + usbcfg.b.force_host = 0; usbcfg.b.force_dev = 0; - + if ( mode == HOST_MODE) { usbcfg.b.force_host = 1; @@ -572,7 +572,7 @@ USB_OTG_STS USB_OTG_SetCurrentMode(USB_OTG_CORE_HANDLE *pdev , uint8_t mode) { usbcfg.b.force_dev = 1; } - + USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, usbcfg.d32); USB_OTG_BSP_mDelay(50); return status; @@ -646,36 +646,36 @@ USB_OTG_STS USB_OTG_CoreInitHost(USB_OTG_CORE_HANDLE *pdev) { USB_OTG_STS status = USB_OTG_OK; USB_OTG_FSIZ_TypeDef nptxfifosize; - USB_OTG_FSIZ_TypeDef ptxfifosize; + USB_OTG_FSIZ_TypeDef ptxfifosize; USB_OTG_HCFG_TypeDef hcfg; - + #ifdef USE_OTG_MODE USB_OTG_OTGCTL_TypeDef gotgctl; #endif - + uint32_t i = 0; - - nptxfifosize.d32 = 0; + + nptxfifosize.d32 = 0; ptxfifosize.d32 = 0; #ifdef USE_OTG_MODE gotgctl.d32 = 0; #endif hcfg.d32 = 0; - - + + /* configure charge pump IO */ USB_OTG_BSP_ConfigVBUS(pdev); - + /* Restart the Phy Clock */ USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, 0); - + /* Initialize Host Configuration Register */ USB_OTG_InitFSLSPClkSel(pdev , HCFG_48_MHZ); /* in init phase */ - + hcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.HREGS->HCFG); hcfg.b.fslssupp = 0; USB_OTG_WRITE_REG32(&pdev->regs.HREGS->HCFG, hcfg.d32); - + /* Configure data FIFO sizes */ /* Rx FIFO */ #ifdef USB_OTG_FS_CORE @@ -683,41 +683,41 @@ USB_OTG_STS USB_OTG_CoreInitHost(USB_OTG_CORE_HANDLE *pdev) { /* set Rx FIFO size */ USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GRXFSIZ, RX_FIFO_FS_SIZE); - nptxfifosize.b.startaddr = RX_FIFO_FS_SIZE; - nptxfifosize.b.depth = TXH_NP_FS_FIFOSIZ; + nptxfifosize.b.startaddr = RX_FIFO_FS_SIZE; + nptxfifosize.b.depth = TXH_NP_FS_FIFOSIZ; USB_OTG_WRITE_REG32(&pdev->regs.GREGS->DIEPTXF0_HNPTXFSIZ, nptxfifosize.d32); - + ptxfifosize.b.startaddr = RX_FIFO_FS_SIZE + TXH_NP_FS_FIFOSIZ; ptxfifosize.b.depth = TXH_P_FS_FIFOSIZ; - USB_OTG_WRITE_REG32(&pdev->regs.GREGS->HPTXFSIZ, ptxfifosize.d32); + USB_OTG_WRITE_REG32(&pdev->regs.GREGS->HPTXFSIZ, ptxfifosize.d32); } #endif -#ifdef USB_OTG_HS_CORE +#ifdef USB_OTG_HS_CORE if (pdev->cfg.coreID == USB_OTG_HS_CORE_ID) { /* set Rx FIFO size */ USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GRXFSIZ, RX_FIFO_HS_SIZE); - nptxfifosize.b.startaddr = RX_FIFO_HS_SIZE; - nptxfifosize.b.depth = TXH_NP_HS_FIFOSIZ; + nptxfifosize.b.startaddr = RX_FIFO_HS_SIZE; + nptxfifosize.b.depth = TXH_NP_HS_FIFOSIZ; USB_OTG_WRITE_REG32(&pdev->regs.GREGS->DIEPTXF0_HNPTXFSIZ, nptxfifosize.d32); - + ptxfifosize.b.startaddr = RX_FIFO_HS_SIZE + TXH_NP_HS_FIFOSIZ; ptxfifosize.b.depth = TXH_P_HS_FIFOSIZ; - USB_OTG_WRITE_REG32(&pdev->regs.GREGS->HPTXFSIZ, ptxfifosize.d32); + USB_OTG_WRITE_REG32(&pdev->regs.GREGS->HPTXFSIZ, ptxfifosize.d32); } -#endif - +#endif + #ifdef USE_OTG_MODE /* Clear Host Set HNP Enable in the USB_OTG Control Register */ gotgctl.b.hstsethnpen = 1; USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GOTGCTL, gotgctl.d32, 0); #endif - + /* Make sure the FIFOs are flushed. */ USB_OTG_FlushTxFifo(pdev, 0x10 ); /* all Tx FIFOs */ USB_OTG_FlushRxFifo(pdev); - - + + /* Clear all pending HC Interrupts */ for (i = 0; i < pdev->cfg.host_channels; i++) { @@ -727,18 +727,18 @@ USB_OTG_STS USB_OTG_CoreInitHost(USB_OTG_CORE_HANDLE *pdev) #ifndef USE_OTG_MODE USB_OTG_DriveVbus(pdev, 1); #endif - + USB_OTG_EnableHostInt(pdev); return status; } /** -* @brief USB_OTG_IsEvenFrame +* @brief USB_OTG_IsEvenFrame * This function returns the frame number for sof packet * @param pdev : Selected device * @retval Frame number */ -uint8_t USB_OTG_IsEvenFrame (USB_OTG_CORE_HANDLE *pdev) +uint8_t USB_OTG_IsEvenFrame (USB_OTG_CORE_HANDLE *pdev) { return !(USB_OTG_READ_REG32(&pdev->regs.HREGS->HFNUM) & 0x1); } @@ -752,12 +752,12 @@ uint8_t USB_OTG_IsEvenFrame (USB_OTG_CORE_HANDLE *pdev) void USB_OTG_DriveVbus (USB_OTG_CORE_HANDLE *pdev, uint8_t state) { USB_OTG_HPRT0_TypeDef hprt0; - + hprt0.d32 = 0; - + /* enable disable the external charge pump */ USB_OTG_BSP_DriveVBUS(pdev, state); - + /* Turn on the Host port power. */ hprt0.d32 = USB_OTG_ReadHPRT0(pdev); if ((hprt0.b.prtpwr == 0 ) && (state == 1 )) @@ -770,7 +770,7 @@ void USB_OTG_DriveVbus (USB_OTG_CORE_HANDLE *pdev, uint8_t state) hprt0.b.prtpwr = 0; USB_OTG_WRITE_REG32(pdev->regs.HPRT0, hprt0.d32); } - + USB_OTG_BSP_mDelay(200); } /** @@ -785,28 +785,28 @@ USB_OTG_STS USB_OTG_EnableHostInt(USB_OTG_CORE_HANDLE *pdev) intmsk.d32 = 0; /* Disable all interrupts. */ USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTMSK, 0); - + /* Clear any pending interrupts. */ USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, 0xFFFFFFFF); - + /* Enable the common interrupts */ USB_OTG_EnableCommonInt(pdev); - + if (pdev->cfg.dma_enable == 0) - { + { intmsk.b.rxstsqlvl = 1; - } + } intmsk.b.portintr = 1; intmsk.b.hcintr = 1; - intmsk.b.disconnect = 1; - intmsk.b.sofintr = 1; - intmsk.b.incomplisoout = 1; + intmsk.b.disconnect = 1; + intmsk.b.sofintr = 1; + intmsk.b.incomplisoout = 1; USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GINTMSK, intmsk.d32, intmsk.d32); return status; } /** -* @brief USB_OTG_InitFSLSPClkSel : Initializes the FSLSPClkSel field of the +* @brief USB_OTG_InitFSLSPClkSel : Initializes the FSLSPClkSel field of the * HCFG register on the PHY type * @param pdev : Selected device * @param freq : clock frequency @@ -815,7 +815,7 @@ USB_OTG_STS USB_OTG_EnableHostInt(USB_OTG_CORE_HANDLE *pdev) void USB_OTG_InitFSLSPClkSel(USB_OTG_CORE_HANDLE *pdev , uint8_t freq) { USB_OTG_HCFG_TypeDef hcfg; - + hcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.HREGS->HCFG); hcfg.b.fslspclksel = freq; USB_OTG_WRITE_REG32(&pdev->regs.HREGS->HCFG, hcfg.d32); @@ -830,7 +830,7 @@ void USB_OTG_InitFSLSPClkSel(USB_OTG_CORE_HANDLE *pdev , uint8_t freq) uint32_t USB_OTG_ReadHPRT0(USB_OTG_CORE_HANDLE *pdev) { USB_OTG_HPRT0_TypeDef hprt0; - + hprt0.d32 = USB_OTG_READ_REG32(pdev->regs.HPRT0); hprt0.b.prtena = 0; hprt0.b.prtconndet = 0; @@ -861,14 +861,14 @@ uint32_t USB_OTG_ReadHostAllChannels_intr (USB_OTG_CORE_HANDLE *pdev) uint32_t USB_OTG_ResetPort(USB_OTG_CORE_HANDLE *pdev) { USB_OTG_HPRT0_TypeDef hprt0; - + hprt0.d32 = USB_OTG_ReadHPRT0(pdev); hprt0.b.prtrst = 1; USB_OTG_WRITE_REG32(pdev->regs.HPRT0, hprt0.d32); USB_OTG_BSP_mDelay (10); /* See Note #1 */ hprt0.b.prtrst = 0; USB_OTG_WRITE_REG32(pdev->regs.HPRT0, hprt0.d32); - USB_OTG_BSP_mDelay (20); + USB_OTG_BSP_mDelay (20); return 1; } @@ -887,25 +887,25 @@ USB_OTG_STS USB_OTG_HC_Init(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num) USB_OTG_GINTMSK_TypeDef gintmsk; USB_OTG_HCCHAR_TypeDef hcchar; USB_OTG_HCINTn_TypeDef hcint; - - + + gintmsk.d32 = 0; hcintmsk.d32 = 0; hcchar.d32 = 0; - + /* Clear old interrupt conditions for this host channel. */ hcint.d32 = 0xFFFFFFFF; USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCINT, hcint.d32); - + /* Enable channel interrupts required for this transfer. */ hcintmsk.d32 = 0; - + if (pdev->cfg.dma_enable == 1) { hcintmsk.b.ahberr = 1; } - - switch (pdev->host.hc[hc_num].ep_type) + + switch (pdev->host.hc[hc_num].ep_type) { case EP_TYPE_CTRL: case EP_TYPE_BULK: @@ -913,15 +913,15 @@ USB_OTG_STS USB_OTG_HC_Init(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num) hcintmsk.b.stall = 1; hcintmsk.b.xacterr = 1; hcintmsk.b.datatglerr = 1; - hcintmsk.b.nak = 1; - if (pdev->host.hc[hc_num].ep_is_in) + hcintmsk.b.nak = 1; + if (pdev->host.hc[hc_num].ep_is_in) { hcintmsk.b.bblerr = 1; - } - else + } + else { hcintmsk.b.nyet = 1; - if (pdev->host.hc[hc_num].do_ping) + if (pdev->host.hc[hc_num].do_ping) { hcintmsk.b.ack = 1; } @@ -934,38 +934,38 @@ USB_OTG_STS USB_OTG_HC_Init(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num) hcintmsk.b.xacterr = 1; hcintmsk.b.datatglerr = 1; hcintmsk.b.frmovrun = 1; - - if (pdev->host.hc[hc_num].ep_is_in) + + if (pdev->host.hc[hc_num].ep_is_in) { hcintmsk.b.bblerr = 1; } - + break; case EP_TYPE_ISOC: hcintmsk.b.xfercompl = 1; hcintmsk.b.frmovrun = 1; hcintmsk.b.ack = 1; - - if (pdev->host.hc[hc_num].ep_is_in) + + if (pdev->host.hc[hc_num].ep_is_in) { hcintmsk.b.xacterr = 1; hcintmsk.b.bblerr = 1; } break; } - - + + USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCGINTMSK, hcintmsk.d32); - - + + /* Enable the top level host channel interrupt. */ intr_enable = (1 << hc_num); USB_OTG_MODIFY_REG32(&pdev->regs.HREGS->HAINTMSK, 0, intr_enable); - + /* Make sure host channel interrupts are enabled. */ gintmsk.b.hcintr = 1; USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GINTMSK, 0, gintmsk.d32); - + /* Program the HCCHAR register */ hcchar.d32 = 0; hcchar.b.devaddr = pdev->host.hc[hc_num].dev_addr; @@ -994,25 +994,25 @@ USB_OTG_STS USB_OTG_HC_StartXfer(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num) USB_OTG_STS status = USB_OTG_OK; USB_OTG_HCCHAR_TypeDef hcchar; USB_OTG_HCTSIZn_TypeDef hctsiz; - USB_OTG_HNPTXSTS_TypeDef hnptxsts; - USB_OTG_HPTXSTS_TypeDef hptxsts; + USB_OTG_HNPTXSTS_TypeDef hnptxsts; + USB_OTG_HPTXSTS_TypeDef hptxsts; USB_OTG_GINTMSK_TypeDef intmsk; - uint16_t len_words = 0; - + uint16_t len_words = 0; + uint16_t num_packets; uint16_t max_hc_pkt_count; - + max_hc_pkt_count = 256; hctsiz.d32 = 0; hcchar.d32 = 0; intmsk.d32 = 0; - + /* Compute the expected number of packets associated to the transfer */ if (pdev->host.hc[hc_num].xfer_len > 0) { num_packets = (pdev->host.hc[hc_num].xfer_len + \ pdev->host.hc[hc_num].max_packet - 1) / pdev->host.hc[hc_num].max_packet; - + if (num_packets > max_hc_pkt_count) { num_packets = max_hc_pkt_count; @@ -1034,43 +1034,43 @@ USB_OTG_STS USB_OTG_HC_StartXfer(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num) hctsiz.b.pktcnt = num_packets; hctsiz.b.pid = pdev->host.hc[hc_num].data_pid; USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCTSIZ, hctsiz.d32); - + if (pdev->cfg.dma_enable == 1) { USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCDMA, (unsigned int)pdev->host.hc[hc_num].xfer_buff); } - - + + hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR); hcchar.b.oddfrm = USB_OTG_IsEvenFrame(pdev); - + /* Set host channel enable */ hcchar.b.chen = 1; hcchar.b.chdis = 0; USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR, hcchar.d32); if (pdev->cfg.dma_enable == 0) /* Slave mode */ - { - if((pdev->host.hc[hc_num].ep_is_in == 0) && + { + if((pdev->host.hc[hc_num].ep_is_in == 0) && (pdev->host.hc[hc_num].xfer_len > 0)) { - switch(pdev->host.hc[hc_num].ep_type) + switch(pdev->host.hc[hc_num].ep_type) { /* Non periodic transfer */ case EP_TYPE_CTRL: case EP_TYPE_BULK: - + hnptxsts.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->HNPTXSTS); len_words = (pdev->host.hc[hc_num].xfer_len + 3) / 4; - + /* check if there is enough space in FIFO space */ if(len_words > hnptxsts.b.nptxfspcavail) { /* need to process data in nptxfempty interrupt */ intmsk.b.nptxfempty = 1; - USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, 0, intmsk.d32); + USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, 0, intmsk.d32); } - + break; /* Periodic transfer */ case EP_TYPE_INTR: @@ -1082,17 +1082,17 @@ USB_OTG_STS USB_OTG_HC_StartXfer(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num) { /* need to process data in ptxfempty interrupt */ intmsk.b.ptxfempty = 1; - USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, 0, intmsk.d32); + USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, 0, intmsk.d32); } break; - + default: break; } - + /* Write packet into the Tx FIFO. */ - USB_OTG_WritePacket(pdev, - pdev->host.hc[hc_num].xfer_buff , + USB_OTG_WritePacket(pdev, + pdev->host.hc[hc_num].xfer_buff , hc_num, pdev->host.hc[hc_num].xfer_len); } } @@ -1112,13 +1112,13 @@ USB_OTG_STS USB_OTG_HC_Halt(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num) USB_OTG_HNPTXSTS_TypeDef nptxsts; USB_OTG_HPTXSTS_TypeDef hptxsts; USB_OTG_HCCHAR_TypeDef hcchar; - + nptxsts.d32 = 0; hptxsts.d32 = 0; hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR); hcchar.b.chen = 1; hcchar.b.chdis = 1; - + /* Check for space in the request queue to issue the halt. */ if (hcchar.b.eptype == HCCHAR_CTRL || hcchar.b.eptype == HCCHAR_BULK) { @@ -1149,18 +1149,18 @@ USB_OTG_STS USB_OTG_HC_DoPing(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num) { USB_OTG_STS status = USB_OTG_OK; USB_OTG_HCCHAR_TypeDef hcchar; - USB_OTG_HCTSIZn_TypeDef hctsiz; - + USB_OTG_HCTSIZn_TypeDef hctsiz; + hctsiz.d32 = 0; hctsiz.b.dopng = 1; hctsiz.b.pktcnt = 1; USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCTSIZ, hctsiz.d32); - + hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR); hcchar.b.chen = 1; hcchar.b.chdis = 0; USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR, hcchar.d32); - return status; + return status; } /** @@ -1172,11 +1172,11 @@ void USB_OTG_StopHost(USB_OTG_CORE_HANDLE *pdev) { USB_OTG_HCCHAR_TypeDef hcchar; uint32_t i; - + USB_OTG_WRITE_REG32(&pdev->regs.HREGS->HAINTMSK , 0); USB_OTG_WRITE_REG32(&pdev->regs.HREGS->HAINT, 0xFFFFFFFF); /* Flush out any leftover queued requests. */ - + for (i = 0; i < pdev->cfg.host_channels; i++) { hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[i]->HCCHAR); @@ -1185,17 +1185,17 @@ void USB_OTG_StopHost(USB_OTG_CORE_HANDLE *pdev) hcchar.b.epdir = 0; USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[i]->HCCHAR, hcchar.d32); } - + /* Flush the FIFO */ USB_OTG_FlushRxFifo(pdev); - USB_OTG_FlushTxFifo(pdev , 0x10 ); + USB_OTG_FlushTxFifo(pdev , 0x10 ); } #endif #ifdef USE_DEVICE_MODE /* PCD Core Layer */ /** -* @brief USB_OTG_InitDevSpeed :Initializes the DevSpd field of DCFG register +* @brief USB_OTG_InitDevSpeed :Initializes the DevSpd field of DCFG register * depending the PHY type and the enumeration speed of the device. * @param pdev : Selected device * @retval : None @@ -1203,7 +1203,7 @@ void USB_OTG_StopHost(USB_OTG_CORE_HANDLE *pdev) void USB_OTG_InitDevSpeed(USB_OTG_CORE_HANDLE *pdev , uint8_t speed) { USB_OTG_DCFG_TypeDef dcfg; - + dcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DCFG); dcfg.b.devspd = speed; USB_OTG_WRITE_REG32(&pdev->regs.DREGS->DCFG, dcfg.d32); @@ -1211,7 +1211,7 @@ void USB_OTG_InitDevSpeed(USB_OTG_CORE_HANDLE *pdev , uint8_t speed) /** -* @brief USB_OTG_CoreInitDev : Initializes the USB_OTG controller registers +* @brief USB_OTG_CoreInitDev : Initializes the USB_OTG controller registers * for device mode * @param pdev : Selected device * @retval USB_OTG_STS : status @@ -1225,50 +1225,50 @@ USB_OTG_STS USB_OTG_CoreInitDev (USB_OTG_CORE_HANDLE *pdev) USB_OTG_FSIZ_TypeDef nptxfifosize; USB_OTG_FSIZ_TypeDef txfifosize; USB_OTG_DIEPMSK_TypeDef msk; - USB_OTG_DTHRCTL_TypeDef dthrctl; - + USB_OTG_DTHRCTL_TypeDef dthrctl; + depctl.d32 = 0; dcfg.d32 = 0; nptxfifosize.d32 = 0; txfifosize.d32 = 0; msk.d32 = 0; - + /* Restart the Phy Clock */ USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, 0); /* Device configuration register */ dcfg.d32 = USB_OTG_READ_REG32( &pdev->regs.DREGS->DCFG); dcfg.b.perfrint = DCFG_FRAME_INTERVAL_80; USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DCFG, dcfg.d32 ); - + #ifdef USB_OTG_FS_CORE if(pdev->cfg.coreID == USB_OTG_FS_CORE_ID ) - { - + { + /* Set Full speed phy */ USB_OTG_InitDevSpeed (pdev , USB_OTG_SPEED_PARAM_FULL); - + /* set Rx FIFO size */ USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GRXFSIZ, RX_FIFO_FS_SIZE); - + /* EP0 TX*/ nptxfifosize.b.depth = TX0_FIFO_FS_SIZE; nptxfifosize.b.startaddr = RX_FIFO_FS_SIZE; USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF0_HNPTXFSIZ, nptxfifosize.d32 ); - - + + /* EP1 TX*/ txfifosize.b.startaddr = nptxfifosize.b.startaddr + nptxfifosize.b.depth; txfifosize.b.depth = TX1_FIFO_FS_SIZE; USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[0], txfifosize.d32 ); - - + + /* EP2 TX*/ txfifosize.b.startaddr += txfifosize.b.depth; txfifosize.b.depth = TX2_FIFO_FS_SIZE; USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[1], txfifosize.d32 ); - - - /* EP3 TX*/ + + + /* EP3 TX*/ txfifosize.b.startaddr += txfifosize.b.depth; txfifosize.b.depth = TX3_FIFO_FS_SIZE; USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[2], txfifosize.d32 ); @@ -1277,9 +1277,9 @@ USB_OTG_STS USB_OTG_CoreInitDev (USB_OTG_CORE_HANDLE *pdev) #ifdef USB_OTG_HS_CORE if(pdev->cfg.coreID == USB_OTG_HS_CORE_ID ) { - + /* Set High speed phy */ - + if(pdev->cfg.phy_itface == USB_OTG_ULPI_PHY) { USB_OTG_InitDevSpeed (pdev , USB_OTG_SPEED_PARAM_HIGH); @@ -1288,45 +1288,45 @@ USB_OTG_STS USB_OTG_CoreInitDev (USB_OTG_CORE_HANDLE *pdev) { USB_OTG_InitDevSpeed (pdev , USB_OTG_SPEED_PARAM_HIGH_IN_FULL); } - + /* set Rx FIFO size */ USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GRXFSIZ, RX_FIFO_HS_SIZE); - + /* EP0 TX*/ nptxfifosize.b.depth = TX0_FIFO_HS_SIZE; nptxfifosize.b.startaddr = RX_FIFO_HS_SIZE; USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF0_HNPTXFSIZ, nptxfifosize.d32 ); - - + + /* EP1 TX*/ txfifosize.b.startaddr = nptxfifosize.b.startaddr + nptxfifosize.b.depth; txfifosize.b.depth = TX1_FIFO_HS_SIZE; USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[0], txfifosize.d32 ); - - + + /* EP2 TX*/ txfifosize.b.startaddr += txfifosize.b.depth; txfifosize.b.depth = TX2_FIFO_HS_SIZE; USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[1], txfifosize.d32 ); - - - /* EP3 TX*/ + + + /* EP3 TX*/ txfifosize.b.startaddr += txfifosize.b.depth; txfifosize.b.depth = TX3_FIFO_HS_SIZE; USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[2], txfifosize.d32 ); - + /* EP4 TX*/ txfifosize.b.startaddr += txfifosize.b.depth; txfifosize.b.depth = TX4_FIFO_HS_SIZE; USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[3], txfifosize.d32 ); - - - /* EP5 TX*/ + + + /* EP5 TX*/ txfifosize.b.startaddr += txfifosize.b.depth; txfifosize.b.depth = TX5_FIFO_HS_SIZE; USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[4], txfifosize.d32 ); } -#endif +#endif /* Flush the FIFOs */ USB_OTG_FlushTxFifo(pdev , 0x10); /* all Tx FIFOs */ USB_OTG_FlushRxFifo(pdev); @@ -1335,7 +1335,7 @@ USB_OTG_STS USB_OTG_CoreInitDev (USB_OTG_CORE_HANDLE *pdev) USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DOEPMSK, 0 ); USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DAINT, 0xFFFFFFFF ); USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DAINTMSK, 0 ); - + for (i = 0; i < pdev->cfg.dev_endpoints; i++) { depctl.d32 = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[i]->DIEPCTL); @@ -1374,7 +1374,7 @@ USB_OTG_STS USB_OTG_CoreInitDev (USB_OTG_CORE_HANDLE *pdev) msk.d32 = 0; msk.b.txfifoundrn = 1; USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPMSK, msk.d32, msk.d32); - + if (pdev->cfg.dma_enable == 1) { dthrctl.d32 = 0; @@ -1383,7 +1383,7 @@ USB_OTG_STS USB_OTG_CoreInitDev (USB_OTG_CORE_HANDLE *pdev) dthrctl.b.tx_thr_len = 64; dthrctl.b.rx_thr_en = 1; dthrctl.b.rx_thr_len = 64; - USB_OTG_WRITE_REG32(&pdev->regs.DREGS->DTHRCTL, dthrctl.d32); + USB_OTG_WRITE_REG32(&pdev->regs.DREGS->DTHRCTL, dthrctl.d32); } USB_OTG_EnableDevInt(pdev); return status; @@ -1399,35 +1399,35 @@ USB_OTG_STS USB_OTG_EnableDevInt(USB_OTG_CORE_HANDLE *pdev) { USB_OTG_STS status = USB_OTG_OK; USB_OTG_GINTMSK_TypeDef intmsk; - + intmsk.d32 = 0; - + /* Disable all interrupts. */ USB_OTG_WRITE_REG32( &pdev->regs.GREGS->GINTMSK, 0); /* Clear any pending interrupts */ USB_OTG_WRITE_REG32( &pdev->regs.GREGS->GINTSTS, 0xFFFFFFFF); /* Enable the common interrupts */ USB_OTG_EnableCommonInt(pdev); - + if (pdev->cfg.dma_enable == 0) { intmsk.b.rxstsqlvl = 1; } - + /* Enable interrupts matching to the Device mode ONLY */ intmsk.b.usbsuspend = 1; intmsk.b.usbreset = 1; intmsk.b.enumdone = 1; intmsk.b.inepintr = 1; intmsk.b.outepintr = 1; - intmsk.b.sofintr = 1; + intmsk.b.sofintr = 1; - intmsk.b.incomplisoin = 1; - intmsk.b.incomplisoout = 1; + intmsk.b.incomplisoin = 1; + intmsk.b.incomplisoout = 1; #ifdef VBUS_SENSING_ENABLED - intmsk.b.sessreqintr = 1; - intmsk.b.otgintr = 1; -#endif + intmsk.b.sessreqintr = 1; + intmsk.b.otgintr = 1; +#endif USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, intmsk.d32, intmsk.d32); return status; } @@ -1443,10 +1443,10 @@ enum USB_OTG_SPEED USB_OTG_GetDeviceSpeed (USB_OTG_CORE_HANDLE *pdev) { USB_OTG_DSTS_TypeDef dsts; enum USB_OTG_SPEED speed = USB_SPEED_UNKNOWN; - - + + dsts.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DSTS); - + switch (dsts.b.enumspd) { case DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ: @@ -1456,12 +1456,12 @@ enum USB_OTG_SPEED USB_OTG_GetDeviceSpeed (USB_OTG_CORE_HANDLE *pdev) case DSTS_ENUMSPD_FS_PHY_48MHZ: speed = USB_SPEED_FULL; break; - + case DSTS_ENUMSPD_LS_PHY_6MHZ: speed = USB_SPEED_LOW; break; } - + return speed; } /** @@ -1476,7 +1476,7 @@ USB_OTG_STS USB_OTG_EP0Activate(USB_OTG_CORE_HANDLE *pdev) USB_OTG_DSTS_TypeDef dsts; USB_OTG_DEPCTL_TypeDef diepctl; USB_OTG_DCTL_TypeDef dctl; - + dctl.d32 = 0; /* Read the Device Status and Endpoint 0 Control registers */ dsts.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DSTS); @@ -1511,8 +1511,8 @@ USB_OTG_STS USB_OTG_EPActivate(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) USB_OTG_DEPCTL_TypeDef depctl; USB_OTG_DAINT_TypeDef daintmsk; __IO uint32_t *addr; - - + + depctl.d32 = 0; daintmsk.d32 = 0; /* Read DEPCTLn register */ @@ -1545,7 +1545,7 @@ USB_OTG_STS USB_OTG_EPActivate(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DEACHMSK, 0, daintmsk.d32); } else -#endif +#endif USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DAINTMSK, 0, daintmsk.d32); return status; } @@ -1562,9 +1562,9 @@ USB_OTG_STS USB_OTG_EPDeactivate(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) USB_OTG_DEPCTL_TypeDef depctl; USB_OTG_DAINT_TypeDef daintmsk; __IO uint32_t *addr; - + depctl.d32 = 0; - daintmsk.d32 = 0; + daintmsk.d32 = 0; /* Read DEPCTLn register */ if (ep->is_in == 1) { @@ -1579,21 +1579,21 @@ USB_OTG_STS USB_OTG_EPDeactivate(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) depctl.b.usbactep = 0; USB_OTG_WRITE_REG32(addr, depctl.d32); /* Disable the Interrupt for this EP */ - + #ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED if((ep->num == 1)&&(pdev->cfg.coreID == USB_OTG_HS_CORE_ID)) { USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DEACHMSK, daintmsk.d32, 0); } else -#endif +#endif USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DAINTMSK, daintmsk.d32, 0); return status; } /** -* @brief USB_OTG_EPStartXfer : Handle the setup for data xfer for an EP and +* @brief USB_OTG_EPStartXfer : Handle the setup for data xfer for an EP and * starts the xfer * @param pdev : Selected device * @retval USB_OTG_STS : status @@ -1603,9 +1603,9 @@ USB_OTG_STS USB_OTG_EPStartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) USB_OTG_STS status = USB_OTG_OK; USB_OTG_DEPCTL_TypeDef depctl; USB_OTG_DEPXFRSIZ_TypeDef deptsiz; - USB_OTG_DSTS_TypeDef dsts; - uint32_t fifoemptymsk = 0; - + USB_OTG_DSTS_TypeDef dsts; + uint32_t fifoemptymsk = 0; + depctl.d32 = 0; deptsiz.d32 = 0; /* IN endpoint */ @@ -1632,10 +1632,10 @@ USB_OTG_STS USB_OTG_EPStartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) if (ep->type == EP_TYPE_ISOC) { deptsiz.b.mc = 1; - } + } } USB_OTG_WRITE_REG32(&pdev->regs.INEP_REGS[ep->num]->DIEPTSIZ, deptsiz.d32); - + if (pdev->cfg.dma_enable == 1) { USB_OTG_WRITE_REG32(&pdev->regs.INEP_REGS[ep->num]->DIEPDMA, ep->dma_addr); @@ -1652,12 +1652,12 @@ USB_OTG_STS USB_OTG_EPStartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) } } } - - + + if (ep->type == EP_TYPE_ISOC) { dsts.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DSTS); - + if (((dsts.b.soffn)&0x1) == 0) { depctl.b.setd1pid = 1; @@ -1666,8 +1666,8 @@ USB_OTG_STS USB_OTG_EPStartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) { depctl.b.setd0pid = 1; } - } - + } + /* EP enable, IN data in FIFO */ depctl.b.cnak = 1; depctl.b.epena = 1; @@ -1675,8 +1675,8 @@ USB_OTG_STS USB_OTG_EPStartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) if (ep->type == EP_TYPE_ISOC) { - USB_OTG_WritePacket(pdev, ep->xfer_buff, ep->num, ep->xfer_len); - } + USB_OTG_WritePacket(pdev, ep->xfer_buff, ep->num, ep->xfer_len); + } } else { @@ -1698,12 +1698,12 @@ USB_OTG_STS USB_OTG_EPStartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket; } USB_OTG_WRITE_REG32(&pdev->regs.OUTEP_REGS[ep->num]->DOEPTSIZ, deptsiz.d32); - + if (pdev->cfg.dma_enable == 1) { USB_OTG_WRITE_REG32(&pdev->regs.OUTEP_REGS[ep->num]->DOEPDMA, ep->dma_addr); } - + if (ep->type == EP_TYPE_ISOC) { if (ep->even_odd_frame) @@ -1725,7 +1725,7 @@ USB_OTG_STS USB_OTG_EPStartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) /** -* @brief USB_OTG_EP0StartXfer : Handle the setup for a data xfer for EP0 and +* @brief USB_OTG_EP0StartXfer : Handle the setup for a data xfer for EP0 and * starts the xfer * @param pdev : Selected device * @retval USB_OTG_STS : status @@ -1737,7 +1737,7 @@ USB_OTG_STS USB_OTG_EP0StartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) USB_OTG_DEP0XFRSIZ_TypeDef deptsiz; USB_OTG_INEPREGS *in_regs; uint32_t fifoemptymsk = 0; - + depctl.d32 = 0; deptsiz.d32 = 0; /* IN endpoint */ @@ -1751,7 +1751,7 @@ USB_OTG_STS USB_OTG_EP0StartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) { deptsiz.b.xfersize = 0; deptsiz.b.pktcnt = 1; - + } else { @@ -1767,19 +1767,19 @@ USB_OTG_STS USB_OTG_EP0StartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) deptsiz.b.pktcnt = 1; } USB_OTG_WRITE_REG32(&in_regs->DIEPTSIZ, deptsiz.d32); - + if (pdev->cfg.dma_enable == 1) { - USB_OTG_WRITE_REG32(&pdev->regs.INEP_REGS[ep->num]->DIEPDMA, ep->dma_addr); + USB_OTG_WRITE_REG32(&pdev->regs.INEP_REGS[ep->num]->DIEPDMA, ep->dma_addr); } - + /* EP enable, IN data in FIFO */ depctl.b.cnak = 1; depctl.b.epena = 1; USB_OTG_WRITE_REG32(&in_regs->DIEPCTL, depctl.d32); - - - + + + if (pdev->cfg.dma_enable == 0) { /* Enable the Tx FIFO Empty Interrupt for this EP */ @@ -1820,7 +1820,7 @@ USB_OTG_STS USB_OTG_EP0StartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) depctl.b.cnak = 1; depctl.b.epena = 1; USB_OTG_WRITE_REG32 (&(pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL), depctl.d32); - + } return status; } @@ -1836,7 +1836,7 @@ USB_OTG_STS USB_OTG_EPSetStall(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) USB_OTG_STS status = USB_OTG_OK; USB_OTG_DEPCTL_TypeDef depctl; __IO uint32_t *depctl_addr; - + depctl.d32 = 0; if (ep->is_in == 1) { @@ -1872,9 +1872,9 @@ USB_OTG_STS USB_OTG_EPClearStall(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep) USB_OTG_STS status = USB_OTG_OK; USB_OTG_DEPCTL_TypeDef depctl; __IO uint32_t *depctl_addr; - + depctl.d32 = 0; - + if (ep->is_in == 1) { depctl_addr = &(pdev->regs.INEP_REGS[ep->num]->DIEPCTL); @@ -1950,14 +1950,14 @@ void USB_OTG_EP0_OutStart(USB_OTG_CORE_HANDLE *pdev) doeptsize0.b.pktcnt = 1; doeptsize0.b.xfersize = 8 * 3; USB_OTG_WRITE_REG32( &pdev->regs.OUTEP_REGS[0]->DOEPTSIZ, doeptsize0.d32 ); - + if (pdev->cfg.dma_enable == 1) { USB_OTG_DEPCTL_TypeDef doepctl; doepctl.d32 = 0; - USB_OTG_WRITE_REG32( &pdev->regs.OUTEP_REGS[0]->DOEPDMA, + USB_OTG_WRITE_REG32( &pdev->regs.OUTEP_REGS[0]->DOEPDMA, (uint32_t)&pdev->dev.setup_packet); - + /* EP enable */ doepctl.d32 = USB_OTG_READ_REG32(&pdev->regs.OUTEP_REGS[0]->DOEPCTL); doepctl.b.epena = 1; @@ -1973,12 +1973,12 @@ void USB_OTG_EP0_OutStart(USB_OTG_CORE_HANDLE *pdev) */ void USB_OTG_ActiveRemoteWakeup(USB_OTG_CORE_HANDLE *pdev) { - + USB_OTG_DCTL_TypeDef dctl; USB_OTG_DSTS_TypeDef dsts; - USB_OTG_PCGCCTL_TypeDef power; - - if (pdev->dev.DevRemoteWakeup) + USB_OTG_PCGCCTL_TypeDef power; + + if (pdev->dev.DevRemoteWakeup) { dsts.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DSTS); if(dsts.b.suspsts == 1) @@ -1990,7 +1990,7 @@ void USB_OTG_ActiveRemoteWakeup(USB_OTG_CORE_HANDLE *pdev) power.b.gatehclk = 0; power.b.stoppclk = 0; USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, power.d32); - } + } /* active Remote wakeup signaling */ dctl.d32 = 0; dctl.b.rmtwkupsig = 1; @@ -2011,12 +2011,12 @@ void USB_OTG_UngateClock(USB_OTG_CORE_HANDLE *pdev) { if(pdev->cfg.low_power) { - + USB_OTG_DSTS_TypeDef dsts; - USB_OTG_PCGCCTL_TypeDef power; - + USB_OTG_PCGCCTL_TypeDef power; + dsts.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DSTS); - + if(dsts.b.suspsts == 1) { /* un-gate USB Core clock */ @@ -2024,7 +2024,7 @@ void USB_OTG_UngateClock(USB_OTG_CORE_HANDLE *pdev) power.b.gatehclk = 0; power.b.stoppclk = 0; USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, power.d32); - + } } } @@ -2037,9 +2037,9 @@ void USB_OTG_UngateClock(USB_OTG_CORE_HANDLE *pdev) void USB_OTG_StopDevice(USB_OTG_CORE_HANDLE *pdev) { uint32_t i; - + pdev->dev.device_status = 1; - + for (i = 0; i < pdev->cfg.dev_endpoints ; i++) { USB_OTG_WRITE_REG32( &pdev->regs.INEP_REGS[i]->DIEPINT, 0xFF); @@ -2049,11 +2049,11 @@ void USB_OTG_StopDevice(USB_OTG_CORE_HANDLE *pdev) USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DIEPMSK, 0 ); USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DOEPMSK, 0 ); USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DAINTMSK, 0 ); - USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DAINT, 0xFFFFFFFF ); - + USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DAINT, 0xFFFFFFFF ); + /* Flush the FIFO */ USB_OTG_FlushRxFifo(pdev); - USB_OTG_FlushTxFifo(pdev , 0x10 ); + USB_OTG_FlushTxFifo(pdev , 0x10 ); } /** @@ -2067,34 +2067,34 @@ uint32_t USB_OTG_GetEPStatus(USB_OTG_CORE_HANDLE *pdev ,USB_OTG_EP *ep) { USB_OTG_DEPCTL_TypeDef depctl; __IO uint32_t *depctl_addr; - uint32_t Status = 0; - + uint32_t Status = 0; + depctl.d32 = 0; if (ep->is_in == 1) { depctl_addr = &(pdev->regs.INEP_REGS[ep->num]->DIEPCTL); depctl.d32 = USB_OTG_READ_REG32(depctl_addr); - - if (depctl.b.stall == 1) + + if (depctl.b.stall == 1) Status = USB_OTG_EP_TX_STALL; else if (depctl.b.naksts == 1) Status = USB_OTG_EP_TX_NAK; - else - Status = USB_OTG_EP_TX_VALID; + else + Status = USB_OTG_EP_TX_VALID; } else { depctl_addr = &(pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL); depctl.d32 = USB_OTG_READ_REG32(depctl_addr); - if (depctl.b.stall == 1) + if (depctl.b.stall == 1) Status = USB_OTG_EP_RX_STALL; else if (depctl.b.naksts == 1) Status = USB_OTG_EP_RX_NAK; - else - Status = USB_OTG_EP_RX_VALID; - } - + else + Status = USB_OTG_EP_RX_VALID; + } + /* Return the current status */ return Status; } @@ -2110,7 +2110,7 @@ void USB_OTG_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep , uint32_t { USB_OTG_DEPCTL_TypeDef depctl; __IO uint32_t *depctl_addr; - + depctl.d32 = 0; /* Process for IN endpoint */ @@ -2118,8 +2118,8 @@ void USB_OTG_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep , uint32_t { depctl_addr = &(pdev->regs.INEP_REGS[ep->num]->DIEPCTL); depctl.d32 = USB_OTG_READ_REG32(depctl_addr); - - if (Status == USB_OTG_EP_TX_STALL) + + if (Status == USB_OTG_EP_TX_STALL) { USB_OTG_EPSetStall(pdev, ep); return; } @@ -2128,23 +2128,23 @@ void USB_OTG_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep , uint32_t else if (Status == USB_OTG_EP_TX_VALID) { if (depctl.b.stall == 1) - { + { ep->even_odd_frame = 0; USB_OTG_EPClearStall(pdev, ep); return; - } + } depctl.b.cnak = 1; - depctl.b.usbactep = 1; + depctl.b.usbactep = 1; depctl.b.epena = 1; } else if (Status == USB_OTG_EP_TX_DIS) depctl.b.usbactep = 0; - } + } else /* Process for OUT endpoint */ { depctl_addr = &(pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL); - depctl.d32 = USB_OTG_READ_REG32(depctl_addr); - + depctl.d32 = USB_OTG_READ_REG32(depctl_addr); + if (Status == USB_OTG_EP_RX_STALL) { depctl.b.stall = 1; } @@ -2153,32 +2153,32 @@ void USB_OTG_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep , uint32_t else if (Status == USB_OTG_EP_RX_VALID) { if (depctl.b.stall == 1) - { + { ep->even_odd_frame = 0; USB_OTG_EPClearStall(pdev, ep); return; - } + } depctl.b.cnak = 1; - depctl.b.usbactep = 1; + depctl.b.usbactep = 1; depctl.b.epena = 1; } else if (Status == USB_OTG_EP_RX_DIS) { - depctl.b.usbactep = 0; + depctl.b.usbactep = 0; } } - USB_OTG_WRITE_REG32(depctl_addr, depctl.d32); + USB_OTG_WRITE_REG32(depctl_addr, depctl.d32); } #endif /** * @} -*/ +*/ /** * @} -*/ +*/ /** * @} diff --git a/codec2-dev/stm32/usb_lib/otg/usb_core.h b/codec2-dev/stm32/usb_lib/otg/usb_core.h index 82a09e15..acd1f1cc 100644 --- a/codec2-dev/stm32/usb_lib/otg/usb_core.h +++ b/codec2-dev/stm32/usb_lib/otg/usb_core.h @@ -32,16 +32,16 @@ /** @addtogroup USB_OTG_DRIVER * @{ */ - + /** @defgroup USB_CORE * @brief usb otg driver core layer * @{ - */ + */ /** @defgroup USB_CORE_Exported_Defines * @{ - */ + */ #define USB_OTG_EP0_IDLE 0 #define USB_OTG_EP0_SETUP 1 @@ -55,19 +55,19 @@ #define USB_OTG_EP_TX_STALL 0x0010 #define USB_OTG_EP_TX_NAK 0x0020 #define USB_OTG_EP_TX_VALID 0x0030 - + #define USB_OTG_EP_RX_DIS 0x0000 #define USB_OTG_EP_RX_STALL 0x1000 #define USB_OTG_EP_RX_NAK 0x2000 #define USB_OTG_EP_RX_VALID 0x3000 /** * @} - */ + */ #define MAX_DATA_LENGTH 0xFF /** @defgroup USB_CORE_Exported_Types * @{ - */ + */ typedef enum { @@ -82,9 +82,9 @@ typedef enum { HC_NAK, HC_NYET, HC_STALL, - HC_XACTERR, - HC_BBLERR, - HC_DATATGLERR, + HC_XACTERR, + HC_BBLERR, + HC_DATATGLERR, }HC_STATUS; typedef enum { @@ -101,9 +101,9 @@ typedef enum { CTRL_HALTED, CTRL_NAK, CTRL_STALL, - CTRL_XACTERR, - CTRL_BBLERR, - CTRL_DATATGLERR, + CTRL_XACTERR, + CTRL_BBLERR, + CTRL_DATATGLERR, CTRL_FAIL }CTRL_STATUS; @@ -114,16 +114,16 @@ typedef struct USB_OTG_hc uint8_t ep_num; uint8_t ep_is_in; uint8_t speed; - uint8_t do_ping; + uint8_t do_ping; uint8_t ep_type; uint16_t max_packet; uint8_t data_pid; uint8_t *xfer_buff; uint32_t xfer_len; - uint32_t xfer_count; + uint32_t xfer_count; uint8_t toggle_in; uint8_t toggle_out; - uint32_t dma_addr; + uint32_t dma_addr; } USB_OTG_HC , *PUSB_OTG_HC; @@ -131,7 +131,7 @@ typedef struct USB_OTG_ep { uint8_t num; uint8_t is_in; - uint8_t is_stall; + uint8_t is_stall; uint8_t type; uint8_t data_pid_start; uint8_t even_odd_frame; @@ -139,13 +139,13 @@ typedef struct USB_OTG_ep uint32_t maxpacket; /* transaction level variables*/ uint8_t *xfer_buff; - uint32_t dma_addr; + uint32_t dma_addr; uint32_t xfer_len; uint32_t xfer_count; - /* Transfer level variables*/ + /* Transfer level variables*/ uint32_t rem_data_len; uint32_t total_data_len; - uint32_t ctl_data_len; + uint32_t ctl_data_len; } @@ -165,36 +165,36 @@ typedef struct USB_OTG_core_cfg uint8_t Sof_output; uint8_t low_power; uint8_t coreID; - + } USB_OTG_CORE_CFGS, *PUSB_OTG_CORE_CFGS; typedef struct usb_setup_req { - - uint8_t bmRequest; - uint8_t bRequest; - uint16_t wValue; - uint16_t wIndex; - uint16_t wLength; + + uint8_t bmRequest; + uint8_t bRequest; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; } USB_SETUP_REQ; typedef struct _Device_TypeDef { - uint8_t *(*GetDeviceDescriptor)( uint8_t speed , uint16_t *length); - uint8_t *(*GetLangIDStrDescriptor)( uint8_t speed , uint16_t *length); - uint8_t *(*GetManufacturerStrDescriptor)( uint8_t speed , uint16_t *length); - uint8_t *(*GetProductStrDescriptor)( uint8_t speed , uint16_t *length); - uint8_t *(*GetSerialStrDescriptor)( uint8_t speed , uint16_t *length); - uint8_t *(*GetConfigurationStrDescriptor)( uint8_t speed , uint16_t *length); - uint8_t *(*GetInterfaceStrDescriptor)( uint8_t speed , uint16_t *length); + uint8_t *(*GetDeviceDescriptor)( uint8_t speed , uint16_t *length); + uint8_t *(*GetLangIDStrDescriptor)( uint8_t speed , uint16_t *length); + uint8_t *(*GetManufacturerStrDescriptor)( uint8_t speed , uint16_t *length); + uint8_t *(*GetProductStrDescriptor)( uint8_t speed , uint16_t *length); + uint8_t *(*GetSerialStrDescriptor)( uint8_t speed , uint16_t *length); + uint8_t *(*GetConfigurationStrDescriptor)( uint8_t speed , uint16_t *length); + uint8_t *(*GetInterfaceStrDescriptor)( uint8_t speed , uint16_t *length); } USBD_DEVICE, *pUSBD_DEVICE; typedef struct USB_OTG_hPort { void (*Disconnect) (void *phost); - void (*Connect) (void *phost); + void (*Connect) (void *phost); uint8_t ConnStatus; uint8_t DisconnStatus; uint8_t ConnHandled; @@ -206,40 +206,40 @@ typedef struct _Device_cb uint8_t (*Init) (void *pdev , uint8_t cfgidx); uint8_t (*DeInit) (void *pdev , uint8_t cfgidx); /* Control Endpoints*/ - uint8_t (*Setup) (void *pdev , USB_SETUP_REQ *req); - uint8_t (*EP0_TxSent) (void *pdev ); - uint8_t (*EP0_RxReady) (void *pdev ); + uint8_t (*Setup) (void *pdev , USB_SETUP_REQ *req); + uint8_t (*EP0_TxSent) (void *pdev ); + uint8_t (*EP0_RxReady) (void *pdev ); /* Class Specific Endpoints*/ - uint8_t (*DataIn) (void *pdev , uint8_t epnum); - uint8_t (*DataOut) (void *pdev , uint8_t epnum); - uint8_t (*SOF) (void *pdev); - uint8_t (*IsoINIncomplete) (void *pdev); - uint8_t (*IsoOUTIncomplete) (void *pdev); - - uint8_t *(*GetConfigDescriptor)( uint8_t speed , uint16_t *length); -#ifdef USB_OTG_HS_CORE - uint8_t *(*GetOtherConfigDescriptor)( uint8_t speed , uint16_t *length); + uint8_t (*DataIn) (void *pdev , uint8_t epnum); + uint8_t (*DataOut) (void *pdev , uint8_t epnum); + uint8_t (*SOF) (void *pdev); + uint8_t (*IsoINIncomplete) (void *pdev); + uint8_t (*IsoOUTIncomplete) (void *pdev); + + uint8_t *(*GetConfigDescriptor)( uint8_t speed , uint16_t *length); +#ifdef USB_OTG_HS_CORE + uint8_t *(*GetOtherConfigDescriptor)( uint8_t speed , uint16_t *length); +#endif + +#ifdef USB_SUPPORT_USER_STRING_DESC + uint8_t *(*GetUsrStrDescriptor)( uint8_t speed ,uint8_t index, uint16_t *length); #endif -#ifdef USB_SUPPORT_USER_STRING_DESC - uint8_t *(*GetUsrStrDescriptor)( uint8_t speed ,uint8_t index, uint16_t *length); -#endif - } USBD_Class_cb_TypeDef; typedef struct _USBD_USR_PROP { - void (*Init)(void); - void (*DeviceReset)(uint8_t speed); + void (*Init)(void); + void (*DeviceReset)(uint8_t speed); void (*DeviceConfigured)(void); void (*DeviceSuspended)(void); - void (*DeviceResumed)(void); - - void (*DeviceConnected)(void); - void (*DeviceDisconnected)(void); - + void (*DeviceResumed)(void); + + void (*DeviceConnected)(void); + void (*DeviceDisconnected)(void); + } USBD_Usr_cb_TypeDef; @@ -255,7 +255,7 @@ typedef struct _DCD uint8_t setup_packet [8*3]; USBD_Class_cb_TypeDef *class_cb; USBD_Usr_cb_TypeDef *usr_cb; - USBD_DEVICE *usr_device; + USBD_DEVICE *usr_device; uint8_t *pConfig_descriptor; } DCD_DEV , *DCD_PDEV; @@ -263,15 +263,15 @@ DCD_DEV , *DCD_PDEV; typedef struct _HCD { - uint8_t Rx_Buffer [MAX_DATA_LENGTH]; + uint8_t Rx_Buffer [MAX_DATA_LENGTH]; __IO uint32_t ConnSts; __IO uint32_t ErrCnt[USB_OTG_MAX_TX_FIFOS]; __IO uint32_t XferCnt[USB_OTG_MAX_TX_FIFOS]; - __IO HC_STATUS HC_Status[USB_OTG_MAX_TX_FIFOS]; + __IO HC_STATUS HC_Status[USB_OTG_MAX_TX_FIFOS]; __IO URB_STATE URB_State[USB_OTG_MAX_TX_FIFOS]; USB_OTG_HC hc [USB_OTG_MAX_TX_FIFOS]; uint16_t channel [USB_OTG_MAX_TX_FIFOS]; - USB_OTG_hPort_TypeDef *port_cb; + USB_OTG_hPort_TypeDef *port_cb; } HCD_DEV , *USB_OTG_USBH_PDEV; @@ -279,8 +279,8 @@ HCD_DEV , *USB_OTG_USBH_PDEV; typedef struct _OTG { uint8_t OTG_State; - uint8_t OTG_PrevState; - uint8_t OTG_Mode; + uint8_t OTG_PrevState; + uint8_t OTG_Mode; } OTG_DEV , *USB_OTG_USBO_PDEV; @@ -302,31 +302,31 @@ USB_OTG_CORE_HANDLE , *PUSB_OTG_CORE_HANDLE; /** * @} - */ + */ /** @defgroup USB_CORE_Exported_Macros * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_CORE_Exported_Variables * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_CORE_Exported_FunctionsPrototype * @{ - */ + */ USB_OTG_STS USB_OTG_CoreInit (USB_OTG_CORE_HANDLE *pdev); -USB_OTG_STS USB_OTG_SelectCore (USB_OTG_CORE_HANDLE *pdev, +USB_OTG_STS USB_OTG_SelectCore (USB_OTG_CORE_HANDLE *pdev, USB_OTG_CORE_ID_TypeDef coreID); USB_OTG_STS USB_OTG_EnableGlobalInt (USB_OTG_CORE_HANDLE *pdev); USB_OTG_STS USB_OTG_DisableGlobalInt(USB_OTG_CORE_HANDLE *pdev); @@ -392,17 +392,17 @@ uint32_t USB_OTG_GetEPStatus(USB_OTG_CORE_HANDLE *pdev ,USB_OTG_EP *ep); #endif /** * @} - */ + */ #endif /* __USB_CORE_H__ */ /** * @} - */ + */ /** * @} - */ + */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_lib/otg/usb_dcd.c b/codec2-dev/stm32/usb_lib/otg/usb_dcd.c index a74522f5..bab0146e 100644 --- a/codec2-dev/stm32/usb_lib/otg/usb_dcd.c +++ b/codec2-dev/stm32/usb_lib/otg/usb_dcd.c @@ -6,7 +6,7 @@ * @date 22-July-2011 * @brief Peripheral Device Interface Layer ****************************************************************************** - * @attention + * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE @@ -30,7 +30,7 @@ * @{ */ -/** @defgroup USB_DCD +/** @defgroup USB_DCD * @brief This file is the interface between EFSL ans Host mass-storage class * @{ */ @@ -38,63 +38,63 @@ /** @defgroup USB_DCD_Private_Defines * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_DCD_Private_TypesDefinitions * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_DCD_Private_Macros * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_DCD_Private_Variables * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_DCD_Private_FunctionPrototypes * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_DCD_Private_Functions * @{ -*/ +*/ -void DCD_Init(USB_OTG_CORE_HANDLE *pdev , +void DCD_Init(USB_OTG_CORE_HANDLE *pdev , USB_OTG_CORE_ID_TypeDef coreID) { uint32_t i; USB_OTG_EP *ep; - + USB_OTG_SelectCore (pdev , coreID); - + pdev->dev.device_status = USB_OTG_DEFAULT; pdev->dev.device_address = 0; - + /* Init ep structure */ for (i = 0; i < pdev->cfg.dev_endpoints ; i++) { @@ -109,7 +109,7 @@ void DCD_Init(USB_OTG_CORE_HANDLE *pdev , ep->xfer_buff = 0; ep->xfer_len = 0; } - + for (i = 0; i < pdev->cfg.dev_endpoints; i++) { ep = &pdev->dev.out_ep[i]; @@ -123,20 +123,20 @@ void DCD_Init(USB_OTG_CORE_HANDLE *pdev , ep->xfer_buff = 0; ep->xfer_len = 0; } - + USB_OTG_DisableGlobalInt(pdev); - + /*Init the Core (common init.) */ USB_OTG_CoreInit(pdev); /* Force Device Mode*/ USB_OTG_SetCurrentMode(pdev, DEVICE_MODE); - + /* Init Device */ USB_OTG_CoreInitDev(pdev); - - + + /* Enable USB Global interrupt */ USB_OTG_EnableGlobalInt(pdev); } @@ -148,13 +148,13 @@ void DCD_Init(USB_OTG_CORE_HANDLE *pdev , * @param epdesc : Endpoint Descriptor * @retval : status */ -uint32_t DCD_EP_Open(USB_OTG_CORE_HANDLE *pdev , +uint32_t DCD_EP_Open(USB_OTG_CORE_HANDLE *pdev , uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type) { USB_OTG_EP *ep; - + if ((ep_addr & 0x80) == 0x80) { ep = &pdev->dev.in_ep[ep_addr & 0x7F]; @@ -164,7 +164,7 @@ uint32_t DCD_EP_Open(USB_OTG_CORE_HANDLE *pdev , ep = &pdev->dev.out_ep[ep_addr & 0x7F]; } ep->num = ep_addr & 0x7F; - + ep->is_in = (0x80 & ep_addr) != 0; ep->maxpacket = ep_mps; ep->type = ep_type; @@ -190,7 +190,7 @@ uint32_t DCD_EP_Open(USB_OTG_CORE_HANDLE *pdev , uint32_t DCD_EP_Close(USB_OTG_CORE_HANDLE *pdev , uint8_t ep_addr) { USB_OTG_EP *ep; - + if ((ep_addr&0x80) == 0x80) { ep = &pdev->dev.in_ep[ep_addr & 0x7F]; @@ -216,25 +216,25 @@ uint32_t DCD_EP_Close(USB_OTG_CORE_HANDLE *pdev , uint8_t ep_addr) */ uint32_t DCD_EP_PrepareRx( USB_OTG_CORE_HANDLE *pdev, uint8_t ep_addr, - uint8_t *pbuf, + uint8_t *pbuf, uint16_t buf_len) { USB_OTG_EP *ep; - + ep = &pdev->dev.out_ep[ep_addr & 0x7F]; - + /*setup and start the Xfer */ - ep->xfer_buff = pbuf; + ep->xfer_buff = pbuf; ep->xfer_len = buf_len; ep->xfer_count = 0; ep->is_in = 0; ep->num = ep_addr & 0x7F; - + if (pdev->cfg.dma_enable == 1) { - ep->dma_addr = (uint32_t)pbuf; + ep->dma_addr = (uint32_t)pbuf; } - + if ( ep->num == 0 ) { USB_OTG_EP0StartXfer(pdev , ep); @@ -260,17 +260,17 @@ uint32_t DCD_EP_Tx ( USB_OTG_CORE_HANDLE *pdev, uint32_t buf_len) { USB_OTG_EP *ep; - + ep = &pdev->dev.in_ep[ep_addr & 0x7F]; - + /* Setup and start the Transfer */ ep->is_in = 1; - ep->num = ep_addr & 0x7F; + ep->num = ep_addr & 0x7F; ep->xfer_buff = pbuf; - ep->dma_addr = (uint32_t)pbuf; + ep->dma_addr = (uint32_t)pbuf; ep->xfer_count = 0; ep->xfer_len = buf_len; - + if ( ep->num == 0 ) { USB_OTG_EP0StartXfer(pdev , ep); @@ -304,7 +304,7 @@ uint32_t DCD_EP_Stall (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum) ep->is_stall = 1; ep->num = epnum & 0x7F; ep->is_in = ((epnum & 0x80) == 0x80); - + USB_OTG_EPSetStall(pdev , ep); return (0); } @@ -321,17 +321,17 @@ uint32_t DCD_EP_ClrStall (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum) USB_OTG_EP *ep; if ((0x80 & epnum) == 0x80) { - ep = &pdev->dev.in_ep[epnum & 0x7F]; + ep = &pdev->dev.in_ep[epnum & 0x7F]; } else { ep = &pdev->dev.out_ep[epnum]; } - - ep->is_stall = 0; + + ep->is_stall = 0; ep->num = epnum & 0x7F; ep->is_in = ((epnum & 0x80) == 0x80); - + USB_OTG_EPClearStall(pdev , ep); return (0); } @@ -419,17 +419,17 @@ void DCD_DevDisconnect (USB_OTG_CORE_HANDLE *pdev) uint32_t DCD_GetEPStatus(USB_OTG_CORE_HANDLE *pdev ,uint8_t epnum) { USB_OTG_EP *ep; - uint32_t Status = 0; - + uint32_t Status = 0; + if ((0x80 & epnum) == 0x80) { - ep = &pdev->dev.in_ep[epnum & 0x7F]; + ep = &pdev->dev.in_ep[epnum & 0x7F]; } else { ep = &pdev->dev.out_ep[epnum]; } - + Status = USB_OTG_GetEPStatus(pdev ,ep); /* Return the current status */ @@ -446,26 +446,26 @@ uint32_t DCD_GetEPStatus(USB_OTG_CORE_HANDLE *pdev ,uint8_t epnum) void DCD_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum , uint32_t Status) { USB_OTG_EP *ep; - + if ((0x80 & epnum) == 0x80) { - ep = &pdev->dev.in_ep[epnum & 0x7F]; + ep = &pdev->dev.in_ep[epnum & 0x7F]; } else { ep = &pdev->dev.out_ep[epnum]; } - + USB_OTG_SetEPStatus(pdev ,ep , Status); } /** * @} -*/ +*/ /** * @} -*/ +*/ /** * @} diff --git a/codec2-dev/stm32/usb_lib/otg/usb_dcd.h b/codec2-dev/stm32/usb_lib/otg/usb_dcd.h index 6bfd8993..9a23dc6f 100644 --- a/codec2-dev/stm32/usb_lib/otg/usb_dcd.h +++ b/codec2-dev/stm32/usb_lib/otg/usb_dcd.h @@ -6,7 +6,7 @@ * @date 22-July-2011 * @brief Peripheral Driver Header file ****************************************************************************** - * @attention + * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE @@ -32,14 +32,14 @@ */ /** @defgroup USB_DCD -* @brief This file is the +* @brief This file is the * @{ -*/ +*/ /** @defgroup USB_DCD_Exported_Defines * @{ -*/ +*/ #define USB_OTG_EP_CONTROL 0 #define USB_OTG_EP_ISOC 1 #define USB_OTG_EP_BULK 2 @@ -54,12 +54,12 @@ /** * @} -*/ +*/ /** @defgroup USB_DCD_Exported_Types * @{ -*/ +*/ /******************************************************************************** Data structure type ********************************************************************************/ @@ -76,26 +76,26 @@ EP_DESCRIPTOR , *PEP_DESCRIPTOR; /** * @} -*/ +*/ /** @defgroup USB_DCD_Exported_Macros * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_DCD_Exported_Variables * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_DCD_Exported_FunctionsPrototype * @{ -*/ +*/ /******************************************************************************** EXPORTED FUNCTION FROM THE USB-OTG LAYER ********************************************************************************/ @@ -106,7 +106,7 @@ void DCD_DevConnect (USB_OTG_CORE_HANDLE *pdev); void DCD_DevDisconnect (USB_OTG_CORE_HANDLE *pdev); void DCD_EP_SetAddress (USB_OTG_CORE_HANDLE *pdev, uint8_t address); -uint32_t DCD_EP_Open(USB_OTG_CORE_HANDLE *pdev , +uint32_t DCD_EP_Open(USB_OTG_CORE_HANDLE *pdev , uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type); @@ -116,10 +116,10 @@ uint32_t DCD_EP_Close (USB_OTG_CORE_HANDLE *pdev, uint32_t DCD_EP_PrepareRx ( USB_OTG_CORE_HANDLE *pdev, - uint8_t ep_addr, - uint8_t *pbuf, + uint8_t ep_addr, + uint8_t *pbuf, uint16_t buf_len); - + uint32_t DCD_EP_Tx (USB_OTG_CORE_HANDLE *pdev, uint8_t ep_addr, uint8_t *pbuf, @@ -135,13 +135,13 @@ uint32_t DCD_Handle_ISR(USB_OTG_CORE_HANDLE *pdev); uint32_t DCD_GetEPStatus(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum); -void DCD_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , - uint8_t epnum , +void DCD_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , + uint8_t epnum , uint32_t Status); /** * @} -*/ +*/ #endif //__DCD_H__ @@ -149,10 +149,10 @@ void DCD_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , /** * @} -*/ +*/ /** * @} -*/ +*/ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_lib/otg/usb_dcd_int.c b/codec2-dev/stm32/usb_lib/otg/usb_dcd_int.c index 5b47017a..59627830 100644 --- a/codec2-dev/stm32/usb_lib/otg/usb_dcd_int.c +++ b/codec2-dev/stm32/usb_lib/otg/usb_dcd_int.c @@ -6,7 +6,7 @@ * @date 22-July-2011 * @brief Peripheral Device interrupt subroutines ****************************************************************************** - * @attention + * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE @@ -27,7 +27,7 @@ * @{ */ -/** @defgroup USB_DCD_INT +/** @defgroup USB_DCD_INT * @brief This file contains the interrupt subroutines for the Device mode. * @{ */ @@ -35,40 +35,40 @@ /** @defgroup USB_DCD_INT_Private_Defines * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_DCD_INT_Private_TypesDefinitions * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_DCD_INT_Private_Macros * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_DCD_INT_Private_Variables * @{ -*/ +*/ /** * @} -*/ +*/ /** @defgroup USB_DCD_INT_Private_FunctionPrototypes * @{ -*/ +*/ /* static functions */ static uint32_t DCD_ReadDevInEP (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum); @@ -94,15 +94,15 @@ static uint32_t DCD_OTG_ISR(USB_OTG_CORE_HANDLE *pdev); /** * @} -*/ +*/ /** @defgroup USB_DCD_INT_Private_Functions * @{ -*/ +*/ -#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED +#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED /** * @brief USBD_OTG_EP1OUT_ISR_Handler * handles all USB Interrupts @@ -111,13 +111,13 @@ static uint32_t DCD_OTG_ISR(USB_OTG_CORE_HANDLE *pdev); */ uint32_t USBD_OTG_EP1OUT_ISR_Handler (USB_OTG_CORE_HANDLE *pdev) { - + USB_OTG_DOEPINTn_TypeDef doepint; - USB_OTG_DEPXFRSIZ_TypeDef deptsiz; - + USB_OTG_DEPXFRSIZ_TypeDef deptsiz; + doepint.d32 = USB_OTG_READ_REG32(&pdev->regs.OUTEP_REGS[1]->DOEPINT); doepint.d32&= USB_OTG_READ_REG32(&pdev->regs.DREGS->DOUTEP1MSK); - + /* Transfer complete */ if ( doepint.b.xfercompl ) { @@ -129,13 +129,13 @@ uint32_t USBD_OTG_EP1OUT_ISR_Handler (USB_OTG_CORE_HANDLE *pdev) /*ToDo : handle more than one single MPS size packet */ pdev->dev.out_ep[1].xfer_count = pdev->dev.out_ep[1].maxpacket - \ deptsiz.b.xfersize; - } + } /* Inform upper layer: data ready */ /* RX COMPLETE */ USBD_DCD_INT_fops->DataOutStage(pdev , 1); - + } - + /* Endpoint disable */ if ( doepint.b.epdisabled ) { @@ -146,7 +146,7 @@ uint32_t USBD_OTG_EP1OUT_ISR_Handler (USB_OTG_CORE_HANDLE *pdev) if ( doepint.b.ahberr ) { CLEAR_OUT_EP_INTR(1, ahberr); - } + } return 1; } @@ -158,15 +158,15 @@ uint32_t USBD_OTG_EP1OUT_ISR_Handler (USB_OTG_CORE_HANDLE *pdev) */ uint32_t USBD_OTG_EP1IN_ISR_Handler (USB_OTG_CORE_HANDLE *pdev) { - + USB_OTG_DIEPINTn_TypeDef diepint; uint32_t fifoemptymsk, msk, emp; - + msk = USB_OTG_READ_REG32(&pdev->regs.DREGS->DINEP1MSK); emp = USB_OTG_READ_REG32(&pdev->regs.DREGS->DIEPEMPMSK); msk |= ((emp >> 1 ) & 0x1) << 7; - diepint.d32 = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[1]->DIEPINT) & msk; - + diepint.d32 = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[1]->DIEPINT) & msk; + if ( diepint.b.xfercompl ) { fifoemptymsk = 0x1 << 1; @@ -182,7 +182,7 @@ uint32_t USBD_OTG_EP1IN_ISR_Handler (USB_OTG_CORE_HANDLE *pdev) if ( diepint.b.epdisabled ) { CLEAR_IN_EP_INTR(1, epdisabled); - } + } if ( diepint.b.timeout ) { CLEAR_IN_EP_INTR(1, timeout); @@ -218,7 +218,7 @@ uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev) { USB_OTG_GINTSTS_TypeDef gintr_status; uint32_t retval = 0; - + if (USB_OTG_IsDeviceMode(pdev)) /* ensure that we are in device mode */ { gintr_status.d32 = USB_OTG_ReadCoreItr(pdev); @@ -226,32 +226,32 @@ uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev) { return 0; } - + if (gintr_status.b.outepintr) { retval |= DCD_HandleOutEP_ISR(pdev); - } - + } + if (gintr_status.b.inepint) { retval |= DCD_HandleInEP_ISR(pdev); } - + if (gintr_status.b.modemismatch) { USB_OTG_GINTSTS_TypeDef gintsts; - + /* Clear interrupt */ gintsts.d32 = 0; gintsts.b.modemismatch = 1; USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, gintsts.d32); } - + if (gintr_status.b.wkupintr) { retval |= DCD_HandleResume_ISR(pdev); } - + if (gintr_status.b.usbsuspend) { retval |= DCD_HandleUSBSuspend_ISR(pdev); @@ -259,25 +259,25 @@ uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev) if (gintr_status.b.sofintr) { retval |= DCD_HandleSof_ISR(pdev); - + } - + if (gintr_status.b.rxstsqlvl) { retval |= DCD_HandleRxStatusQueueLevel_ISR(pdev); - + } - + if (gintr_status.b.usbreset) { retval |= DCD_HandleUsbReset_ISR(pdev); - + } if (gintr_status.b.enumdone) { retval |= DCD_HandleEnumDone_ISR(pdev); } - + if (gintr_status.b.incomplisoin) { retval |= DCD_IsoINIncomplete_ISR(pdev); @@ -286,7 +286,7 @@ uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev) if (gintr_status.b.incomplisoout) { retval |= DCD_IsoOUTIncomplete_ISR(pdev); - } + } #ifdef VBUS_SENSING_ENABLED if (gintr_status.b.sessreqintr) { @@ -296,8 +296,8 @@ uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev) if (gintr_status.b.otgintr) { retval |= DCD_OTG_ISR(pdev); - } -#endif + } +#endif } return retval; } @@ -311,13 +311,13 @@ uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev) */ static uint32_t DCD_SessionRequest_ISR(USB_OTG_CORE_HANDLE *pdev) { - USB_OTG_GINTSTS_TypeDef gintsts; + USB_OTG_GINTSTS_TypeDef gintsts; USBD_DCD_INT_fops->DevConnected (pdev); /* Clear interrupt */ gintsts.d32 = 0; gintsts.b.sessreqintr = 1; - USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GINTSTS, gintsts.d32); + USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GINTSTS, gintsts.d32); return 1; } @@ -334,13 +334,13 @@ static uint32_t DCD_OTG_ISR(USB_OTG_CORE_HANDLE *pdev) USB_OTG_GOTGINT_TypeDef gotgint; gotgint.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GOTGINT); - + if (gotgint.b.sesenddet) { USBD_DCD_INT_fops->DevDisconnected (pdev); } /* Clear OTG interrupt */ - USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GOTGINT, gotgint.d32); + USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GOTGINT, gotgint.d32); return 1; } #endif @@ -356,7 +356,7 @@ static uint32_t DCD_HandleResume_ISR(USB_OTG_CORE_HANDLE *pdev) USB_OTG_GINTSTS_TypeDef gintsts; USB_OTG_DCTL_TypeDef devctl; USB_OTG_PCGCCTL_TypeDef power; - + if(pdev->cfg.low_power) { /* un-gate USB Core clock */ @@ -365,15 +365,15 @@ static uint32_t DCD_HandleResume_ISR(USB_OTG_CORE_HANDLE *pdev) power.b.stoppclk = 0; USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, power.d32); } - + /* Clear the Remote Wake-up Signaling */ devctl.d32 = 0; devctl.b.rmtwkupsig = 1; USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DCTL, devctl.d32, 0); - + /* Inform upper layer by the Resume Event */ USBD_DCD_INT_fops->Resume (pdev); - + /* Clear interrupt */ gintsts.d32 = 0; gintsts.b.wkupintr = 1; @@ -392,26 +392,26 @@ static uint32_t DCD_HandleUSBSuspend_ISR(USB_OTG_CORE_HANDLE *pdev) USB_OTG_GINTSTS_TypeDef gintsts; USB_OTG_PCGCCTL_TypeDef power; USB_OTG_DSTS_TypeDef dsts; - - USBD_DCD_INT_fops->Suspend (pdev); - + + USBD_DCD_INT_fops->Suspend (pdev); + dsts.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DSTS); - + /* Clear interrupt */ gintsts.d32 = 0; gintsts.b.usbsuspend = 1; USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, gintsts.d32); - + if((pdev->cfg.low_power) && (dsts.b.suspsts == 1)) { /* switch-off the clocks */ power.d32 = 0; power.b.stoppclk = 1; - USB_OTG_MODIFY_REG32(pdev->regs.PCGCCTL, 0, power.d32); - + USB_OTG_MODIFY_REG32(pdev->regs.PCGCCTL, 0, power.d32); + power.b.gatehclk = 1; USB_OTG_MODIFY_REG32(pdev->regs.PCGCCTL, 0, power.d32); - + /* Request to enter Sleep mode after exit from current ISR */ SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk); } @@ -427,13 +427,13 @@ static uint32_t DCD_HandleUSBSuspend_ISR(USB_OTG_CORE_HANDLE *pdev) static uint32_t DCD_HandleInEP_ISR(USB_OTG_CORE_HANDLE *pdev) { USB_OTG_DIEPINTn_TypeDef diepint; - + uint32_t ep_intr; uint32_t epnum = 0; uint32_t fifoemptymsk; diepint.d32 = 0; ep_intr = USB_OTG_ReadDevAllInEPItr(pdev); - + while ( ep_intr ) { if (ep_intr&0x1) /* In ITR */ @@ -446,7 +446,7 @@ static uint32_t DCD_HandleInEP_ISR(USB_OTG_CORE_HANDLE *pdev) CLEAR_IN_EP_INTR(epnum, xfercompl); /* TX COMPLETE */ USBD_DCD_INT_fops->DataInStage(pdev , epnum); - + if (pdev->cfg.dma_enable == 1) { if((epnum == 0) && (pdev->dev.device_state == USB_OTG_EP0_STATUS_IN)) @@ -454,7 +454,7 @@ static uint32_t DCD_HandleInEP_ISR(USB_OTG_CORE_HANDLE *pdev) /* prepare to rx more setup packets */ USB_OTG_EP0_OutStart(pdev); } - } + } } if ( diepint.b.ahberr ) { @@ -479,19 +479,19 @@ static uint32_t DCD_HandleInEP_ISR(USB_OTG_CORE_HANDLE *pdev) if ( diepint.b.epdisabled ) { CLEAR_IN_EP_INTR(epnum, epdisabled); - } + } if (diepint.b.emptyintr) { - + DCD_WriteEmptyTxFifo(pdev , epnum); - + CLEAR_IN_EP_INTR(epnum, emptyintr); } } epnum++; ep_intr >>= 1; } - + return 1; } @@ -507,19 +507,19 @@ static uint32_t DCD_HandleOutEP_ISR(USB_OTG_CORE_HANDLE *pdev) USB_OTG_DOEPINTn_TypeDef doepint; USB_OTG_DEPXFRSIZ_TypeDef deptsiz; uint32_t epnum = 0; - + doepint.d32 = 0; - + /* Read in the device interrupt bits */ ep_intr = USB_OTG_ReadDevAllOutEp_itr(pdev); - + while ( ep_intr ) { if (ep_intr&0x1) { - + doepint.d32 = USB_OTG_ReadDevOutEP_itr(pdev, epnum); - + /* Transfer complete */ if ( doepint.b.xfercompl ) { @@ -535,7 +535,7 @@ static uint32_t DCD_HandleOutEP_ISR(USB_OTG_CORE_HANDLE *pdev) /* Inform upper layer: data ready */ /* RX COMPLETE */ USBD_DCD_INT_fops->DataOutStage(pdev , epnum); - + if (pdev->cfg.dma_enable == 1) { if((epnum == 0) && (pdev->dev.device_state == USB_OTG_EP0_STATUS_OUT)) @@ -543,7 +543,7 @@ static uint32_t DCD_HandleOutEP_ISR(USB_OTG_CORE_HANDLE *pdev) /* prepare to rx more setup packets */ USB_OTG_EP0_OutStart(pdev); } - } + } } /* Endpoint disable */ if ( doepint.b.epdisabled ) @@ -559,7 +559,7 @@ static uint32_t DCD_HandleOutEP_ISR(USB_OTG_CORE_HANDLE *pdev) /* Setup Phase Done (control EPs) */ if ( doepint.b.setup ) { - + /* inform the upper layer that a setup packet is available */ /* SETUP COMPLETE */ USBD_DCD_INT_fops->SetupStage(pdev); @@ -581,15 +581,15 @@ static uint32_t DCD_HandleOutEP_ISR(USB_OTG_CORE_HANDLE *pdev) static uint32_t DCD_HandleSof_ISR(USB_OTG_CORE_HANDLE *pdev) { USB_OTG_GINTSTS_TypeDef GINTSTS; - - + + USBD_DCD_INT_fops->SOF(pdev); - + /* Clear interrupt */ GINTSTS.d32 = 0; GINTSTS.b.sofintr = 1; USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GINTSTS, GINTSTS.d32); - + return 1; } @@ -604,17 +604,17 @@ static uint32_t DCD_HandleRxStatusQueueLevel_ISR(USB_OTG_CORE_HANDLE *pdev) USB_OTG_GINTMSK_TypeDef int_mask; USB_OTG_DRXSTS_TypeDef status; USB_OTG_EP *ep; - + /* Disable the Rx Status Queue Level interrupt */ int_mask.d32 = 0; int_mask.b.rxstsqlvl = 1; USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, int_mask.d32, 0); - + /* Get the Status from the top of the FIFO */ status.d32 = USB_OTG_READ_REG32( &pdev->regs.GREGS->GRXSTSP ); - + ep = &pdev->dev.out_ep[status.b.epnum]; - + switch (status.b.pktsts) { case STS_GOUT_NAK: @@ -639,10 +639,10 @@ static uint32_t DCD_HandleRxStatusQueueLevel_ISR(USB_OTG_CORE_HANDLE *pdev) default: break; } - + /* Enable the Rx Status Queue Level interrupt */ USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, 0, int_mask.d32); - + return 1; } @@ -659,42 +659,42 @@ static uint32_t DCD_WriteEmptyTxFifo(USB_OTG_CORE_HANDLE *pdev, uint32_t epnum) uint32_t len = 0; uint32_t len32b; txstatus.d32 = 0; - - ep = &pdev->dev.in_ep[epnum]; - + + ep = &pdev->dev.in_ep[epnum]; + len = ep->xfer_len - ep->xfer_count; - + if (len > ep->maxpacket) { len = ep->maxpacket; } - + len32b = (len + 3) / 4; txstatus.d32 = USB_OTG_READ_REG32( &pdev->regs.INEP_REGS[epnum]->DTXFSTS); - - - + + + while (txstatus.b.txfspcavail > len32b && ep->xfer_count < ep->xfer_len && ep->xfer_len != 0) { /* Write the FIFO */ len = ep->xfer_len - ep->xfer_count; - + if (len > ep->maxpacket) { len = ep->maxpacket; } len32b = (len + 3) / 4; - + USB_OTG_WritePacket (pdev , ep->xfer_buff, epnum, len); - + ep->xfer_buff += len; ep->xfer_count += len; - + txstatus.d32 = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[epnum]->DTXFSTS); } - + return 1; } @@ -713,38 +713,38 @@ static uint32_t DCD_HandleUsbReset_ISR(USB_OTG_CORE_HANDLE *pdev) USB_OTG_DCTL_TypeDef dctl; USB_OTG_GINTSTS_TypeDef gintsts; uint32_t i; - + dctl.d32 = 0; daintmsk.d32 = 0; doepmsk.d32 = 0; diepmsk.d32 = 0; dcfg.d32 = 0; gintsts.d32 = 0; - + /* Clear the Remote Wake-up Signaling */ dctl.b.rmtwkupsig = 1; USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DCTL, dctl.d32, 0 ); - + /* Flush the Tx FIFO */ USB_OTG_FlushTxFifo(pdev , 0 ); - + for (i = 0; i < pdev->cfg.dev_endpoints ; i++) { USB_OTG_WRITE_REG32( &pdev->regs.INEP_REGS[i]->DIEPINT, 0xFF); USB_OTG_WRITE_REG32( &pdev->regs.OUTEP_REGS[i]->DOEPINT, 0xFF); } USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DAINT, 0xFFFFFFFF ); - + daintmsk.ep.in = 1; daintmsk.ep.out = 1; USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DAINTMSK, daintmsk.d32 ); - + doepmsk.b.setup = 1; doepmsk.b.xfercompl = 1; doepmsk.b.ahberr = 1; doepmsk.b.epdisabled = 1; USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DOEPMSK, doepmsk.d32 ); -#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED +#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DOUTEP1MSK, doepmsk.d32 ); #endif diepmsk.b.xfercompl = 1; @@ -753,23 +753,23 @@ static uint32_t DCD_HandleUsbReset_ISR(USB_OTG_CORE_HANDLE *pdev) diepmsk.b.ahberr = 1; diepmsk.b.intknepmis = 1; USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DIEPMSK, diepmsk.d32 ); -#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED +#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DINEP1MSK, diepmsk.d32 ); #endif /* Reset Device Address */ dcfg.d32 = USB_OTG_READ_REG32( &pdev->regs.DREGS->DCFG); dcfg.b.devaddr = 0; USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DCFG, dcfg.d32); - - + + /* setup EP0 to receive SETUP packets */ USB_OTG_EP0_OutStart(pdev); - + /* Clear interrupt */ gintsts.d32 = 0; gintsts.b.usbreset = 1; USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GINTSTS, gintsts.d32); - + /*Reset internal state machine */ USBD_DCD_INT_fops->Reset(pdev); return 1; @@ -785,28 +785,28 @@ static uint32_t DCD_HandleEnumDone_ISR(USB_OTG_CORE_HANDLE *pdev) { USB_OTG_GINTSTS_TypeDef gintsts; USB_OTG_GUSBCFG_TypeDef gusbcfg; - + USB_OTG_EP0Activate(pdev); - + /* Set USB turn-around time based on device speed and PHY interface. */ gusbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GUSBCFG); - + /* Full or High speed */ if ( USB_OTG_GetDeviceSpeed(pdev) == USB_SPEED_HIGH) { pdev->cfg.speed = USB_OTG_SPEED_HIGH; - pdev->cfg.mps = USB_OTG_HS_MAX_PACKET_SIZE ; + pdev->cfg.mps = USB_OTG_HS_MAX_PACKET_SIZE ; gusbcfg.b.usbtrdtim = 9; } else { pdev->cfg.speed = USB_OTG_SPEED_FULL; - pdev->cfg.mps = USB_OTG_FS_MAX_PACKET_SIZE ; + pdev->cfg.mps = USB_OTG_FS_MAX_PACKET_SIZE ; gusbcfg.b.usbtrdtim = 5; } - + USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, gusbcfg.d32); - + /* Clear interrupt */ gintsts.d32 = 0; gintsts.b.enumdone = 1; @@ -823,16 +823,16 @@ static uint32_t DCD_HandleEnumDone_ISR(USB_OTG_CORE_HANDLE *pdev) */ static uint32_t DCD_IsoINIncomplete_ISR(USB_OTG_CORE_HANDLE *pdev) { - USB_OTG_GINTSTS_TypeDef gintsts; - + USB_OTG_GINTSTS_TypeDef gintsts; + gintsts.d32 = 0; - USBD_DCD_INT_fops->IsoINIncomplete (pdev); - + USBD_DCD_INT_fops->IsoINIncomplete (pdev); + /* Clear interrupt */ gintsts.b.incomplisoin = 1; USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, gintsts.d32); - + return 1; } @@ -844,12 +844,12 @@ static uint32_t DCD_IsoINIncomplete_ISR(USB_OTG_CORE_HANDLE *pdev) */ static uint32_t DCD_IsoOUTIncomplete_ISR(USB_OTG_CORE_HANDLE *pdev) { - USB_OTG_GINTSTS_TypeDef gintsts; - + USB_OTG_GINTSTS_TypeDef gintsts; + gintsts.d32 = 0; - USBD_DCD_INT_fops->IsoOUTIncomplete (pdev); - + USBD_DCD_INT_fops->IsoOUTIncomplete (pdev); + /* Clear interrupt */ gintsts.b.incomplisoout = 1; USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, gintsts.d32); @@ -875,11 +875,11 @@ static uint32_t DCD_ReadDevInEP (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum) /** * @} -*/ +*/ /** * @} -*/ +*/ /** * @} diff --git a/codec2-dev/stm32/usb_lib/otg/usb_dcd_int.h b/codec2-dev/stm32/usb_lib/otg/usb_dcd_int.h index 9df1a417..3cbebd85 100644 --- a/codec2-dev/stm32/usb_lib/otg/usb_dcd_int.h +++ b/codec2-dev/stm32/usb_lib/otg/usb_dcd_int.h @@ -6,7 +6,7 @@ * @date 22-July-2011 * @brief Peripheral Device Interface Layer ****************************************************************************** - * @attention + * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE @@ -31,16 +31,16 @@ /** @addtogroup USB_OTG_DRIVER * @{ */ - + /** @defgroup USB_DCD_INT - * @brief This file is the + * @brief This file is the * @{ - */ + */ /** @defgroup USB_DCD_INT_Exported_Defines * @{ - */ + */ typedef struct _USBD_DCD_INT { @@ -52,29 +52,29 @@ typedef struct _USBD_DCD_INT uint8_t (* Suspend) (USB_OTG_CORE_HANDLE *pdev); uint8_t (* Resume) (USB_OTG_CORE_HANDLE *pdev); uint8_t (* IsoINIncomplete) (USB_OTG_CORE_HANDLE *pdev); - uint8_t (* IsoOUTIncomplete) (USB_OTG_CORE_HANDLE *pdev); - + uint8_t (* IsoOUTIncomplete) (USB_OTG_CORE_HANDLE *pdev); + uint8_t (* DevConnected) (USB_OTG_CORE_HANDLE *pdev); - uint8_t (* DevDisconnected) (USB_OTG_CORE_HANDLE *pdev); - + uint8_t (* DevDisconnected) (USB_OTG_CORE_HANDLE *pdev); + }USBD_DCD_INT_cb_TypeDef; extern USBD_DCD_INT_cb_TypeDef *USBD_DCD_INT_fops; /** * @} - */ + */ /** @defgroup USB_DCD_INT_Exported_Types * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_DCD_INT_Exported_Macros * @{ - */ + */ #define CLEAR_IN_EP_INTR(epnum,intr) \ diepint.d32=0; \ @@ -88,34 +88,34 @@ extern USBD_DCD_INT_cb_TypeDef *USBD_DCD_INT_fops; /** * @} - */ + */ /** @defgroup USB_DCD_INT_Exported_Variables * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_DCD_INT_Exported_FunctionsPrototype * @{ - */ + */ uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev); /** * @} - */ + */ #endif // USB_DCD_INT_H__ /** * @} - */ + */ /** * @} - */ + */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_lib/otg/usb_defines.h b/codec2-dev/stm32/usb_lib/otg/usb_defines.h index b119c258..70f99520 100644 --- a/codec2-dev/stm32/usb_lib/otg/usb_defines.h +++ b/codec2-dev/stm32/usb_lib/otg/usb_defines.h @@ -29,19 +29,19 @@ /** @addtogroup USB_OTG_DRIVER * @{ */ - + /** @defgroup USB_DEFINES - * @brief This file is the + * @brief This file is the * @{ - */ + */ /** @defgroup USB_DEFINES_Exported_Defines * @{ - */ + */ /** * @} - */ + */ /** @defgroup _CORE_DEFINES_ @@ -178,7 +178,7 @@ /** @defgroup USB_DEFINES_Exported_Types * @{ - */ + */ typedef enum { @@ -187,29 +187,29 @@ typedef enum }USB_OTG_CORE_ID_TypeDef; /** * @} - */ + */ /** @defgroup USB_DEFINES_Exported_Macros * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_DEFINES_Exported_Variables * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_DEFINES_Exported_FunctionsPrototype * @{ - */ + */ /** * @} - */ + */ /** @defgroup Internal_Macro's @@ -235,10 +235,10 @@ enum USB_OTG_SPEED { /** * @} - */ + */ /** * @} - */ + */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/usb_lib/otg/usb_regs.h b/codec2-dev/stm32/usb_lib/otg/usb_regs.h index cd71ddfa..57e478cc 100644 --- a/codec2-dev/stm32/usb_lib/otg/usb_regs.h +++ b/codec2-dev/stm32/usb_lib/otg/usb_regs.h @@ -30,16 +30,16 @@ /** @addtogroup USB_OTG_DRIVER * @{ */ - + /** @defgroup USB_REGS - * @brief This file is the + * @brief This file is the * @{ - */ + */ /** @defgroup USB_REGS_Exported_Defines * @{ - */ + */ #define USB_OTG_HS_BASE_ADDR 0x40040000 #define USB_OTG_FS_BASE_ADDR 0x50000000 @@ -65,11 +65,11 @@ #define USB_OTG_MAX_EP0_SIZE 64 /** * @} - */ + */ /** @defgroup USB_REGS_Exported_Types * @{ - */ + */ /** @defgroup __USB_OTG_Core_register * @{ @@ -122,11 +122,11 @@ typedef struct _USB_OTG_DREGS // 800h __IO uint32_t DTHRCTL; /* dev thr 830h*/ __IO uint32_t DIEPEMPMSK; /* dev empty msk 834h*/ __IO uint32_t DEACHINT; /* dedicated EP interrupt 838h*/ - __IO uint32_t DEACHMSK; /* dedicated EP msk 83Ch*/ + __IO uint32_t DEACHMSK; /* dedicated EP msk 83Ch*/ uint32_t Reserved40; /* dedicated EP mask 840h*/ __IO uint32_t DINEP1MSK; /* dedicated EP mask 844h*/ uint32_t Reserved44[15]; /* Reserved 844-87Ch*/ - __IO uint32_t DOUTEP1MSK; /* dedicated EP msk 884h*/ + __IO uint32_t DOUTEP1MSK; /* dedicated EP msk 884h*/ } USB_OTG_DREGS; /** @@ -227,7 +227,7 @@ typedef struct USB_OTG_core_regs //000h __IO uint32_t *PCGCCTL; } USB_OTG_CORE_REGS , *PUSB_OTG_CORE_REGS; -typedef union _USB_OTG_OTGCTL_TypeDef +typedef union _USB_OTG_OTGCTL_TypeDef { uint32_t d32; struct @@ -263,7 +263,7 @@ uint32_t Reserved21_31 : } b; } USB_OTG_OTGCTL_TypeDef ; -typedef union _USB_OTG_GOTGINT_TypeDef +typedef union _USB_OTG_GOTGINT_TypeDef { uint32_t d32; struct @@ -291,7 +291,7 @@ uint32_t Reserved31_20 : } b; } USB_OTG_GOTGINT_TypeDef ; -typedef union _USB_OTG_GAHBCFG_TypeDef +typedef union _USB_OTG_GAHBCFG_TypeDef { uint32_t d32; struct @@ -313,7 +313,7 @@ uint32_t Reserved9_31 : } b; } USB_OTG_GAHBCFG_TypeDef ; -typedef union _USB_OTG_GUSBCFG_TypeDef +typedef union _USB_OTG_GUSBCFG_TypeDef { uint32_t d32; struct @@ -365,7 +365,7 @@ uint32_t corrupt_tx : } b; } USB_OTG_GUSBCFG_TypeDef ; -typedef union _USB_OTG_GRSTCTL_TypeDef +typedef union _USB_OTG_GRSTCTL_TypeDef { uint32_t d32; struct @@ -393,7 +393,7 @@ uint32_t ahbidle : } b; } USB_OTG_GRSTCTL_TypeDef ; -typedef union _USB_OTG_GINTMSK_TypeDef +typedef union _USB_OTG_GINTMSK_TypeDef { uint32_t d32; struct @@ -463,7 +463,7 @@ uint32_t wkupintr : } b; } USB_OTG_GINTMSK_TypeDef ; -typedef union _USB_OTG_GINTSTS_TypeDef +typedef union _USB_OTG_GINTSTS_TypeDef { uint32_t d32; struct @@ -533,7 +533,7 @@ uint32_t wkupintr : } b; } USB_OTG_GINTSTS_TypeDef ; -typedef union _USB_OTG_DRXSTS_TypeDef +typedef union _USB_OTG_DRXSTS_TypeDef { uint32_t d32; struct @@ -553,7 +553,7 @@ uint32_t Reserved : } b; } USB_OTG_DRXSTS_TypeDef ; -typedef union _USB_OTG_GRXSTS_TypeDef +typedef union _USB_OTG_GRXSTS_TypeDef { uint32_t d32; struct @@ -571,7 +571,7 @@ uint32_t Reserved : } b; } USB_OTG_GRXFSTS_TypeDef ; -typedef union _USB_OTG_FSIZ_TypeDef +typedef union _USB_OTG_FSIZ_TypeDef { uint32_t d32; struct @@ -583,7 +583,7 @@ uint32_t depth : } b; } USB_OTG_FSIZ_TypeDef ; -typedef union _USB_OTG_HNPTXSTS_TypeDef +typedef union _USB_OTG_HNPTXSTS_TypeDef { uint32_t d32; struct @@ -599,13 +599,13 @@ uint32_t nptxqtop_timer : uint32_t nptxqtop : 2; uint32_t chnum : - 2; + 2; uint32_t Reserved : 1; } b; } USB_OTG_HNPTXSTS_TypeDef ; -typedef union _USB_OTG_DTXFSTSn_TypeDef +typedef union _USB_OTG_DTXFSTSn_TypeDef { uint32_t d32; struct @@ -617,7 +617,7 @@ uint32_t Reserved : } b; } USB_OTG_DTXFSTSn_TypeDef ; -typedef union _USB_OTG_GI2CCTL_TypeDef +typedef union _USB_OTG_GI2CCTL_TypeDef { uint32_t d32; struct @@ -647,7 +647,7 @@ uint32_t bsydne : } b; } USB_OTG_GI2CCTL_TypeDef ; -typedef union _USB_OTG_GCCFG_TypeDef +typedef union _USB_OTG_GCCFG_TypeDef { uint32_t d32; struct @@ -672,7 +672,7 @@ uint32_t Reserved_out : b; } USB_OTG_GCCFG_TypeDef ; -typedef union _USB_OTG_DCFG_TypeDef +typedef union _USB_OTG_DCFG_TypeDef { uint32_t d32; struct @@ -694,7 +694,7 @@ uint32_t epmscnt : } b; } USB_OTG_DCFG_TypeDef ; -typedef union _USB_OTG_DCTL_TypeDef +typedef union _USB_OTG_DCTL_TypeDef { uint32_t d32; struct @@ -722,7 +722,7 @@ uint32_t Reserved : } b; } USB_OTG_DCTL_TypeDef ; -typedef union _USB_OTG_DSTS_TypeDef +typedef union _USB_OTG_DSTS_TypeDef { uint32_t d32; struct @@ -742,7 +742,7 @@ uint32_t Reserved22_31 : } b; } USB_OTG_DSTS_TypeDef ; -typedef union _USB_OTG_DIEPINTn_TypeDef +typedef union _USB_OTG_DIEPINTn_TypeDef { uint32_t d32; struct @@ -771,7 +771,7 @@ uint32_t Reserved08_31 : b; } USB_OTG_DIEPINTn_TypeDef ; typedef union _USB_OTG_DIEPINTn_TypeDef USB_OTG_DIEPMSK_TypeDef ; -typedef union _USB_OTG_DOEPINTn_TypeDef +typedef union _USB_OTG_DOEPINTn_TypeDef { uint32_t d32; struct @@ -791,7 +791,7 @@ uint32_t Reserved04_31 : } USB_OTG_DOEPINTn_TypeDef ; typedef union _USB_OTG_DOEPINTn_TypeDef USB_OTG_DOEPMSK_TypeDef ; -typedef union _USB_OTG_DAINT_TypeDef +typedef union _USB_OTG_DAINT_TypeDef { uint32_t d32; struct @@ -804,7 +804,7 @@ uint32_t out : ep; } USB_OTG_DAINT_TypeDef ; -typedef union _USB_OTG_DTHRCTL_TypeDef +typedef union _USB_OTG_DTHRCTL_TypeDef { uint32_t d32; struct @@ -826,7 +826,7 @@ uint32_t Reserved26_31 : } b; } USB_OTG_DTHRCTL_TypeDef ; -typedef union _USB_OTG_DEPCTL_TypeDef +typedef union _USB_OTG_DEPCTL_TypeDef { uint32_t d32; struct @@ -864,7 +864,7 @@ uint32_t epena : } b; } USB_OTG_DEPCTL_TypeDef ; -typedef union _USB_OTG_DEPXFRSIZ_TypeDef +typedef union _USB_OTG_DEPXFRSIZ_TypeDef { uint32_t d32; struct @@ -880,7 +880,7 @@ uint32_t Reserved : } b; } USB_OTG_DEPXFRSIZ_TypeDef ; -typedef union _USB_OTG_DEP0XFRSIZ_TypeDef +typedef union _USB_OTG_DEP0XFRSIZ_TypeDef { uint32_t d32; struct @@ -899,7 +899,7 @@ uint32_t supcnt : } b; } USB_OTG_DEP0XFRSIZ_TypeDef ; -typedef union _USB_OTG_HCFG_TypeDef +typedef union _USB_OTG_HCFG_TypeDef { uint32_t d32; struct @@ -911,7 +911,7 @@ uint32_t fslssupp : } b; } USB_OTG_HCFG_TypeDef ; -typedef union _USB_OTG_HFRMINTRVL_TypeDef +typedef union _USB_OTG_HFRMINTRVL_TypeDef { uint32_t d32; struct @@ -924,7 +924,7 @@ uint32_t Reserved : b; } USB_OTG_HFRMINTRVL_TypeDef ; -typedef union _USB_OTG_HFNUM_TypeDef +typedef union _USB_OTG_HFNUM_TypeDef { uint32_t d32; struct @@ -936,7 +936,7 @@ uint32_t frrem : } b; } USB_OTG_HFNUM_TypeDef ; -typedef union _USB_OTG_HPTXSTS_TypeDef +typedef union _USB_OTG_HPTXSTS_TypeDef { uint32_t d32; struct @@ -958,7 +958,7 @@ uint32_t ptxqtop_odd : } b; } USB_OTG_HPTXSTS_TypeDef ; -typedef union _USB_OTG_HPRT0_TypeDef +typedef union _USB_OTG_HPRT0_TypeDef { uint32_t d32; struct @@ -996,7 +996,7 @@ uint32_t Reserved19_31 : } b; } USB_OTG_HPRT0_TypeDef ; -typedef union _USB_OTG_HAINT_TypeDef +typedef union _USB_OTG_HAINT_TypeDef { uint32_t d32; struct @@ -1008,7 +1008,7 @@ uint32_t Reserved : } b; } USB_OTG_HAINT_TypeDef ; -typedef union _USB_OTG_HAINTMSK_TypeDef +typedef union _USB_OTG_HAINTMSK_TypeDef { uint32_t d32; struct @@ -1020,7 +1020,7 @@ uint32_t Reserved : } b; } USB_OTG_HAINTMSK_TypeDef ; -typedef union _USB_OTG_HCCHAR_TypeDef +typedef union _USB_OTG_HCCHAR_TypeDef { uint32_t d32; struct @@ -1050,7 +1050,7 @@ uint32_t chen : } b; } USB_OTG_HCCHAR_TypeDef ; -typedef union _USB_OTG_HCSPLT_TypeDef +typedef union _USB_OTG_HCSPLT_TypeDef { uint32_t d32; struct @@ -1070,7 +1070,7 @@ uint32_t spltena : } b; } USB_OTG_HCSPLT_TypeDef ; -typedef union _USB_OTG_HCINTn_TypeDef +typedef union _USB_OTG_HCINTn_TypeDef { uint32_t d32; struct @@ -1102,7 +1102,7 @@ uint32_t Reserved : } b; } USB_OTG_HCINTn_TypeDef ; -typedef union _USB_OTG_HCTSIZn_TypeDef +typedef union _USB_OTG_HCTSIZn_TypeDef { uint32_t d32; struct @@ -1118,7 +1118,7 @@ uint32_t dopng : } b; } USB_OTG_HCTSIZn_TypeDef ; -typedef union _USB_OTG_HCGINTMSK_TypeDef +typedef union _USB_OTG_HCGINTMSK_TypeDef { uint32_t d32; struct @@ -1150,7 +1150,7 @@ uint32_t Reserved : } b; } USB_OTG_HCGINTMSK_TypeDef ; -typedef union _USB_OTG_PCGCCTL_TypeDef +typedef union _USB_OTG_PCGCCTL_TypeDef { uint32_t d32; struct @@ -1167,29 +1167,29 @@ uint32_t Reserved : /** * @} - */ + */ /** @defgroup USB_REGS_Exported_Macros * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_REGS_Exported_Variables * @{ - */ + */ /** * @} - */ + */ /** @defgroup USB_REGS_Exported_FunctionsPrototype * @{ - */ + */ /** * @} - */ + */ #endif //__USB_OTG_REGS_H__ @@ -1197,10 +1197,10 @@ uint32_t Reserved : /** * @} - */ + */ /** * @} - */ + */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/unittest/create_interleaver.c b/codec2-dev/unittest/create_interleaver.c index 39ff99c0..7fb1ae58 100644 --- a/codec2-dev/unittest/create_interleaver.c +++ b/codec2-dev/unittest/create_interleaver.c @@ -14,7 +14,7 @@ int main(int argc, char * argv[]) { int m,i, src_bit, dest_bit; FILE *f; int *interleaver; - + if (argc != 3) { printf("usage: %s InterleaverBits InterleaverFile\n", argv[0]); exit(1); diff --git a/codec2-dev/unittest/de.c b/codec2-dev/unittest/de.c index 081bba58..97267432 100644 --- a/codec2-dev/unittest/de.c +++ b/codec2-dev/unittest/de.c @@ -1,4 +1,4 @@ -/* +/* de.c David Rowe Sep 26 2012 @@ -28,7 +28,7 @@ int main(int argc, char *argv[]) { printf("e.g de input.raw output.raw"); exit(1); } - + if (strcmp(argv[1], "-") == 0) fin = stdin; else if ( (fin = fopen(argv[1],"rb")) == NULL ) { fprintf(stderr, "Error opening input speech file: %s: %s.\n", diff --git a/codec2-dev/unittest/dvdongle2.c b/codec2-dev/unittest/dvdongle2.c index 792b3fc1..0635faca 100644 --- a/codec2-dev/unittest/dvdongle2.c +++ b/codec2-dev/unittest/dvdongle2.c @@ -1,17 +1,17 @@ /*---------------------------------------------------------------------------*\ - + FILE........: dvdongle2.c - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: 28 Oct 2010 - + Program to encode and decode raw speech samples using the AMBE codec implemented on a DV Dongle. The DV Dongle connects to a USB port and provides encoding and decoding of compressed audio using the DVSI AMBE2000 full duplex vocoder DSP chip. - - Refs: + + Refs: [1] http://www.dvdongle.com/ [2] http://www.moetronix.com/files/dvdongletechref100.pdf @@ -49,13 +49,13 @@ along with this program; if not, see . */ -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #define MAX_STR 1024 @@ -64,9 +64,9 @@ /* message parsing state machine states */ -#define MSGSTATE_HDR1 0 +#define MSGSTATE_HDR1 0 #define MSGSTATE_HDR2 1 -#define MSGSTATE_DATA 2 +#define MSGSTATE_DATA 2 #define LENGTH_MASK 0x1FFF /* mask for message length */ #define TYPE_MASK 0xE0 /* mask for upper byte of header */ @@ -181,7 +181,7 @@ void parse_message(int msg_type, int msg_len, char msg_data[]) { short buf[N]; COMPRESSED *c_out; - //printf("msg_type: 0x%02x msg_len: %d\n", msg_type, msg_len); + //printf("msg_type: 0x%02x msg_len: %d\n", msg_type, msg_len); /* echo compressed speech frames back to target */ @@ -203,22 +203,22 @@ void parse_message(int msg_type, int msg_len, char msg_data[]) { printf("cd[5] 0x%04x\n", c_out->channel_data[5] & 0xffff); printf("cd[6] 0x%04x\n", c_out->channel_data[6] & 0xffff); printf("uc_msg %d\n", uc_msg); -#endif +#endif printf("bit errors %d\n", c_out->unused[2]); - memcpy(&c_in.channel_data, - &c_out->channel_data, + memcpy(&c_in.channel_data, + &c_out->channel_data, sizeof(c_in.channel_data)); - + write_dongle(fd, data_item_1, sizeof(data_item_1)); write_dongle(fd, (char*)&c_in, sizeof(c_in)); - + c_msg++; } /* write speech buffers to disk */ if (msg_type == TYPE_UC) { - + if (fout != NULL) { fwrite(msg_data, sizeof(char), msg_len-2, fout); printf("msg_len %d\n", msg_len); @@ -228,10 +228,10 @@ void parse_message(int msg_type, int msg_len, char msg_data[]) { fread(buf, sizeof(short), N, fin); else memset(buf, 0, sizeof(buf)); - + write_dongle(fd, data_item_0, sizeof(data_item_0)); write_dongle(fd, (char*)buf, sizeof(buf)); - + uc_msg++; } } @@ -260,7 +260,7 @@ int main(int argc, char **argv) { } else { fcntl(fd, F_SETFL, 0); } - + initport(fd); fin = NULL; @@ -305,7 +305,7 @@ int main(int argc, char **argv) { c_in.rate[4] = 0x6860; #endif - c_in.unused[0] = 0x0; + c_in.unused[0] = 0x0; c_in.unused[1] = 0x0; c_in.unused[2] = 0x0; c_in.dtmf = 0x00ff; @@ -322,7 +322,7 @@ int main(int argc, char **argv) { c_msg = uc_msg = 0; for(i=0; i<100000; i++) { - /* + /* We can only reliably read one byte at a time. Until I realised this there was "much wailing and gnashing of teeth". Trying to read() n bytes read() returns n but may @@ -375,9 +375,9 @@ int main(int argc, char **argv) { write_dongle(fd, run_state_stop, sizeof(run_state_stop)); close(fd); - if (fin != NULL) + if (fin != NULL) fclose(fin); - if (fout != NULL) + if (fout != NULL) fclose(fout); fclose(f); diff --git a/codec2-dev/unittest/extract.c b/codec2-dev/unittest/extract.c index 2812d55e..5fbb3ca2 100644 --- a/codec2-dev/unittest/extract.c +++ b/codec2-dev/unittest/extract.c @@ -111,9 +111,9 @@ void scan_line(FILE *fp, float f[], int n) char s[MAX_STR]; char *ps,*pe; int i; - + memset(s, 0, MAX_STR); - ps = pe = fgets(s,MAX_STR,fp); + ps = pe = fgets(s,MAX_STR,fp); if (ps == NULL) return; for(i=0; i quantized @@ -14,7 +14,7 @@ */ /* - Copyright (C) 2012 Jean-Marc Valin + Copyright (C) 2012 Jean-Marc Valin All rights reserved. @@ -80,7 +80,7 @@ void compute_weights2(const float *x, const float *xp, float *w, int ndim) //w[0] = 30; //w[1] = 1; - + /* Square the weights because it's applied on the squared error */ w[0] *= w[0]; w[1] *= w[1]; @@ -92,7 +92,7 @@ int find_nearest_weighted(const float *codebook, int nb_entries, float *x, const int i, j; float min_dist = 1e15; int nearest = 0; - + for (i=0;i 2.0) gt2++; diff --git a/codec2-dev/unittest/speexnoisesup.c b/codec2-dev/unittest/speexnoisesup.c index 8706fd67..f76d5e2e 100644 --- a/codec2-dev/unittest/speexnoisesup.c +++ b/codec2-dev/unittest/speexnoisesup.c @@ -1,9 +1,9 @@ /*----------------------------------------------------------------------------*\ FILE....: speexnoisesup.c - AUTHOR..: David Rowe + AUTHOR..: David Rowe CREATED.: Sun 22 June 2014 - + File I/O based test program for Speex pre-processor, used for initial testing of Speech noise supression. @@ -34,19 +34,19 @@ int main(int argc, char *argv[]) { fprintf(stderr, "Error opening %s\n", argv[1]); exit(1); } - + if (strcmp(argv[2], "-") == 0) fout = stdout; else if ((fout = fopen(argv[2],"wb")) == NULL) { fprintf(stderr, "Error opening %s\n", argv[2]); exit(1); } - + st = speex_preprocess_state_init(N, FS); while(fread(buf, sizeof(short), N, fin) == N) { speex_preprocess_run(st, buf); fwrite(buf, sizeof(short), N, fout); - if (fin == stdin) fflush(stdin); + if (fin == stdin) fflush(stdin); if (fout == stdout) fflush(stdout); } diff --git a/codec2-dev/unittest/t16_8.c b/codec2-dev/unittest/t16_8.c index 34d1f137..f6d83ba8 100644 --- a/codec2-dev/unittest/t16_8.c +++ b/codec2-dev/unittest/t16_8.c @@ -1,4 +1,4 @@ -/* +/* t16_8.c David Rowe May 10 2012 @@ -48,7 +48,7 @@ int main() { assert(f16 != NULL); f8 = fopen("out8.raw", "wb"); assert(f8 != NULL); - + /* clear filter memories */ for(i=0; iSn, c2->w, LPC_ORD); encode_lsps_scalar(lsp_indexes, lsps, LPC_ORD); @@ -137,7 +137,7 @@ int test2() pack((unsigned char*)bits, (unsigned *)&nbit, energy_index, E_BITS); pack((unsigned char*)bits, (unsigned *)&nbit, voiced1, 1); pack((unsigned char*)bits, (unsigned *)&nbit, voiced2, 1); - + nbit = 0; Wo_index = unpack((unsigned char*)bits, (unsigned *)&nbit, WO_BITS); for(i=0; ich_symb_log = (COMP *)malloc(sizeof(COMP)*NSYMROWPILOT*FRAMESL*coh->ch_symb_log_col_sz); coh->rx_timing_log = (float*)malloc(sizeof(float)*NSYMROWPILOT*FRAMESL); - + /* init stuff */ log_r = log_data_r = noise_r = log_bits = ff_log_r = f_est_samples = 0; - phase_ch.real = 1.0; phase_ch.imag = 0.0; + phase_ch.real = 1.0; phase_ch.imag = 0.0; foff = FOFF; - + /* each carrier has power = 2, total power 2Nc, total symbol rate NcRs, noise BW B=Fs Es/No = (C/Rs)/(N/B), N = var = 2NcFs/NcRs(Es/No) = 2Fs/Rs(Es/No) */ @@ -146,9 +146,9 @@ int main(int argc, char *argv[]) bits_to_qpsk_symbols(tx_symb, (int*)tx_bits, COHPSK_BITS_PER_FRAME); for(r=0; rtx_filter_memory, + for(c=0; ctx_filter_memory, fdmdv->phase_tx, fdmdv->freq, &fdmdv->fbb_phase_tx, fdmdv->fbb_rect); } cohpsk_clip(tx_fdm_frame); @@ -182,10 +182,10 @@ int main(int argc, char *argv[]) memcpy(&tx_bits_log[COHPSK_BITS_PER_FRAME*f], tx_bits, sizeof(int)*COHPSK_BITS_PER_FRAME); memcpy(&tx_fdm_frame_log[COHPSK_M*NSYMROWPILOT*f], tx_fdm_frame, sizeof(COMP)*COHPSK_M*NSYMROWPILOT); memcpy(&ch_fdm_frame_log[COHPSK_M*NSYMROWPILOT*f], ch_fdm_frame, sizeof(COMP)*COHPSK_M*NSYMROWPILOT); - + for(r=0; rsync == 1) { for(r=0; rct_symb_ff_buf[r][c]; + ct_symb_ff_log[ff_log_r][c] = coh->ct_symb_ff_buf[r][c]; } } for(r=0; ramp_[r][c]; - rx_phi_log[log_data_r][c] = coh->phi_[r][c]; - rx_symb_log[log_data_r][c] = coh->rx_symb[r][c]; + rx_amp_log[log_data_r][c] = coh->amp_[r][c]; + rx_phi_log[log_data_r][c] = coh->phi_[r][c]; + rx_symb_log[log_data_r][c] = coh->rx_symb[r][c]; } } memcpy(&rx_bits_log[COHPSK_BITS_PER_FRAME*log_bits], rx_bits, sizeof(int)*COHPSK_BITS_PER_FRAME); @@ -251,7 +251,7 @@ int main(int argc, char *argv[]) printf("\n"); /*---------------------------------------------------------*\ - Dump logs to Octave file for evaluation + Dump logs to Octave file for evaluation by tcohpsk.m Octave script \*---------------------------------------------------------*/ @@ -259,22 +259,22 @@ int main(int argc, char *argv[]) assert(fout != NULL); fprintf(fout, "# Created by tcohpsk.c\n"); octave_save_int(fout, "tx_bits_log_c", tx_bits_log, 1, COHPSK_BITS_PER_FRAME*FRAMES); - octave_save_complex(fout, "tx_symb_log_c", (COMP*)tx_symb_log, NSYMROWPILOT*FRAMES, COHPSK_NC*ND, COHPSK_NC*ND); - octave_save_complex(fout, "tx_fdm_frame_log_c", (COMP*)tx_fdm_frame_log, 1, COHPSK_M*NSYMROWPILOT*FRAMES, COHPSK_M*NSYMROWPILOT*FRAMES); - octave_save_complex(fout, "ch_fdm_frame_log_c", (COMP*)ch_fdm_frame_log_out, 1, nout-1, nout-1); - //octave_save_complex(fout, "rx_fdm_frame_bb_log_c", (COMP*)rx_fdm_frame_bb_log, 1, M*NSYMROWPILOT*FRAMES, M*NSYMROWPILOT*FRAMES); - octave_save_complex(fout, "rx_baseband_log_c", (COMP*)coh->rx_baseband_log, COHPSK_NC*ND, coh->rx_baseband_log_col_index, coh->rx_baseband_log_col_sz); - octave_save_complex(fout, "rx_filt_log_c", (COMP*)coh->rx_filt_log, COHPSK_NC*ND, coh->rx_filt_log_col_index, coh->rx_filt_log_col_sz); - octave_save_complex(fout, "ch_symb_log_c", (COMP*)coh->ch_symb_log, coh->ch_symb_log_r, COHPSK_NC*ND, COHPSK_NC*ND); - octave_save_float(fout, "rx_timing_log_c", (float*)coh->rx_timing_log, 1, coh->rx_timing_log_index, coh->rx_timing_log_index); - octave_save_complex(fout, "ct_symb_ff_log_c", (COMP*)ct_symb_ff_log, NSYMROWPILOT*FRAMES, COHPSK_NC*ND, COHPSK_NC*ND); - octave_save_float(fout, "rx_amp_log_c", (float*)rx_amp_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); - octave_save_float(fout, "rx_phi_log_c", (float*)rx_phi_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); - octave_save_complex(fout, "rx_symb_log_c", (COMP*)rx_symb_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); + octave_save_complex(fout, "tx_symb_log_c", (COMP*)tx_symb_log, NSYMROWPILOT*FRAMES, COHPSK_NC*ND, COHPSK_NC*ND); + octave_save_complex(fout, "tx_fdm_frame_log_c", (COMP*)tx_fdm_frame_log, 1, COHPSK_M*NSYMROWPILOT*FRAMES, COHPSK_M*NSYMROWPILOT*FRAMES); + octave_save_complex(fout, "ch_fdm_frame_log_c", (COMP*)ch_fdm_frame_log_out, 1, nout-1, nout-1); + //octave_save_complex(fout, "rx_fdm_frame_bb_log_c", (COMP*)rx_fdm_frame_bb_log, 1, M*NSYMROWPILOT*FRAMES, M*NSYMROWPILOT*FRAMES); + octave_save_complex(fout, "rx_baseband_log_c", (COMP*)coh->rx_baseband_log, COHPSK_NC*ND, coh->rx_baseband_log_col_index, coh->rx_baseband_log_col_sz); + octave_save_complex(fout, "rx_filt_log_c", (COMP*)coh->rx_filt_log, COHPSK_NC*ND, coh->rx_filt_log_col_index, coh->rx_filt_log_col_sz); + octave_save_complex(fout, "ch_symb_log_c", (COMP*)coh->ch_symb_log, coh->ch_symb_log_r, COHPSK_NC*ND, COHPSK_NC*ND); + octave_save_float(fout, "rx_timing_log_c", (float*)coh->rx_timing_log, 1, coh->rx_timing_log_index, coh->rx_timing_log_index); + octave_save_complex(fout, "ct_symb_ff_log_c", (COMP*)ct_symb_ff_log, NSYMROWPILOT*FRAMES, COHPSK_NC*ND, COHPSK_NC*ND); + octave_save_float(fout, "rx_amp_log_c", (float*)rx_amp_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); + octave_save_float(fout, "rx_phi_log_c", (float*)rx_phi_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); + octave_save_complex(fout, "rx_symb_log_c", (COMP*)rx_symb_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); octave_save_int(fout, "rx_bits_log_c", rx_bits_log, 1, COHPSK_BITS_PER_FRAME*log_bits); - octave_save_float(fout, "f_est_log_c", &f_est_log[1], 1, f_est_samples-1, f_est_samples-1); - octave_save_float(fout, "sig_rms_log_c", sig_rms_log, 1, f_est_samples, f_est_samples-1); - octave_save_float(fout, "noise_rms_log_c", noise_rms_log, 1, f_est_samples, f_est_samples); + octave_save_float(fout, "f_est_log_c", &f_est_log[1], 1, f_est_samples-1, f_est_samples-1); + octave_save_float(fout, "sig_rms_log_c", sig_rms_log, 1, f_est_samples, f_est_samples-1); + octave_save_float(fout, "noise_rms_log_c", noise_rms_log, 1, f_est_samples, f_est_samples); #ifdef XX #endif fclose(fout); diff --git a/codec2-dev/unittest/tcontphase.c b/codec2-dev/unittest/tcontphase.c index 6761bac8..1ae507e7 100644 --- a/codec2-dev/unittest/tcontphase.c +++ b/codec2-dev/unittest/tcontphase.c @@ -1,13 +1,13 @@ /*---------------------------------------------------------------------------*\ - - FILE........: tcontphase.c - AUTHOR......: David Rowe - DATE CREATED: 11/9/09 - + + FILE........: tcontphase.c + AUTHOR......: David Rowe + DATE CREATED: 11/9/09 + Test program for developing continuous phase track synthesis algorithm. However while developing this it was discovered that synthesis_mixed() worked just as well. - + \*---------------------------------------------------------------------------*/ /* @@ -58,13 +58,13 @@ float ak[] = { /*---------------------------------------------------------------------------*\ - - switch_present() - - Searches the command line arguments for a "switch". If the switch is - found, returns the command line argument where it ws found, else returns - NULL. - + + switch_present() + + Searches the command line arguments for a "switch". If the switch is + found, returns the command line argument where it ws found, else returns + NULL. + \*---------------------------------------------------------------------------*/ int switch_present(sw,argc,argv) @@ -93,12 +93,12 @@ char *argv[]; { FILE *fout; short buf[N]; - int i,j; + int i,j; int dump; float phi_prev[MAX_AMP]; float Wo_prev, ex_phase, G; //float ak[P+1]; - COMP H[MAX_AMP]; + COMP H[MAX_AMP]; float f0; if (argc < 3) { @@ -116,7 +116,7 @@ char *argv[]; f0 = atof(argv[2]); dump = switch_present("--dump",argc,argv); - if (dump) + if (dump) dump_on(argv[dump+1]); init_decoder(); @@ -124,11 +124,11 @@ char *argv[]; for(i=0; i noise_end) { noise_r = 0; - //fprintf(stderr, " [%d] noise wrap\n", f); + //fprintf(stderr, " [%d] noise wrap\n", f); } - + } /* buffer so we can let demod Fs offset code do it's thing */ - + memcpy(&ch_buf[ch_buf_n], ch_fdm, sizeof(COMP)*COHPSK_NOM_SAMPLES_PER_FRAME); ch_buf_n += COHPSK_NOM_SAMPLES_PER_FRAME; assert(ch_buf_n < CH_BUF_SZ); @@ -251,32 +251,32 @@ int main(int argc, char *argv[]) if (state) { for(r=0; ramp_[r][c]; - rx_phi_log[log_data_r*COHPSK_NC*ND+c] = coh->phi_[r][c]; - rx_symb_log[log_data_r*COHPSK_NC*ND+c] = coh->rx_symb[r][c]; + rx_amp_log[log_data_r*COHPSK_NC*ND+c] = coh->amp_[r][c]; + rx_phi_log[log_data_r*COHPSK_NC*ND+c] = coh->phi_[r][c]; + rx_symb_log[log_data_r*COHPSK_NC*ND+c] = coh->rx_symb[r][c]; } } } - + } - + printf("%4.3f %d %d\n", (float)nerrors/nbits, nbits, nerrors); - printf("tx var: %f noise var: %f rx var: %f\n", - tx_pwr/(frames*COHPSK_NOM_SAMPLES_PER_FRAME), + printf("tx var: %f noise var: %f rx var: %f\n", + tx_pwr/(frames*COHPSK_NOM_SAMPLES_PER_FRAME), noise_pwr/(frames*COHPSK_NOM_SAMPLES_PER_FRAME), - rx_pwr/(frames*COHPSK_NOM_SAMPLES_PER_FRAME) + rx_pwr/(frames*COHPSK_NOM_SAMPLES_PER_FRAME) ); if (fading_en) { free(ch_fdm_delay); fclose(ffading); } cohpsk_destroy(coh); - + fout = fopen("test_cohpsk_ch_out.txt","wt"); - octave_save_complex(fout, "ch_symb_log_c", (COMP*)coh->ch_symb_log, coh->ch_symb_log_r, COHPSK_NC*ND, COHPSK_NC*ND); - octave_save_float(fout, "rx_amp_log_c", (float*)rx_amp_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); - octave_save_float(fout, "rx_phi_log_c", (float*)rx_phi_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); - octave_save_complex(fout, "rx_symb_log_c", (COMP*)rx_symb_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); + octave_save_complex(fout, "ch_symb_log_c", (COMP*)coh->ch_symb_log, coh->ch_symb_log_r, COHPSK_NC*ND, COHPSK_NC*ND); + octave_save_float(fout, "rx_amp_log_c", (float*)rx_amp_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); + octave_save_float(fout, "rx_phi_log_c", (float*)rx_phi_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); + octave_save_complex(fout, "rx_symb_log_c", (COMP*)rx_symb_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); fclose(fout); return 0; diff --git a/codec2-dev/unittest/tfdmdv.c b/codec2-dev/unittest/tfdmdv.c index cd2513c7..9fbdfdff 100644 --- a/codec2-dev/unittest/tfdmdv.c +++ b/codec2-dev/unittest/tfdmdv.c @@ -1,14 +1,14 @@ /*---------------------------------------------------------------------------*\ - + FILE........: tfdmdv.c - AUTHOR......: David Rowe + AUTHOR......: David Rowe DATE CREATED: April 16 2012 - + Tests for the C version of the FDMDV modem. This program outputs a file of Octave vectors that are loaded and automatically tested against the Octave version of the modem by the Octave script tfmddv.m - + \*---------------------------------------------------------------------------*/ /* @@ -105,7 +105,7 @@ int main(int argc, char *argv[]) printf("sizeof FDMDV states: %d bytes\n", sizeof(struct FDMDV)); for(f=0; fprev_tx_symbols, tx_bits, &fdmdv->tx_pilot_bit, 0); memcpy(fdmdv->prev_tx_symbols, tx_symbols, sizeof(COMP)*(FDMDV_NC+1)); - tx_filter_and_upconvert(tx_fdm, FDMDV_NC , tx_symbols, fdmdv->tx_filter_memory, + tx_filter_and_upconvert(tx_fdm, FDMDV_NC , tx_symbols, fdmdv->tx_filter_memory, fdmdv->phase_tx, fdmdv->freq, &fdmdv->fbb_phase_tx, fdmdv->fbb_rect); /* --------------------------------------------------------*\ @@ -143,7 +143,7 @@ int main(int argc, char *argv[]) for(i=0,j=nin; jsync == 0) fdmdv->foff = foff_coarse; fdmdv_freq_shift(rx_fdm_fcorr, rx_fdm, -fdmdv->foff, &fdmdv->foff_phase_rect, nin); - + /* 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, + 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); - rx_timing = rx_est_timing(rx_symbols, FDMDV_NC, rx_filt, fdmdv->rx_filter_mem_timing, env, nin, M); + rx_timing = rx_est_timing(rx_symbols, FDMDV_NC, rx_filt, fdmdv->rx_filter_mem_timing, env, nin, M); foff_fine = qpsk_to_bits(rx_bits, &sync_bit, FDMDV_NC, fdmdv->phase_difference, fdmdv->prev_rx_symbols, rx_symbols, 0); //for(i=0; isig_est, fdmdv->noise_est, FDMDV_NC, fdmdv->phase_difference); memcpy(fdmdv->prev_rx_symbols, rx_symbols, sizeof(COMP)*(FDMDV_NC+1)); - + next_nin = M; - + if (rx_timing > 2*M/P) next_nin += M/P; - + if (rx_timing < 0) next_nin -= M/P; - + fdmdv->sync = freq_state(&reliable_sync_bit, sync_bit, &fdmdv->fest_state, &fdmdv->timer, fdmdv->sync_mem); fdmdv->foff -= TRACK_COEFF*foff_fine; /* --------------------------------------------------------*\ - Log each vector + Log each vector \*---------------------------------------------------------*/ memcpy(&tx_bits_log[FDMDV_BITS_PER_FRAME*f], tx_bits, sizeof(int)*FDMDV_BITS_PER_FRAME); @@ -211,7 +211,7 @@ int main(int argc, char *argv[]) for(c=0; cphase_difference[c]; } - + /* qpsk_to_bits() */ memcpy(&rx_bits_log[FDMDV_BITS_PER_FRAME*f], rx_bits, sizeof(int)*FDMDV_BITS_PER_FRAME); @@ -249,7 +249,7 @@ int main(int argc, char *argv[]) /*---------------------------------------------------------*\ - Dump logs to Octave file for evaluation + Dump logs to Octave file for evaluation by tfdmdv.m Octave script \*---------------------------------------------------------*/ @@ -257,31 +257,31 @@ int main(int argc, char *argv[]) assert(fout != NULL); fprintf(fout, "# Created by tfdmdv.c\n"); octave_save_int(fout, "tx_bits_log_c", tx_bits_log, 1, FDMDV_BITS_PER_FRAME*FRAMES); - octave_save_complex(fout, "tx_symbols_log_c", tx_symbols_log, 1, (FDMDV_NC+1)*FRAMES, (FDMDV_NC+1)*FRAMES); - octave_save_complex(fout, "tx_fdm_log_c", (COMP*)tx_fdm_log, 1, M*FRAMES, M*FRAMES); - octave_save_complex(fout, "pilot_lut_c", (COMP*)fdmdv->pilot_lut, 1, NPILOT_LUT, NPILOT_LUT); - octave_save_complex(fout, "pilot_baseband1_log_c", pilot_baseband1_log, 1, NPILOTBASEBAND*FRAMES, NPILOTBASEBAND*FRAMES); - octave_save_complex(fout, "pilot_baseband2_log_c", pilot_baseband2_log, 1, NPILOTBASEBAND*FRAMES, NPILOTBASEBAND*FRAMES); - octave_save_float(fout, "pilot_coeff_c", pilot_coeff, 1, NPILOTCOEFF, NPILOTCOEFF); - octave_save_complex(fout, "pilot_lpf1_log_c", pilot_lpf1_log, 1, NPILOTLPF*FRAMES, NPILOTLPF*FRAMES); - octave_save_complex(fout, "pilot_lpf2_log_c", pilot_lpf2_log, 1, NPILOTLPF*FRAMES, NPILOTLPF*FRAMES); - octave_save_complex(fout, "S1_log_c", S1_log, 1, MPILOTFFT*FRAMES, MPILOTFFT*FRAMES); - octave_save_complex(fout, "S2_log_c", S2_log, 1, MPILOTFFT*FRAMES, MPILOTFFT*FRAMES); - octave_save_float(fout, "foff_log_c", foff_log, 1, FRAMES, FRAMES); - octave_save_float(fout, "foff_coarse_log_c", foff_coarse_log, 1, FRAMES, FRAMES); - octave_save_complex(fout, "rx_baseband_log_c", (COMP*)rx_baseband_log, (FDMDV_NC+1), rx_baseband_log_col_index, (M+M/P)*FRAMES); - octave_save_complex(fout, "rx_filt_log_c", (COMP*)rx_filt_log, (FDMDV_NC+1), rx_filt_log_col_index, (P+1)*FRAMES); - octave_save_float(fout, "env_log_c", env_log, 1, NT*P*FRAMES, NT*P*FRAMES); - octave_save_float(fout, "rx_timing_log_c", rx_timing_log, 1, FRAMES, FRAMES); - octave_save_complex(fout, "rx_symbols_log_c", (COMP*)rx_symbols_log, (FDMDV_NC+1), FRAMES, FRAMES); - octave_save_complex(fout, "phase_difference_log_c", (COMP*)phase_difference_log, (FDMDV_NC+1), FRAMES, FRAMES); - octave_save_float(fout, "sig_est_log_c", (float*)sig_est_log, (FDMDV_NC+1), FRAMES, FRAMES); - octave_save_float(fout, "noise_est_log_c", (float*)noise_est_log, (FDMDV_NC+1), FRAMES, FRAMES); + octave_save_complex(fout, "tx_symbols_log_c", tx_symbols_log, 1, (FDMDV_NC+1)*FRAMES, (FDMDV_NC+1)*FRAMES); + octave_save_complex(fout, "tx_fdm_log_c", (COMP*)tx_fdm_log, 1, M*FRAMES, M*FRAMES); + octave_save_complex(fout, "pilot_lut_c", (COMP*)fdmdv->pilot_lut, 1, NPILOT_LUT, NPILOT_LUT); + octave_save_complex(fout, "pilot_baseband1_log_c", pilot_baseband1_log, 1, NPILOTBASEBAND*FRAMES, NPILOTBASEBAND*FRAMES); + octave_save_complex(fout, "pilot_baseband2_log_c", pilot_baseband2_log, 1, NPILOTBASEBAND*FRAMES, NPILOTBASEBAND*FRAMES); + octave_save_float(fout, "pilot_coeff_c", pilot_coeff, 1, NPILOTCOEFF, NPILOTCOEFF); + octave_save_complex(fout, "pilot_lpf1_log_c", pilot_lpf1_log, 1, NPILOTLPF*FRAMES, NPILOTLPF*FRAMES); + octave_save_complex(fout, "pilot_lpf2_log_c", pilot_lpf2_log, 1, NPILOTLPF*FRAMES, NPILOTLPF*FRAMES); + octave_save_complex(fout, "S1_log_c", S1_log, 1, MPILOTFFT*FRAMES, MPILOTFFT*FRAMES); + octave_save_complex(fout, "S2_log_c", S2_log, 1, MPILOTFFT*FRAMES, MPILOTFFT*FRAMES); + octave_save_float(fout, "foff_log_c", foff_log, 1, FRAMES, FRAMES); + octave_save_float(fout, "foff_coarse_log_c", foff_coarse_log, 1, FRAMES, FRAMES); + octave_save_complex(fout, "rx_baseband_log_c", (COMP*)rx_baseband_log, (FDMDV_NC+1), rx_baseband_log_col_index, (M+M/P)*FRAMES); + octave_save_complex(fout, "rx_filt_log_c", (COMP*)rx_filt_log, (FDMDV_NC+1), rx_filt_log_col_index, (P+1)*FRAMES); + octave_save_float(fout, "env_log_c", env_log, 1, NT*P*FRAMES, NT*P*FRAMES); + octave_save_float(fout, "rx_timing_log_c", rx_timing_log, 1, FRAMES, FRAMES); + octave_save_complex(fout, "rx_symbols_log_c", (COMP*)rx_symbols_log, (FDMDV_NC+1), FRAMES, FRAMES); + octave_save_complex(fout, "phase_difference_log_c", (COMP*)phase_difference_log, (FDMDV_NC+1), FRAMES, FRAMES); + octave_save_float(fout, "sig_est_log_c", (float*)sig_est_log, (FDMDV_NC+1), FRAMES, FRAMES); + octave_save_float(fout, "noise_est_log_c", (float*)noise_est_log, (FDMDV_NC+1), FRAMES, FRAMES); octave_save_int(fout, "rx_bits_log_c", rx_bits_log, 1, FDMDV_BITS_PER_FRAME*FRAMES); - octave_save_float(fout, "foff_fine_log_c", foff_fine_log, 1, FRAMES, FRAMES); - octave_save_int(fout, "sync_bit_log_c", sync_bit_log, 1, FRAMES); - octave_save_int(fout, "sync_log_c", sync_log, 1, FRAMES); - octave_save_int(fout, "nin_log_c", nin_log, 1, FRAMES); + octave_save_float(fout, "foff_fine_log_c", foff_fine_log, 1, FRAMES, FRAMES); + octave_save_int(fout, "sync_bit_log_c", sync_bit_log, 1, FRAMES); + octave_save_int(fout, "sync_log_c", sync_log, 1, FRAMES); + octave_save_int(fout, "nin_log_c", nin_log, 1, FRAMES); fclose(fout); fdmdv_destroy(fdmdv); diff --git a/codec2-dev/unittest/tfifo.c b/codec2-dev/unittest/tfifo.c index 12e0d2b6..5c96fcd1 100644 --- a/codec2-dev/unittest/tfifo.c +++ b/codec2-dev/unittest/tfifo.c @@ -1,4 +1,4 @@ -/* +/* tfifo.c David Rowe Nov 19 2012 @@ -13,7 +13,7 @@ #define FIFO_SZ 1024 #define WRITE_SZ 10 -#define READ_SZ 8 +#define READ_SZ 8 #define N_MAX 100 #define LOOPS 1000000 @@ -54,7 +54,7 @@ int main() { if (sucess) { for(j=0; jL); for(i=1; i<=model->L; i++) ps = get_next_float(ps, &model->A[i]); - + fclose(f); } -void load_or_make_amp(MODEL *model, +void load_or_make_amp(MODEL *model, const char * filename, int frame, float f0, float cdB, float mdBHz) { diff --git a/codec2-dev/unittest/tlspsens.c b/codec2-dev/unittest/tlspsens.c index 4200d570..da4f82e9 100644 --- a/codec2-dev/unittest/tlspsens.c +++ b/codec2-dev/unittest/tlspsens.c @@ -1,12 +1,12 @@ /*---------------------------------------------------------------------------*\ - - FILE........: tlspsens.c - AUTHOR......: David Rowe + + FILE........: tlspsens.c + AUTHOR......: David Rowe DATE CREATED: 31 May 2012 - + Testing bit error sensitivity of LSP bits, first step in devising an unequal error protection scheme. - + \*---------------------------------------------------------------------------*/ /* @@ -94,7 +94,7 @@ float run_a_test(char raw_file_name[], int bit_to_corrupt) check_lsp_order(lsps, LPC_ORD); bw_expand_lsps(lsps, LPC_ORD, 50.0, 100.0); lsp_to_lpc(lsps, ak, LPC_ORD); - aks_to_M2(fft_fwd_cfg, ak, LPC_ORD, &model, e, &snr, 0, 0, 1, 1, LPCPF_BETA, LPCPF_GAMMA, Aw); + aks_to_M2(fft_fwd_cfg, ak, LPC_ORD, &model, e, &snr, 0, 0, 1, 1, LPCPF_BETA, LPCPF_GAMMA, Aw); snr_sum += snr; frames++; } @@ -105,7 +105,7 @@ float run_a_test(char raw_file_name[], int bit_to_corrupt) return snr_sum/frames; } - + int main(int argc, char *argv[]) { int i; int total_lsp_bits = 0; diff --git a/codec2-dev/unittest/tnlp.c b/codec2-dev/unittest/tnlp.c index 89a69a11..b75b369b 100644 --- a/codec2-dev/unittest/tnlp.c +++ b/codec2-dev/unittest/tnlp.c @@ -1,11 +1,11 @@ /*---------------------------------------------------------------------------*\ - - FILE........: tnlp.c - AUTHOR......: David Rowe - DATE CREATED: 23/3/93 - - Test program for non linear pitch estimation functions. - + + FILE........: tnlp.c + AUTHOR......: David Rowe + DATE CREATED: 23/3/93 + + Test program for non linear pitch estimation functions. + \*---------------------------------------------------------------------------*/ /* @@ -45,13 +45,13 @@ int frames; /*---------------------------------------------------------------------------*\ - - switch_present() - - Searches the command line arguments for a "switch". If the switch is - found, returns the command line argument where it ws found, else returns - NULL. - + + switch_present() + + Searches the command line arguments for a "switch". If the switch is + found, returns the command line argument where it ws found, else returns + NULL. + \*---------------------------------------------------------------------------*/ int switch_present(sw,argc,argv) @@ -86,7 +86,7 @@ char *argv[]; float w[M]; /* time domain hamming window */ COMP W[FFT_ENC]; /* DFT of w[] */ float pitch; - int i; + int i; float prev_Wo; void *nlp_states; #ifdef DUMP @@ -115,7 +115,7 @@ char *argv[]; #ifdef DUMP dump = switch_present("--dump",argc,argv); - if (dump) + if (dump) dump_on(argv[dump+1]); #else /// TODO @@ -139,7 +139,7 @@ char *argv[]; Sn[i+M-N] = buf[i]; dft_speech(fft_fwd_cfg, Sw, Sn, w); #ifdef DUMP - dump_Sn(Sn); dump_Sw(Sw); + dump_Sn(Sn); dump_Sw(Sw); #endif nlp(nlp_states,Sn,N,PITCH_MIN,PITCH_MAX,&pitch,Sw,W, &prev_Wo); @@ -157,5 +157,5 @@ char *argv[]; return 0; } - + diff --git a/codec2-dev/unittest/tprede.c b/codec2-dev/unittest/tprede.c index cbde69f5..4d3d09c7 100644 --- a/codec2-dev/unittest/tprede.c +++ b/codec2-dev/unittest/tprede.c @@ -1,4 +1,4 @@ -/* +/* tpre_de.c David Rowe Sep 24 2012 @@ -21,7 +21,7 @@ #include #include "lpc.h" -#define N 10 +#define N 10 #define F 10 int main() { @@ -32,7 +32,7 @@ int main() { fprede = fopen("prede.txt", "wt"); assert(fprede != NULL); - + for(i=0; i. + along with this program; if not, see . */ #include @@ -76,10 +76,10 @@ int test_energy_quant(int levels, float max_error_dB) { e = decode_energy(index_in, E_BITS); index_out = encode_energy(e, E_BITS); if (index_in != index_out) { - printf("edB: %f index_in: %d index_out: %d\n", + printf("edB: %f index_in: %d index_out: %d\n", 10.0*log10(e), index_in, index_out); exit(0); - } + } } /* check error over range of quantiser */ @@ -116,7 +116,7 @@ int test_lsp(int lsp_number, int levels, float max_error_hz) { lsp_number--; max_error_rads = max_error_hz*TWO_PI/FS; - + for(i=0; i pop_thresh) { @@ -211,7 +211,7 @@ int main(int argc, char *argv[]) { } } fclose(fvq); - + return 0; } @@ -222,10 +222,10 @@ int main(int argc, char *argv[]) { \*-----------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*\ - - FUNCTION....: locate_lsps_jnd_steps() - AUTHOR......: David Rowe - DATE CREATED: 27/10/2011 + + FUNCTION....: locate_lsps_jnd_steps() + AUTHOR......: David Rowe + DATE CREATED: 27/10/2011 Applies a form of Bandwidth Expansion (BW) to a vector of LSPs. Listening tests have determined that "quantising" the position of diff --git a/codec2-dev/unittest/vqtrainph.c b/codec2-dev/unittest/vqtrainph.c index f8e016da..ec0a8883 100644 --- a/codec2-dev/unittest/vqtrainph.c +++ b/codec2-dev/unittest/vqtrainph.c @@ -81,7 +81,7 @@ int main(int argc, char *argv[]) { int J; /* number of vectors in training set */ int ind; /* index of current vector */ float se; /* total squared error for this iteration */ - float var; /* variance */ + float var; /* variance */ float var_1; /* previous variance */ float delta; /* improvement in distortion */ FILE *ftrain; /* file containing training set */ @@ -148,7 +148,7 @@ int main(int argc, char *argv[]) { cb[i].real = 1.0; cb[i].imag = 0.0; } - + //print_vec(cb, d, 1); /* main loop */ @@ -184,13 +184,13 @@ int main(int argc, char *argv[]) { n[ind]++; acc(¢[ind*d], vec, d); } - + /* work out stats */ - var = se/var_n; + var = se/var_n; sd_vec = sqrt(var); - /* we need to know dimension of cb (which varies from vector to vector) + /* we need to know dimension of cb (which varies from vector to vector) to calc bits_theory. Maybe measure and use average dimension.... */ //bits_theory = d*log10(PI/(sd_element*sqrt(3.0)))/log10(2.0); @@ -209,8 +209,8 @@ int main(int argc, char *argv[]) { delta = 0; if (delta < DELTAQ) finished = 1; - } - + } + if (!finished) { /* determine new codebook from centroids */ @@ -221,13 +221,13 @@ int main(int argc, char *argv[]) { } printf("%2d %4.3f %4.3f %4.3f \n",iterations, delta, var, sd_vec); - + var_1 = var; } while (!finished); //print_vec(cb, d, 1); - + /* save codebook to disk */ fvq = fopen(argv[4],"wt"); @@ -258,7 +258,7 @@ void print_vec(COMP cb[], int d, int e) int i,j; for(j=0; j