From: baobrien Date: Wed, 23 Sep 2015 14:28:25 +0000 (+0000) Subject: Accepted Stuart's patch to correct SM1000 build issue after freedv api change X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=91525881187a986d8eb0865f8120ab7c881d384c;p=freetel-svn-tracking.git Accepted Stuart's patch to correct SM1000 build issue after freedv api change git-svn-id: https://svn.code.sf.net/p/freetel/code@2350 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/stm32/src/sm1000_main.c b/codec2-dev/stm32/src/sm1000_main.c index 56a2b951..b9d548dc 100644 --- a/codec2-dev/stm32/src/sm1000_main.c +++ b/codec2-dev/stm32/src/sm1000_main.c @@ -1,248 +1,247 @@ -/*---------------------------------------------------------------------------*\ - - FILE........: sm1000_main.c - AUTHOR......: David Rowe - DATE CREATED: August 5 2014 - - Main program for SM1000. - - TODO - - [ ] make led blink 1-2-3 times for "mode" - -\*---------------------------------------------------------------------------*/ - -/* - Copyright (C) 2014 David Rowe - - All rights reserved. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1, as - published by the Free Software Foundation. This program is - distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, see . -*/ - -#include "stm32f4_adc.h" -#include "stm32f4_dac.h" -#include "freedv_api.h" -#include "codec2_fdmdv.h" -#include "sm1000_leds_switches.h" -#include -#include - -#define FREEDV_NSAMPLES_16K (2*FREEDV_NSAMPLES) - -#define FIFTY_MS 50 -#define MAX_MODES 3 -#define ANALOG 0 -#define DV 1 -#define TONE 2 - -#define SS_IDLE 0 -#define SS_DEBOUNCE_DOWN 1 -#define SS_WAIT_BUTTON_UP 2 -#define SS_DEBOUNCE_UP 3 - -typedef struct { - int state; - int mode; -} SWITCH_STATE; - -unsigned int downTicker; - -void SysTick_Handler(void); -void iterate_select_state_machine(SWITCH_STATE *ss); - -#define SINE_SAMPLES 32 - -/* 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 aSine[] = { - -16, 6384, 12528, 18192, 23200, 27232, 30256, 32128, - 32752, 32128, 30256, 27232, 23152, 18192, 12528, 6384, - -16, -6416, -12560, -18224, -23184, -27264, -30288, -32160, - -32768, -32160, -30288, -27264, -23184, -18224, -12560, -6416 -}; - -int main(void) { - struct freedv *f; - SWITCH_STATE ss; - int nin, nout, i; - int n_samples, n_samples_16k; - - /* init all the drivers for various peripherals */ - - SysTick_Config(SystemCoreClock/168000); /* 1 kHz SysTick */ - sm1000_leds_switches_init(); - dac_open(4*DAC_BUF_SZ); - adc_open(4*ADC_BUF_SZ); - f = freedv_open(FREEDV_MODE_1600); - n_samples = freedv_get_n_speech_samples(f); - n_samples_16k = 2*n_samples; - - short adc16k[FDMDV_OS_TAPS_16K+n_samples_16k]; - short dac16k[n_samples_16k]; - short adc8k[n_samples]; - short dac8k[FDMDV_OS_TAPS_8K+n_samples]; - - /* put outputs into a known state */ - - led_pwr(1); led_ptt(0); led_rt(0); led_err(0); not_cptt(1); - - /* clear filter memories */ - - for(i=0; iODR = (1 << 3); - - /* clipping indicator */ - - led_err(0); - for (i=0; i 28000) - led_err(1); - } - - fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], n_samples); - - if (ss.mode == ANALOG) { - for(i=0; iODR &= ~(1 << 3); - } - - } - else { - - /* Receive --------------------------------------------------------------------------*/ - - not_cptt(1); led_ptt(0); - - /* ADC1 is the demod in signal from the radio rx, DAC2 is the SM1000 speaker */ - - if (ss.mode == ANALOG) { - - if (adc1_read(&adc16k[FDMDV_OS_TAPS_16K], n_samples_16k) == 0) { - fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], n_samples); - 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); - dac2_write(dac16k, 2*nout); - led_rt(freedv_get_sync(f)); led_err(freedv_get_total_bit_errors(f)); - GPIOE->ODR &= ~(1 << 3); - } - } - - } - } /* while(1) ... */ -} - -/* - * SysTick Interrupt Handler - */ - -void SysTick_Handler(void) -{ - if (downTicker > 0) { - downTicker--; - } -} - -/* Select button state machine. Debounces switches and enables cycling - through ANALOG-DV-TONE modes */ - -void iterate_select_state_machine(SWITCH_STATE *ss) { - int next_state; - - next_state = ss->state; - switch(ss->state) { - case SS_IDLE: - if (switch_select() == 0) { - downTicker = FIFTY_MS; - next_state = SS_DEBOUNCE_DOWN; - } - break; - case SS_DEBOUNCE_DOWN: - if (downTicker == 0) { - ss->mode++; - if (ss->mode >= MAX_MODES) - ss->mode = 0; - next_state = SS_WAIT_BUTTON_UP; - } - break; - case SS_WAIT_BUTTON_UP: - if (switch_select() == 1) { - downTicker = FIFTY_MS; - next_state = SS_DEBOUNCE_UP; - } - break; - case SS_DEBOUNCE_UP: - if (downTicker == 0) { - next_state = SS_IDLE; - } - break; - } - ss->state = next_state; -} - +/*---------------------------------------------------------------------------*\ + + FILE........: sm1000_main.c + AUTHOR......: David Rowe + DATE CREATED: August 5 2014 + + Main program for SM1000. + + TODO + + [ ] make led blink 1-2-3 times for "mode" + +\*---------------------------------------------------------------------------*/ + +/* + Copyright (C) 2014 David Rowe + + All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 2.1, as + published by the Free Software Foundation. This program is + distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, see . +*/ + +#include "stm32f4_adc.h" +#include "stm32f4_dac.h" +#include "freedv_api.h" +#include "codec2_fdmdv.h" +#include "sm1000_leds_switches.h" +#include +#include + +#define FREEDV_NSAMPLES_16K (2*FREEDV_NSAMPLES) + +#define FIFTY_MS 50 +#define MAX_MODES 3 +#define ANALOG 0 +#define DV 1 +#define TONE 2 + +#define SS_IDLE 0 +#define SS_DEBOUNCE_DOWN 1 +#define SS_WAIT_BUTTON_UP 2 +#define SS_DEBOUNCE_UP 3 + +typedef struct { + int state; + int mode; +} SWITCH_STATE; + +unsigned int downTicker; + +void SysTick_Handler(void); +void iterate_select_state_machine(SWITCH_STATE *ss); + +#define SINE_SAMPLES 32 + +/* 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 aSine[] = { + -16, 6384, 12528, 18192, 23200, 27232, 30256, 32128, + 32752, 32128, 30256, 27232, 23152, 18192, 12528, 6384, + -16, -6416, -12560, -18224, -23184, -27264, -30288, -32160, + -32768, -32160, -30288, -27264, -23184, -18224, -12560, -6416 +}; + +int main(void) { + struct freedv *f; + SWITCH_STATE ss; + int nin, nout, i; + int n_samples, n_samples_16k; + + /* init all the drivers for various peripherals */ + + SysTick_Config(SystemCoreClock/168000); /* 1 kHz SysTick */ + sm1000_leds_switches_init(); + dac_open(4*DAC_BUF_SZ); + adc_open(4*ADC_BUF_SZ); + f = freedv_open(FREEDV_MODE_1600); + n_samples = freedv_get_n_speech_samples(f); + n_samples_16k = 2*n_samples; + + short adc16k[FDMDV_OS_TAPS_16K+n_samples_16k]; + short dac16k[n_samples_16k]; + short adc8k[n_samples]; + short dac8k[FDMDV_OS_TAPS_8K+n_samples]; + + /* put outputs into a known state */ + + led_pwr(1); led_ptt(0); led_rt(0); led_err(0); not_cptt(1); + + /* clear filter memories */ + + for(i=0; iODR = (1 << 3); + + /* clipping indicator */ + + led_err(0); + for (i=0; i 28000) + led_err(1); + } + + fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], n_samples); + + if (ss.mode == ANALOG) { + for(i=0; iODR &= ~(1 << 3); + } + + } + else { + + /* Receive --------------------------------------------------------------------------*/ + + not_cptt(1); led_ptt(0); + + /* ADC1 is the demod in signal from the radio rx, DAC2 is the SM1000 speaker */ + + if (ss.mode == ANALOG) { + + if (adc1_read(&adc16k[FDMDV_OS_TAPS_16K], n_samples_16k) == 0) { + fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], n_samples); + 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); + dac2_write(dac16k, 2*nout); + led_rt(freedv_get_sync(f)); led_err(freedv_get_total_bit_errors(f)); + GPIOE->ODR &= ~(1 << 3); + } + } + + } + } /* while(1) ... */ +} + +/* + * SysTick Interrupt Handler + */ + +void SysTick_Handler(void) +{ + if (downTicker > 0) { + downTicker--; + } +} + +/* Select button state machine. Debounces switches and enables cycling + through ANALOG-DV-TONE modes */ + +void iterate_select_state_machine(SWITCH_STATE *ss) { + int next_state; + + next_state = ss->state; + switch(ss->state) { + case SS_IDLE: + if (switch_select() == 0) { + downTicker = FIFTY_MS; + next_state = SS_DEBOUNCE_DOWN; + } + break; + case SS_DEBOUNCE_DOWN: + if (downTicker == 0) { + ss->mode++; + if (ss->mode >= MAX_MODES) + ss->mode = 0; + next_state = SS_WAIT_BUTTON_UP; + } + break; + case SS_WAIT_BUTTON_UP: + if (switch_select() == 1) { + downTicker = FIFTY_MS; + next_state = SS_DEBOUNCE_UP; + } + break; + case SS_DEBOUNCE_UP: + if (downTicker == 0) { + next_state = SS_IDLE; + } + break; + } + ss->state = next_state; +} +