From 1642f7ef58660b2db5e0ff81d7dcaa84b412b530 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Mon, 21 Jul 2014 08:41:42 +0000 Subject: [PATCH] started coding driver for LEDs and swicthes, dual ch DAC driver looks OK, but would like to test some more git-svn-id: https://svn.code.sf.net/p/freetel/code@1766 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/stm32/inc/leds_switches.h | 37 ++++++++++++++ codec2-dev/stm32/src/dac_ut.c | 13 ++--- codec2-dev/stm32/src/fdmdv_profile.c | 20 +++++--- codec2-dev/stm32/src/leds_switches.c | 72 ++++++++++++++++++++++++++++ codec2-dev/stm32/src/stm32f4_dac.c | 23 +++++---- 5 files changed, 142 insertions(+), 23 deletions(-) create mode 100644 codec2-dev/stm32/inc/leds_switches.h create mode 100644 codec2-dev/stm32/src/leds_switches.c diff --git a/codec2-dev/stm32/inc/leds_switches.h b/codec2-dev/stm32/inc/leds_switches.h new file mode 100644 index 00000000..98ddbdd9 --- /dev/null +++ b/codec2-dev/stm32/inc/leds_switches.h @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------*\ + + FILE........: leds_switches.h + AUTHOR......: David Rowe + DATE CREATED: 18 July 2014 + + Functions for controlling LEDs and reading switches on SM1000. + +\*---------------------------------------------------------------------------*/ + +/* + 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 . +*/ + +#ifndef __LEDS_SWITCHES__ +#define __LEDS_SWITCHES__ + +void leds_switches_init(void); +void led_pwr(int state); +void led_ptt(int state); +void led_rt(int state); +void led_err(int state); + +#endif diff --git a/codec2-dev/stm32/src/dac_ut.c b/codec2-dev/stm32/src/dac_ut.c index 2da1131f..039c6da3 100644 --- a/codec2-dev/stm32/src/dac_ut.c +++ b/codec2-dev/stm32/src/dac_ut.c @@ -32,15 +32,15 @@ #define SINE_SAMPLES 32 -/* 32 sample sine wave which at Fs=16kHz will be 500Hz. Not sampels +/* 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 + -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) { @@ -48,8 +48,9 @@ int main(void) { while (1) { - /* keep DAC FIFO topped up */ + /* keep DAC FIFOs topped up */ + dac1_write((short*)aSine, SINE_SAMPLES); dac2_write((short*)aSine, SINE_SAMPLES); } diff --git a/codec2-dev/stm32/src/fdmdv_profile.c b/codec2-dev/stm32/src/fdmdv_profile.c index 0e4e765f..2826b309 100644 --- a/codec2-dev/stm32/src/fdmdv_profile.c +++ b/codec2-dev/stm32/src/fdmdv_profile.c @@ -4,7 +4,7 @@ AUTHOR......: David Rowe DATE CREATED: 18 July 2014 - Profiling Codec 2 operation on the STM32F4. + Profiling FDMDV modem operation on the STM32F4. \*---------------------------------------------------------------------------*/ @@ -55,16 +55,19 @@ int main(int argc, char *argv[]) { int *tx_bits; int *rx_bits; COMP tx_fdm[2*FDMDV_NOM_SAMPLES_PER_FRAME]; - int i, nin, reliable_sync_bit, sync_bit; + int i, nin, reliable_sync_bit, sync_bit, bit_errors, ntest_bits, test_frame_sync; + short *error_pattern; struct FDMDV_STATS stats; TIMER_VAR(mod_start, demod_start); + machdep_timer_init (); fdmdv = fdmdv_create(FDMDV_NC); bits_per_fdmdv_frame = fdmdv_bits_per_frame(fdmdv); bits_per_codec_frame = 2*fdmdv_bits_per_frame(fdmdv); tx_bits = (int*)malloc(sizeof(int)*bits_per_codec_frame); assert(tx_bits != NULL); rx_bits = (int*)malloc(sizeof(int)*bits_per_codec_frame); assert(rx_bits != NULL); + error_pattern = (short*)malloc(fdmdv_error_pattern_size(fdmdv)*sizeof(int)); assert(error_pattern != NULL); nin = FDMDV_NOM_SAMPLES_PER_FRAME; @@ -79,15 +82,18 @@ int main(int argc, char *argv[]) { fdmdv_mod(fdmdv, &tx_fdm[FDMDV_NOM_SAMPLES_PER_FRAME], &tx_bits[bits_per_fdmdv_frame], &sync_bit); assert(sync_bit == 0); - TIMER_SAMPLE_AND_LOG(demod_start, mod_start, " enc"); + TIMER_SAMPLE_AND_LOG(demod_start, mod_start, " mod"); fdmdv_demod(fdmdv, rx_bits, &reliable_sync_bit, tx_fdm, &nin); - fdmdv_demod(fdmdv, rx_bits, &reliable_sync_bit, &tx_fdm[FDMDV_NOM_SAMPLES_PER_FRAME], &nin); - TIMER_SAMPLE_AND_LOG2(demod_start, " dec"); - TIMER_SAMPLE_AND_LOG2(mod_start, " enc & dec"); + fdmdv_demod(fdmdv, &rx_bits[bits_per_fdmdv_frame], &reliable_sync_bit, &tx_fdm[FDMDV_NOM_SAMPLES_PER_FRAME], &nin); + TIMER_SAMPLE_AND_LOG2(demod_start, " demod"); + TIMER_SAMPLE_AND_LOG2(mod_start, " mod & demod"); fdmdv_get_demod_stats(fdmdv, &stats); - printf("frame: %d sync: %d reliable_sync_bit: %d SNR: %3.2f\n", i, stats.sync, reliable_sync_bit, (double)stats.snr_est); + fdmdv_put_test_bits(fdmdv, &test_frame_sync, error_pattern, &bit_errors, &ntest_bits, rx_bits); + + printf("frame: %d sync: %d reliable_sync_bit: %d SNR: %3.2f test_frame_sync: %d\n", + i, stats.sync, reliable_sync_bit, (double)stats.snr_est, test_frame_sync); machdep_timer_print_logged_samples(); } diff --git a/codec2-dev/stm32/src/leds_switches.c b/codec2-dev/stm32/src/leds_switches.c new file mode 100644 index 00000000..3985b839 --- /dev/null +++ b/codec2-dev/stm32/src/leds_switches.c @@ -0,0 +1,72 @@ +/*---------------------------------------------------------------------------*\ + + FILE........: leds_switches.c + AUTHOR......: David Rowe + DATE CREATED: 18 July 2014 + + Functions for controlling LEDs and reading switches on SM1000. + +\*---------------------------------------------------------------------------*/ + +/* + 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 . +*/ + +#define LED_PWR 12 +#define LED_PTT 13 +#define LED_RT 14 +#define LED_ERR 15 + +#include "stm32f4xx_conf.h" +#include "stm32f4xx.h" +#include "leds_switches.h" + +void leds_switches_init(void) { + RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN; // enable the clock to GPIOD + + // Set pins as general purpose IOs + + GPIOD->MODER = (2 << LED_PWR) | (2 << LED_PTT) | (2 << LED_RT) | (2 << LED_ERR); +} + +void led_pwr(int state) { + if (state) + GPIOD->ODR = (1 << LED_PWR); + else + GPIOD->ODR &= ~(1 << LED_PWR); +} + +void led_ptt(int state) { + if (state) + GPIOD->ODR = (1 << LED_PTT); + else + GPIOD->ODR &= ~(1 << LED_PTT); +} + +void led_rt(int state) { + if (state) + GPIOD->ODR = (1 << LED_RT); + else + GPIOD->ODR &= ~(1 << LED_RT); +} + +void led_err(int state) { + if (state) + GPIOD->ODR = (1 << LED_ERR); + else + GPIOD->ODR &= ~(1 << LED_ERR); +} + diff --git a/codec2-dev/stm32/src/stm32f4_dac.c b/codec2-dev/stm32/src/stm32f4_dac.c index f79c51df..31fa7348 100644 --- a/codec2-dev/stm32/src/stm32f4_dac.c +++ b/codec2-dev/stm32/src/stm32f4_dac.c @@ -32,7 +32,10 @@ #include "codec2_fifo.h" #include "stm32f4_dac.h" -#define DAC_DHR12R2_ADDRESS 0x40007414 +/* 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_DHR12L1_ADDRESS 0x4000740c #define DAC_DHR12L2_ADDRESS 0x40007418 #define DAC_BUF_SZ 320 @@ -144,7 +147,7 @@ static void dac1_config(void) DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; - DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; + DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; DAC_Init(DAC_Channel_1, &DAC_InitStructure); /* DMA1_Stream5 channel7 configuration **************************************/ @@ -152,7 +155,7 @@ static void dac1_config(void) DMA_DeInit(DMA1_Stream5); DMA_InitStructure.DMA_Channel = DMA_Channel_7; - DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)DAC_DHR12R2_ADDRESS; + DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)DAC_DHR12L1_ADDRESS; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)dac1_buf; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; DMA_InitStructure.DMA_BufferSize = DAC_BUF_SZ; @@ -166,7 +169,7 @@ static void dac1_config(void) DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; - DMA_Init(DMA1_Stream6, &DMA_InitStructure); + DMA_Init(DMA1_Stream5, &DMA_InitStructure); /* Enable DMA Half & Complete interrupts */ @@ -203,7 +206,7 @@ static void dac2_config(void) DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; - DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; + DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; DAC_Init(DAC_Channel_2, &DAC_InitStructure); /* DMA1_Stream6 channel7 configuration **************************************/ @@ -280,7 +283,7 @@ void DMA1_Stream5_IRQHandler(void) { for(i=0; i