<commit_before>/*
 * Copyright (c) 2018 STMicroelectronics
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <string.h>
#include <zephyr.h>
#include <misc/printk.h>

#include <gpio.h>
#include <led.h>

#include <audio/dmic.h>

/* uncomment if you want PCM output in ascii */
/*#define PCM_OUTPUT_IN_ASCII		1  */

#define AUDIO_FREQ		16000
#define CHAN_SIZE		16
#define PCM_BLK_SIZE_MS		((AUDIO_FREQ/1000) * sizeof(s16_t))

#define NUM_MS		5000

K_MEM_SLAB_DEFINE(rx_mem_slab, PCM_BLK_SIZE_MS, NUM_MS, 1);

struct pcm_stream_cfg mic_streams = {
	.pcm_rate = AUDIO_FREQ,
	.pcm_width = CHAN_SIZE,
	.block_size = PCM_BLK_SIZE_MS,
	.mem_slab = &rx_mem_slab,
};

struct dmic_cfg cfg = {
	.io = {
		/* requesting a pdm freq around 2MHz */
		.min_pdm_clk_freq = 1800000,
		.max_pdm_clk_freq = 2500000,
	},
	.streams = &mic_streams,
	.channel = {
		.req_num_chan = 1,
	},
};

#define NUM_LEDS 12
#define DELAY_TIME K_MSEC(25)

void signal_sampling_started(void)
{
	static struct device *led0, *led1;

	led0 = device_get_binding(LED0_GPIO_CONTROLLER);
	gpio_pin_configure(led0, LED0_GPIO_PIN, GPIO_DIR_OUT);
	gpio_pin_write(led0, LED0_GPIO_PIN, 1);

	led1 = device_get_binding(LED1_GPIO_CONTROLLER);
	gpio_pin_configure(led1, LED1_GPIO_PIN, GPIO_DIR_OUT);
	gpio_pin_write(led1, LED1_GPIO_PIN, 0);
}

void signal_sampling_stopped(void)
{
	static struct device *led0, *led1;

	led0 = device_get_binding(LED0_GPIO_CONTROLLER);
	gpio_pin_configure(led0, LED0_GPIO_PIN, GPIO_DIR_OUT);
	gpio_pin_write(led0, LED0_GPIO_PIN, 1);

	led1 = device_get_binding(LED1_GPIO_CONTROLLER);
	gpio_pin_configure(led1, LED1_GPIO_PIN, GPIO_DIR_OUT);
	gpio_pin_write(led1, LED1_GPIO_PIN, 1);
}

void signal_print_stopped(void)
{
	static struct device *led0, *led1;

	led0 = device_get_binding(LED0_GPIO_CONTROLLER);
	gpio_pin_configure(led0, LED0_GPIO_PIN, GPIO_DIR_OUT);
	gpio_pin_write(led0, LED0_GPIO_PIN, 0);

	led1 = device_get_binding(LED1_GPIO_CONTROLLER);
	gpio_pin_configure(led1, LED1_GPIO_PIN, GPIO_DIR_OUT);
	gpio_pin_write(led1, LED1_GPIO_PIN, 1);
}

void *rx_block[NUM_MS];
size_t rx_size = PCM_BLK_SIZE_MS;

void main(void)
{
	int i;
	u32_t ms;

#ifdef CONFIG_LP3943
	static struct device *ledc;

	ledc = device_get_binding(DT_TI_LP3943_0_LABEL);
	if (!ledc) {
		printk("Could not get pointer to %s sensor\n",
			DT_TI_LP3943_0_LABEL);
		return;
	}

	/* turn all leds on */
	for (i = 0; i < NUM_LEDS; i++) {
		led_on(ledc, i);
		k_sleep(DELAY_TIME);
	}

	/* turn all leds off */
	for (i = 0; i < NUM_LEDS; i++) {
		led_off(ledc, i);
		k_sleep(DELAY_TIME);
	}

#endif

	printk("ArgonKey test!!\n");

	int ret;

	struct device *mic_dev = device_get_binding(DT_ST_MPXXDTYY_0_LABEL);

	if (!mic_dev) {
		printk("Could not get pointer to %s device\n",
			DT_ST_MPXXDTYY_0_LABEL);
		return;
	}

	ret = dmic_configure(mic_dev, &cfg);
	if (ret < 0) {
		printk("microphone configuration error\n");
		return;
	}

	ret = dmic_trigger(mic_dev, DMIC_TRIGGER_START);
	if (ret < 0) {
		printk("microphone start trigger error\n");
		return;
	}

	signal_sampling_started();

	/* Acquire microphone audio */
	for (ms = 0; ms < NUM_MS; ms++) {
		dmic_read(mic_dev, 0, &rx_block[ms], &rx_size, 2000);
		if (ret < 0) {
			printk("microphone audio read error\n");
			return;
		}
	}
<commit_msg>samples/96b_argonkey: microphone: Fix coverity bug 190958<commit_after>/*
 * Copyright (c) 2018 STMicroelectronics
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <string.h>
#include <zephyr.h>
#include <misc/printk.h>

#include <gpio.h>
#include <led.h>

#include <audio/dmic.h>

/* uncomment if you want PCM output in ascii */
/*#define PCM_OUTPUT_IN_ASCII		1  */

#define AUDIO_FREQ		16000
#define CHAN_SIZE		16
#define PCM_BLK_SIZE_MS		((AUDIO_FREQ/1000) * sizeof(s16_t))

#define NUM_MS		5000

K_MEM_SLAB_DEFINE(rx_mem_slab, PCM_BLK_SIZE_MS, NUM_MS, 1);

struct pcm_stream_cfg mic_streams = {
	.pcm_rate = AUDIO_FREQ,
	.pcm_width = CHAN_SIZE,
	.block_size = PCM_BLK_SIZE_MS,
	.mem_slab = &rx_mem_slab,
};

struct dmic_cfg cfg = {
	.io = {
		/* requesting a pdm freq around 2MHz */
		.min_pdm_clk_freq = 1800000,
		.max_pdm_clk_freq = 2500000,
	},
	.streams = &mic_streams,
	.channel = {
		.req_num_chan = 1,
	},
};

#define NUM_LEDS 12
#define DELAY_TIME K_MSEC(25)

void signal_sampling_started(void)
{
	static struct device *led0, *led1;

	led0 = device_get_binding(LED0_GPIO_CONTROLLER);
	gpio_pin_configure(led0, LED0_GPIO_PIN, GPIO_DIR_OUT);
	gpio_pin_write(led0, LED0_GPIO_PIN, 1);

	led1 = device_get_binding(LED1_GPIO_CONTROLLER);
	gpio_pin_configure(led1, LED1_GPIO_PIN, GPIO_DIR_OUT);
	gpio_pin_write(led1, LED1_GPIO_PIN, 0);
}

void signal_sampling_stopped(void)
{
	static struct device *led0, *led1;

	led0 = device_get_binding(LED0_GPIO_CONTROLLER);
	gpio_pin_configure(led0, LED0_GPIO_PIN, GPIO_DIR_OUT);
	gpio_pin_write(led0, LED0_GPIO_PIN, 1);

	led1 = device_get_binding(LED1_GPIO_CONTROLLER);
	gpio_pin_configure(led1, LED1_GPIO_PIN, GPIO_DIR_OUT);
	gpio_pin_write(led1, LED1_GPIO_PIN, 1);
}

void signal_print_stopped(void)
{
	static struct device *led0, *led1;

	led0 = device_get_binding(LED0_GPIO_CONTROLLER);
	gpio_pin_configure(led0, LED0_GPIO_PIN, GPIO_DIR_OUT);
	gpio_pin_write(led0, LED0_GPIO_PIN, 0);

	led1 = device_get_binding(LED1_GPIO_CONTROLLER);
	gpio_pin_configure(led1, LED1_GPIO_PIN, GPIO_DIR_OUT);
	gpio_pin_write(led1, LED1_GPIO_PIN, 1);
}

void *rx_block[NUM_MS];
size_t rx_size = PCM_BLK_SIZE_MS;

void main(void)
{
	int i;
	u32_t ms;

#ifdef CONFIG_LP3943
	static struct device *ledc;

	ledc = device_get_binding(DT_TI_LP3943_0_LABEL);
	if (!ledc) {
		printk("Could not get pointer to %s sensor\n",
			DT_TI_LP3943_0_LABEL);
		return;
	}

	/* turn all leds on */
	for (i = 0; i < NUM_LEDS; i++) {
		led_on(ledc, i);
		k_sleep(DELAY_TIME);
	}

	/* turn all leds off */
	for (i = 0; i < NUM_LEDS; i++) {
		led_off(ledc, i);
		k_sleep(DELAY_TIME);
	}

#endif

	printk("ArgonKey test!!\n");

	int ret;

	struct device *mic_dev = device_get_binding(DT_ST_MPXXDTYY_0_LABEL);

	if (!mic_dev) {
		printk("Could not get pointer to %s device\n",
			DT_ST_MPXXDTYY_0_LABEL);
		return;
	}

	ret = dmic_configure(mic_dev, &cfg);
	if (ret < 0) {
		printk("microphone configuration error\n");
		return;
	}

	ret = dmic_trigger(mic_dev, DMIC_TRIGGER_START);
	if (ret < 0) {
		printk("microphone start trigger error\n");
		return;
	}

	signal_sampling_started();

	/* Acquire microphone audio */
	for (ms = 0; ms < NUM_MS; ms++) {
		ret = dmic_read(mic_dev, 0, &rx_block[ms], &rx_size, 2000);
		if (ret < 0) {
			printk("microphone audio read error\n");
			return;
		}
	}

{'fraction_non_alphanumeric': 0.1248097412480974, 'fraction_numerical': 0.038356164383561646, 'mean_word_length': 4.979071883530482, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '365191', 'n_tokens_mistral': 3114, 'n_tokens_neox': 2866, 'n_words': 550}