aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-04-11 16:22:04 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-04-11 16:22:04 +0200
commiteed7072d6336a3cfdc8b52eb20166529a4de4d81 (patch)
tree1505819a1216406e6f15c4315bed93750c7ed68d /src
parent3555e921a0c743dbc2cc10d8655827be975c61e0 (diff)
downloadglutte-o-matic-eed7072d6336a3cfdc8b52eb20166529a4de4d81.tar.gz
glutte-o-matic-eed7072d6336a3cfdc8b52eb20166529a4de4d81.tar.bz2
glutte-o-matic-eed7072d6336a3cfdc8b52eb20166529a4de4d81.zip
Add some 1750 detection code to glutt-o-logic
Diffstat (limited to 'src')
-rw-r--r--src/common/includes/Audio/audio_in.h15
-rw-r--r--src/common/includes/Audio/tone.h7
-rw-r--r--src/common/includes/Core/common.h1
-rw-r--r--src/common/src/Audio/audio_in.c26
-rw-r--r--src/common/src/Audio/tone.c24
-rw-r--r--src/common/src/Core/main.c60
-rw-r--r--src/common/src/GPIO/usart.c3
-rw-r--r--src/glutt-o-logique/analog_input.c27
-rw-r--r--src/glutt-o-logique/analog_input.h13
-rw-r--r--src/glutt-o-logique/audio_in.c148
-rw-r--r--src/glutt-o-logique/pio.c2
-rw-r--r--src/glutt-o-logique/stm32f4discovery-with-stlinkv2.1.cfg10
-rw-r--r--src/simulator/src/Audio/audio.c8
-rw-r--r--src/simulator/src/Audio/audio_in.c37
-rw-r--r--src/simulator/src/Gui/gui.c5
-rw-r--r--src/simulator/src/Gui/nuklear.h2
-rwxr-xr-xsrc/tone-test-sim/analyse.py6
-rw-r--r--src/tone-test-sim/src/test.c17
18 files changed, 315 insertions, 96 deletions
diff --git a/src/common/includes/Audio/audio_in.h b/src/common/includes/Audio/audio_in.h
index 86c93b2..3bc543c 100644
--- a/src/common/includes/Audio/audio_in.h
+++ b/src/common/includes/Audio/audio_in.h
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
- * Copyright (c) 2018 Maximilien Cuony
+ * Copyright (c) 2019 Matthias P. Braendli, Maximilien Cuony
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -22,19 +22,16 @@
* SOFTWARE.
*/
-#ifndef __AUDIO_IN_H__
-#define __AUDIO_IN_H__
+#pragma once
#include <stdio.h>
#include "FreeRTOS.h"
-#define AUDIO_IN_BUF_LEN 2048
#define AUDIO_IN_RATE 8000
-
-int16_t * audio_in_buffer;
+#define AUDIO_IN_BUF_LEN 32
void audio_in_initialize(int rate);
-void audio_in_initialize_plateform(int rate);
-void audio_in_buffer_ready(void);
-#endif
+// Fill the buffer with AUDIO_IN_BUF_LEN samples.
+void audio_in_get_buffer(int16_t *buffer /*of length AUDIO_IN_BUF_LEN*/ );
+
diff --git a/src/common/includes/Audio/tone.h b/src/common/includes/Audio/tone.h
index 0e80228..861a472 100644
--- a/src/common/includes/Audio/tone.h
+++ b/src/common/includes/Audio/tone.h
@@ -42,6 +42,11 @@ struct tone_detector {
};
void tone_init(int threshold);
-int tone_detect_1750(int16_t sample);
+
+/* Return 1 when 1750 detected, 0 otherwise */
+int tone_1750_status(void);
+
+/* Update 1750 tone detection status */
+void tone_detect_1750(const int16_t *samples, int len);
#endif
diff --git a/src/common/includes/Core/common.h b/src/common/includes/Core/common.h
index b5dc881..3f7dbcc 100644
--- a/src/common/includes/Core/common.h
+++ b/src/common/includes/Core/common.h
@@ -63,6 +63,7 @@ int random_bool(void);
#define FAULT_SOURCE_TASK_OVERFLOW 5
#define FAULT_SOURCE_CW_AUDIO_QUEUE 6
#define FAULT_SOURCE_ADC1 7
+#define FAULT_SOURCE_ADC2 8
void trigger_fault(int source);
int find_last_sunday(const struct tm*);
diff --git a/src/common/src/Audio/audio_in.c b/src/common/src/Audio/audio_in.c
index b046a62..dd1994e 100644
--- a/src/common/src/Audio/audio_in.c
+++ b/src/common/src/Audio/audio_in.c
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
- * Copyright (c) 2018 Maximilien Cuony
+ * Copyright (c) 2019 Matthias P. Braendli, Maximilien Cuony
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -22,27 +22,3 @@
* SOFTWARE.
*/
-#include "Audio/tone.h"
-#include "Audio/audio_in.h"
-
-int16_t audio_in_buffer_0[AUDIO_IN_BUF_LEN];
-int16_t audio_in_buffer_1[AUDIO_IN_BUF_LEN];
-
-void audio_in_initialize(int rate) {
- audio_in_buffer = audio_in_buffer_0;
- audio_in_initialize_plateform(rate);
-}
-
-void audio_in_buffer_ready() {
-
- for (int i = 0; i < AUDIO_IN_BUF_LEN; i++) {
- tone_detect_1750(audio_in_buffer[i]);
- }
-
- if (audio_in_buffer == audio_in_buffer_0) {
- audio_in_buffer = audio_in_buffer_1;
- } else {
- audio_in_buffer = audio_in_buffer_0;
- }
-
-}
diff --git a/src/common/src/Audio/tone.c b/src/common/src/Audio/tone.c
index 60226ce..5065b31 100644
--- a/src/common/src/Audio/tone.c
+++ b/src/common/src/Audio/tone.c
@@ -37,7 +37,12 @@
static struct tone_detector detector_1750;
-int TONE_1750_DETECTED = 0;
+static int tone_1750_detected = 0;
+
+int tone_1750_status()
+{
+ return tone_1750_detected;
+}
static void init_tone(struct tone_detector* detector, int freq, int threshold) {
detector->coef = 2.0f * arm_cos_f32(2.0f * FLOAT_PI * freq / AUDIO_IN_RATE);
@@ -68,6 +73,12 @@ static inline int analyse_sample(int16_t sample, struct tone_detector *detector)
detector->Q2 * detector->Q2 -
detector->coef * detector->Q1 * detector->Q2);
+#ifdef SIMULATOR
+#define FRMT "%- 12.4f"
+ fprintf(stderr, "1750: Q1 " FRMT " Q2 " FRMT " m " FRMT " thresh " FRMT "\n", detector->Q1, detector->Q2, m, detector->threshold);
+#endif
+
+
detector->Q1 = 0;
detector->Q2 = 0;
detector->num_samples_analysed = 0;
@@ -84,12 +95,13 @@ static inline int analyse_sample(int16_t sample, struct tone_detector *detector)
}
}
-int tone_detect_1750(int16_t sample)
+void tone_detect_1750(const int16_t *samples, int len)
{
- int r = analyse_sample(sample, &detector_1750);
- if (r == 0 || r == 1) {
- TONE_1750_DETECTED = r;
+ for (int i = 0; i < len; i++) {
+ int r = analyse_sample(samples[i], &detector_1750);
+ if (r == 0 || r == 1) {
+ tone_1750_detected = r;
+ }
}
- return r;
}
diff --git a/src/common/src/Core/main.c b/src/common/src/Core/main.c
index d303e09..ed3dfef 100644
--- a/src/common/src/Core/main.c
+++ b/src/common/src/Core/main.c
@@ -50,13 +50,15 @@
#include "GPIO/analog.h"
#include "vc.h"
+#ifdef SIMULATOR
+extern int gui_in_tone_1750;
+#endif
+
static int tm_trigger_button = 0;
static struct fsm_input_signals_t fsm_input;
static int hour_is_even = 0;
-extern int TONE_1750_DETECTED;
-
/* Threshold for SWR measurement */
const int swr_refl_threshold = 10; // mV
@@ -79,6 +81,7 @@ void init(void);
// Tasks
static void detect_button_press(void *pvParameters);
static void exercise_fsm(void *pvParameters);
+static void nf_analyse(void *pvParameters);
static void gps_monit_task(void *pvParameters);
static void launcher_task(void *pvParameters);
@@ -198,10 +201,6 @@ static void launcher_task(void __attribute__ ((unused))*pvParameters)
trigger_fault(FAULT_SOURCE_MAIN);
}
- usart_debug_puts("Tone init\r\n");
-#warning TODO
- tone_init(20000);
-
usart_debug_puts("Audio init\r\n");
audio_initialize(Audio16000HzSettings);
@@ -211,9 +210,26 @@ static void launcher_task(void __attribute__ ((unused))*pvParameters)
usart_debug_puts("Audio set callback\r\n");
audio_play_with_callback(audio_callback, NULL);
+ usart_debug_puts("Tone init\r\n");
+ tone_init(120000);
+
usart_debug_puts("Audio in init\r\n");
audio_in_initialize(AUDIO_IN_RATE);
+ usart_debug_puts("TaskNF init\r\n");
+
+ xTaskCreate(
+ nf_analyse,
+ "TaskNF",
+ 1*configMINIMAL_STACK_SIZE,
+ (void*) NULL,
+ tskIDLE_PRIORITY + 2UL,
+ &task_handle);
+
+ if (!task_handle) {
+ trigger_fault(FAULT_SOURCE_MAIN);
+ }
+
usart_debug_puts("Init done.\r\n");
int last_qrp_from_supply = 0;
@@ -489,11 +505,12 @@ static void gps_monit_task(void __attribute__ ((unused))*pvParameters) {
static void exercise_fsm(void __attribute__ ((unused))*pvParameters)
{
+ fsm_init();
+
int cw_last_trigger = 0;
int last_tm_trigger_button = 0;
int last_sq = 0;
- int last_1750 = 0;
int last_qrp = 0;
int last_cw_done = 0;
int last_discrim_d = 0;
@@ -561,8 +578,10 @@ static void exercise_fsm(void __attribute__ ((unused))*pvParameters)
leds_turn_on(LED_ORANGE);
}
-#warning "TODO: from tone detector"
- fsm_input.det_1750 = TONE_1750_DETECTED;
+#ifdef SIMULATOR
+ gui_in_tone_1750 =
+#endif
+ fsm_input.det_1750 = tone_1750_status();
fsm_input.fax_mode = 0;
fsm_input.swr_high = swr_error_flag;
@@ -589,3 +608,26 @@ static void exercise_fsm(void __attribute__ ((unused))*pvParameters)
}
}
+
+static int16_t audio_in_buffer[AUDIO_IN_BUF_LEN];
+static int led_phase = 0;
+static void nf_analyse(void __attribute__ ((unused))*pvParameters)
+{
+ while (1) {
+ if (led_phase == 0) {
+ leds_turn_on(LED_BLUE);
+ }
+ else if (led_phase == 400) {
+ leds_turn_off(LED_BLUE);
+ }
+
+ led_phase++;
+
+ if (led_phase >= 800) {
+ led_phase = 0;
+ }
+
+ audio_in_get_buffer(audio_in_buffer);
+ tone_detect_1750(audio_in_buffer, AUDIO_IN_BUF_LEN);
+ }
+}
diff --git a/src/common/src/GPIO/usart.c b/src/common/src/GPIO/usart.c
index 052c546..535b062 100644
--- a/src/common/src/GPIO/usart.c
+++ b/src/common/src/GPIO/usart.c
@@ -99,6 +99,9 @@ void usart_debug(const char *format, ...) {
}
void usart_debug_puts(const char* str) {
+#ifdef SIMULATOR
+ fprintf(stderr, "DEBUG: %s", str);
+#endif
vTaskSuspendAll();
usart_debug_timestamp();
usart_puts(USART2, str);
diff --git a/src/glutt-o-logique/analog_input.c b/src/glutt-o-logique/analog_input.c
index 5f0e700..fb9db48 100644
--- a/src/glutt-o-logique/analog_input.c
+++ b/src/glutt-o-logique/analog_input.c
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
- * Copyright (c) 2016 Matthias P. Braendli, Maximilien Cuony
+ * Copyright (c) 2019 Matthias P. Braendli, Maximilien Cuony
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -30,15 +30,26 @@
#include "Core/delay.h"
#include "Core/common.h"
+#include "stm32f4xx_conf.h"
#include "stm32f4xx_adc.h"
+#include "stm32f4xx_gpio.h"
#include <math.h>
#include "GPIO/usart.h"
+#define PIN_SUPPLY GPIO_Pin_5
+#define PIN_SWR_FWD GPIO_Pin_6
+#define PIN_SWR_REFL GPIO_Pin_7
+
+// see doc/pio.txt for allocation
+#define PINS_ADC1 /* PA pins */ (GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7)
+
+#define ADC1_CHANNEL_SUPPLY ADC_Channel_5
+#define ADC1_CHANNEL_SWR_FWD ADC_Channel_6
+#define ADC1_CHANNEL_SWR_REFL ADC_Channel_7
+
// Measured on the board itself
const float v_ref = 2.965f;
-#warning "TODO: initialise ADC2 and use it for NF input"
-
void analog_init(void)
{
// Enable ADC and GPIOA clocks
@@ -48,7 +59,7 @@ void analog_init(void)
// Set analog input pins mode
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
- GPIO_InitStructure.GPIO_Pin = PINS_ANALOG;
+ GPIO_InitStructure.GPIO_Pin = PINS_ADC1;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
@@ -77,7 +88,7 @@ void analog_init(void)
ADC_Cmd(ADC1, ENABLE);
}
-static uint16_t analog_read_channel(uint8_t channel)
+static uint16_t adc1_read(uint8_t channel)
{
ADC_RegularChannelConfig(ADC1,
channel,
@@ -115,7 +126,7 @@ static uint16_t analog_read_channel(uint8_t channel)
float analog_measure_12v(void)
{
- const uint16_t raw_value = analog_read_channel(ADC_CHANNEL_SUPPLY);
+ const uint16_t raw_value = adc1_read(ADC1_CHANNEL_SUPPLY);
const float adc_max_value = (1 << 12);
@@ -129,8 +140,8 @@ float analog_measure_12v(void)
int analog_measure_swr(int *forward_mv, int* reflected_mv)
{
- const uint16_t raw_swr_fwd_value = analog_read_channel(ADC_CHANNEL_SWR_FWD);
- const uint16_t raw_swr_refl_value = analog_read_channel(ADC_CHANNEL_SWR_REFL);
+ const uint16_t raw_swr_fwd_value = adc1_read(ADC1_CHANNEL_SWR_FWD);
+ const uint16_t raw_swr_refl_value = adc1_read(ADC1_CHANNEL_SWR_REFL);
const float adc_max_value = (1 << 12);
diff --git a/src/glutt-o-logique/analog_input.h b/src/glutt-o-logique/analog_input.h
index 0385ec4..635482f 100644
--- a/src/glutt-o-logique/analog_input.h
+++ b/src/glutt-o-logique/analog_input.h
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
- * Copyright (c) 2016 Matthias P. Braendli, Maximilien Cuony
+ * Copyright (c) 2019 Matthias P. Braendli, Maximilien Cuony
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -24,17 +24,6 @@
#pragma once
-#include "stm32f4xx_conf.h"
-#include "stm32f4xx_gpio.h"
#include "GPIO/analog.h"
-#define PIN_SUPPLY GPIO_Pin_5
-#define PIN_SWR_FWD GPIO_Pin_6
-#define PIN_SWR_REFL GPIO_Pin_7
-
-#define PINS_ANALOG (GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7)
-
-#define ADC_CHANNEL_SUPPLY ADC_Channel_5
-#define ADC_CHANNEL_SWR_FWD ADC_Channel_6
-#define ADC_CHANNEL_SWR_REFL ADC_Channel_7
diff --git a/src/glutt-o-logique/audio_in.c b/src/glutt-o-logique/audio_in.c
new file mode 100644
index 0000000..743c79b
--- /dev/null
+++ b/src/glutt-o-logique/audio_in.c
@@ -0,0 +1,148 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 Matthias P. Braendli, Maximilien Cuony
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+*/
+
+#include "stm32f4xx_conf.h"
+#include "stm32f4xx_gpio.h"
+#include "stm32f4xx_adc.h"
+
+#include "Core/common.h"
+#include "Audio/audio_in.h"
+#include "queue.h"
+
+// APB1 prescaler = 4, see bsp/system_stm32f4xx.c
+#define APB1_FREQ (168000000ul / 4)
+#define ADC2_SAMPLE_FREQ 16000
+#define ADC2_CHANNEL_AUDIO ADC_Channel_14
+
+// see doc/pio.txt for allocation
+#define PINS_ADC2 /* PB1 on ADC2 IN9 */ (GPIO_Pin_1)
+
+#warning "TODO: initialise ADC2 and use it for NF input"
+
+// The TIM6 ISR reads from ADC2 and writes into this buffer
+static int16_t adc2_values[AUDIO_IN_BUF_LEN];
+static int adc2_values_end = 0;
+
+// ADC2 data from interrupt to userspace goes through the queue
+static QueueHandle_t adc2_values_queue;
+
+/* ISR for Timer6 and DAC1&2 underrun */
+void TIM6_DAC_IRQHandler(void)
+{
+ if (TIM_GetITStatus(TIM6, TIM_IT_Update)) {
+ if (ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC) == SET) {
+ uint16_t value = ADC_GetConversionValue(ADC2);
+ /* input range: 0 to 65535
+ * output range: -32768 to 32767 */
+ adc2_values[adc2_values_end++] = (int32_t)value - 32768;
+ if (adc2_values_end == AUDIO_IN_BUF_LEN) {
+ int success = xQueueSendToBackFromISR(
+ adc2_values_queue,
+ adc2_values,
+ NULL);
+
+ adc2_values_end = 0;
+
+ if (success == pdFALSE) {
+ trigger_fault(FAULT_SOURCE_ADC2);
+ }
+ }
+ }
+ else {
+#warning "handle fault"
+ }
+
+ ADC_SoftwareStartConv(ADC2);
+
+ TIM_ClearITPendingBit(TIM6, TIM_IT_Update);
+ }
+}
+
+// Timer6 is used for ADC2 sampling
+static void enable_timer6(void)
+{
+ /* TIM6 Periph clock enable */
+ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
+
+ /* Time base configuration */
+ TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
+ TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
+ TIM_TimeBaseStructure.TIM_Period = (int)(APB1_FREQ/ADC2_SAMPLE_FREQ);
+ TIM_TimeBaseStructure.TIM_Prescaler = 0;
+ TIM_TimeBaseStructure.TIM_ClockDivision = 0;
+ TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
+ TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);
+
+ NVIC_InitTypeDef NVIC_InitStructure;
+ NVIC_InitStructure.NVIC_IRQChannel = TIM6_DAC_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ NVIC_Init(&NVIC_InitStructure);
+
+ TIM_Cmd(TIM6, ENABLE);
+ ADC_SoftwareStartConv(ADC2);
+ TIM_ITConfig(TIM6, TIM_IT_Update, ENABLE);
+}
+
+
+void audio_in_initialize(int rate)
+{
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);
+ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
+
+ GPIO_InitTypeDef GPIO_InitStructure;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
+ GPIO_InitStructure.GPIO_Pin = PINS_ADC2;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_Init(GPIOB, &GPIO_InitStructure);
+
+ // Init ADC2 for NF input
+ ADC_InitTypeDef ADC_InitStruct;
+ ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;
+ ADC_InitStruct.ADC_ScanConvMode = DISABLE;
+ ADC_InitStruct.ADC_ContinuousConvMode = DISABLE;
+ ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
+ ADC_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
+ ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
+ ADC_InitStruct.ADC_NbrOfConversion = 1;
+ ADC_Init(ADC2, &ADC_InitStruct);
+
+ ADC_Cmd(ADC2, ENABLE);
+
+ adc2_values_queue = xQueueCreate(4, AUDIO_IN_BUF_LEN);
+ if (adc2_values_queue == 0) {
+ while(1); /* fatal error */
+ }
+
+ enable_timer6();
+}
+
+void audio_in_get_buffer(int16_t *buffer /*of length AUDIO_IN_BUF_LEN*/ )
+{
+ while (!xQueueReceive(adc2_values_queue, buffer, portMAX_DELAY)) {}
+}
+
diff --git a/src/glutt-o-logique/pio.c b/src/glutt-o-logique/pio.c
index e944671..1069886 100644
--- a/src/glutt-o-logique/pio.c
+++ b/src/glutt-o-logique/pio.c
@@ -304,7 +304,7 @@ void pio_set_mod_off(int mod_off)
}
int pio_read_button() {
- return GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == Bit_SET;
+ return GPIO_ReadInputDataBit(GPIOA,GPIOA_PIN_PUSHBTN) == Bit_SET;
}
void pio_set_gps_epps(int on)
diff --git a/src/glutt-o-logique/stm32f4discovery-with-stlinkv2.1.cfg b/src/glutt-o-logique/stm32f4discovery-with-stlinkv2.1.cfg
new file mode 100644
index 0000000..18369f5
--- /dev/null
+++ b/src/glutt-o-logique/stm32f4discovery-with-stlinkv2.1.cfg
@@ -0,0 +1,10 @@
+# This is an STM32F4 discovery board with a single STM32F407VGT6 chip.
+# http://www.st.com/internet/evalboard/product/252419.jsp
+
+source [find interface/stlink-v2-1.cfg]
+
+transport select hla_swd
+
+source [find target/stm32f4x.cfg]
+
+reset_config srst_only
diff --git a/src/simulator/src/Audio/audio.c b/src/simulator/src/Audio/audio.c
index 31f4c98..ab9773a 100644
--- a/src/simulator/src/Audio/audio.c
+++ b/src/simulator/src/Audio/audio.c
@@ -48,15 +48,19 @@ void audio_initialize_platform(int __attribute__ ((unused))plln, int __attribute
ss.rate = rate;
+ fprintf(stderr, "Pulseaudio out init\n");
s = pa_simple_new(NULL, "Glutte", PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error);
+ fprintf(stderr, "Pulseaudio %p\n", s);
if (!s) {
- printf("Pulseaudio playback init error\n");
+ fprintf(stderr, "Pulseaudio playback init error\n");
while(1);
}
+
TaskHandle_t task_handle;
+ fprintf(stderr, "Pulseaudio task\n");
xTaskCreate(
audio_buffer_sender,
"Audio buffer sender",
@@ -64,7 +68,7 @@ void audio_initialize_platform(int __attribute__ ((unused))plln, int __attribute
(void*) NULL,
tskIDLE_PRIORITY + 2UL,
&task_handle);
-
+ fprintf(stderr, "Pulseaudio buffer sender created\n");
}
static void audio_buffer_sender(void __attribute__ ((unused)) *args) {
diff --git a/src/simulator/src/Audio/audio_in.c b/src/simulator/src/Audio/audio_in.c
index 936fe1c..d17e8bc 100644
--- a/src/simulator/src/Audio/audio_in.c
+++ b/src/simulator/src/Audio/audio_in.c
@@ -26,15 +26,31 @@
#include <assert.h>
#include <pulse/simple.h>
#include "Audio/audio_in.h"
+#include "Audio/tone.h"
#include "FreeRTOS.h"
#include "task.h"
+#include "queue.h"
pa_simple *s_in = NULL;
+static QueueHandle_t adc2_values_queue;
-static void audio_buffer_reader(void *args);
+static void audio_buffer_reader(void __attribute__((unused))*args)
+{
+ while (1) {
+ int16_t buffer[AUDIO_IN_BUF_LEN];
+ pa_simple_read(s_in, buffer, AUDIO_IN_BUF_LEN * sizeof(int16_t), NULL);
+ int success = xQueueSendToBack(
+ adc2_values_queue,
+ buffer,
+ portMAX_DELAY);
+ assert(success);
+ taskYIELD();
+ }
+}
-void audio_in_initialize_plateform(int rate) {
+
+void audio_in_initialize(int rate) {
int error;
static pa_sample_spec ss = {
@@ -46,9 +62,11 @@ void audio_in_initialize_plateform(int rate) {
ss.rate = rate;
s_in = pa_simple_new(NULL, "GlutteR", PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error);
-
assert(s_in);
+ adc2_values_queue = xQueueCreate(4, AUDIO_IN_BUF_LEN);
+ assert(adc2_values_queue);
+
TaskHandle_t task_handle;
xTaskCreate(
audio_buffer_reader,
@@ -59,13 +77,8 @@ void audio_in_initialize_plateform(int rate) {
&task_handle);
}
-static void audio_buffer_reader(void __attribute__ ((unused)) *args) {
-
- while(1) {
- pa_simple_read(s_in, audio_in_buffer, AUDIO_IN_BUF_LEN * 2, NULL);
- audio_in_buffer_ready();
-
- taskYIELD();
- }
-
+void audio_in_get_buffer(int16_t *buffer /*of length AUDIO_IN_BUF_LEN*/ )
+{
+ while (!xQueueReceive(adc2_values_queue, buffer, portMAX_DELAY)) {}
}
+
diff --git a/src/simulator/src/Gui/gui.c b/src/simulator/src/Gui/gui.c
index fd4fe7a..f6f9ab9 100644
--- a/src/simulator/src/Gui/gui.c
+++ b/src/simulator/src/Gui/gui.c
@@ -152,6 +152,7 @@ int gui_in_sq_n = 1;
int gui_in_u = 0;
int gui_in_d = 0;
int gui_in_replie = 0;
+int gui_in_tone_1750 = 0;
static const char *replie_status[] = {"In vent", "RepliƩ"};
int gui_in_fax_n = 1;
@@ -163,8 +164,6 @@ int in_u = 0;
int in_d = 0;
int in_fax_n = 1;
-extern int TONE_1750_DETECTED;
-
/**
* FSM
@@ -821,7 +820,7 @@ void main_gui() {
nk_property_float(ctx, "V", 0.0f, &gui_measured_voltage, 24.0f, 0.5f, 0.5f);
- if (TONE_1750_DETECTED) {
+ if (gui_in_tone_1750) {
c = color_on;
} else {
c = color_off;
diff --git a/src/simulator/src/Gui/nuklear.h b/src/simulator/src/Gui/nuklear.h
index 5602251..3d10c4a 100644
--- a/src/simulator/src/Gui/nuklear.h
+++ b/src/simulator/src/Gui/nuklear.h
@@ -13625,7 +13625,7 @@ nk_do_color_picker(nk_flags *state,
* ===============================================================*/
NK_API void nk_style_default(struct nk_context *ctx){nk_style_from_table(ctx, 0);}
#define NK_COLOR_MAP(NK_COLOR)\
- NK_COLOR(NK_COLOR_TEXT, 175,175,175,255) \
+ NK_COLOR(NK_COLOR_TEXT, 255,255,255,255) \
NK_COLOR(NK_COLOR_WINDOW, 45, 45, 45, 255) \
NK_COLOR(NK_COLOR_HEADER, 40, 40, 40, 255) \
NK_COLOR(NK_COLOR_BORDER, 65, 65, 65, 255) \
diff --git a/src/tone-test-sim/analyse.py b/src/tone-test-sim/analyse.py
index 8222213..b1b0649 100755
--- a/src/tone-test-sim/analyse.py
+++ b/src/tone-test-sim/analyse.py
@@ -4,10 +4,12 @@ import numpy as np
import matplotlib.pyplot as plt
dat = np.loadtxt("tone.csv", dtype=np.int32, delimiter=",")
-# columns :"freq, threshold, num_samples, detector_output"
+# columns :"freq, threshold, num_samples, detector_output, avg_rms"
fig, ax = plt.subplots()
-plt.scatter(dat[...,0], dat[...,1], c=dat[...,3].astype(np.float32))
+plt.scatter(dat[...,0], dat[...,1] / dat[...,4], c=dat[...,3].astype(np.float32))
+plt.xlabel("freq")
+plt.ylabel("threshold over rms")
plt.show()
if 0:
diff --git a/src/tone-test-sim/src/test.c b/src/tone-test-sim/src/test.c
index 3bff6d7..716b7ae 100644
--- a/src/tone-test-sim/src/test.c
+++ b/src/tone-test-sim/src/test.c
@@ -33,7 +33,7 @@ int main(int argc, char **argv)
{
printf("Hello, ver %s\n", vc_get_version());
printf("Saving results to tone.csv\n");
- printf("freq, threshold, num_samples, detector_output\n");
+ printf("freq, threshold, num_samples, detector_output, avg_rms\n");
FILE *fd = fopen("tone.csv", "w");
if (!fd) {
@@ -48,12 +48,19 @@ int main(int argc, char **argv)
for (int threshold = 100000; threshold < 4000000; threshold += 100000) {
tone_init(threshold);
- for (size_t j = 0; j < 200; j++) {
- float samplef = cosf(j * 2.0f * FLOAT_PI * freq / AUDIO_IN_RATE);
- int16_t sample = samplef * 32767.0f;
+ double accu = 0;
+
+ for (size_t j = 0; j < 100; j++) {
+ const float samplef = cosf(j * 2.0f * FLOAT_PI * freq / AUDIO_IN_RATE);
+ const float noisef = (drand48() * 2.0f) - 1;
+ int16_t sample = (0.9f * samplef + 0.1f * noisef) * 32767.0f;
+
+ accu += (sample * sample);
+
int r = tone_detect_1750(sample);
if (r != -1) {
- fprintf(fd, "%d,%d,%zu,%d\n",freq, threshold, j, r);
+ const double rms = sqrt(accu / (double)j);
+ fprintf(fd, "%d,%d,%zu,%d,%f\n",freq, threshold, j, r, rms);
}
}
}