<commit_before>/* nrf51-pm.c Power Management for nrf51 chip */

/*
 * Copyright (c) 2016 Intel Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */

#include <gpio.h>

#include <bluetooth/log.h>
#include <errno.h>

#define NBLE_SWDIO_PIN	6
#define NBLE_RESET_PIN	NBLE_SWDIO_PIN
#define NBLE_BTWAKE_PIN 5

static struct device *nrf51_gpio;

int nrf51_enable(void)
{
	return gpio_pin_write(nrf51_gpio, NBLE_BTWAKE_PIN, 1);
}

int nrf51_disable(void)
{
	return gpio_pin_write(nrf51_gpio, NBLE_BTWAKE_PIN, 0);
}

static inline void sleep_ms(unsigned int ms)
{
	switch (sys_execution_context_type_get()) {
	case NANO_CTX_FIBER:
		fiber_sleep(MSEC(ms));
		return;
	case NANO_CTX_TASK:
		task_sleep(MSEC(ms));
		return;
	default:
		BT_ERR("ISR context is not supported");
		return;
	}
}

int nrf51_init(void)
{
	int ret;

	nrf51_gpio = device_get_binding(CONFIG_GPIO_DW_0_NAME);
	if (!nrf51_gpio) {
		BT_ERR("Cannot find %s", CONFIG_GPIO_DW_0_NAME);
		return -ENODEV;
	}

	ret = gpio_pin_configure(nrf51_gpio, NBLE_RESET_PIN, GPIO_DIR_OUT);
	if (ret) {
		BT_ERR("Error configuring pin %d", NBLE_RESET_PIN);
		return -ENODEV;
	}

	/* Reset hold time is 0.2us (normal) or 100us (SWD debug) */
	ret = gpio_pin_write(nrf51_gpio, NBLE_RESET_PIN, 0);
	if (ret) {
		BT_ERR("Error pin write %d", NBLE_RESET_PIN);
		return -EINVAL;
	}

	/**
	 * NBLE reset is achieved by asserting low the SWDIO pin.
	 * However, the BLE Core chip can be in SWD debug mode,<commit_msg>nble: Use string name for GPIO driver<commit_after>/* nrf51-pm.c Power Management for nrf51 chip */

/*
 * Copyright (c) 2016 Intel Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */

#include <gpio.h>

#include <bluetooth/log.h>
#include <errno.h>

#define NBLE_SWDIO_PIN	6
#define NBLE_RESET_PIN	NBLE_SWDIO_PIN
#define NBLE_BTWAKE_PIN 5

static struct device *nrf51_gpio;

int nrf51_enable(void)
{
	return gpio_pin_write(nrf51_gpio, NBLE_BTWAKE_PIN, 1);
}

int nrf51_disable(void)
{
	return gpio_pin_write(nrf51_gpio, NBLE_BTWAKE_PIN, 0);
}

static inline void sleep_ms(unsigned int ms)
{
	switch (sys_execution_context_type_get()) {
	case NANO_CTX_FIBER:
		fiber_sleep(MSEC(ms));
		return;
	case NANO_CTX_TASK:
		task_sleep(MSEC(ms));
		return;
	default:
		BT_ERR("ISR context is not supported");
		return;
	}
}

int nrf51_init(void)
{
	int ret;

	nrf51_gpio = device_get_binding("GPIO_0");
	if (!nrf51_gpio) {
		BT_ERR("Cannot find GPIO_0");
		return -ENODEV;
	}

	ret = gpio_pin_configure(nrf51_gpio, NBLE_RESET_PIN, GPIO_DIR_OUT);
	if (ret) {
		BT_ERR("Error configuring pin %d", NBLE_RESET_PIN);
		return -ENODEV;
	}

	/* Reset hold time is 0.2us (normal) or 100us (SWD debug) */
	ret = gpio_pin_write(nrf51_gpio, NBLE_RESET_PIN, 0);
	if (ret) {
		BT_ERR("Error pin write %d", NBLE_RESET_PIN);
		return -EINVAL;
	}

	/**
	 * NBLE reset is achieved by asserting low the SWDIO pin.
	 * However, the BLE Core chip can be in SWD debug mode,
{'fraction_non_alphanumeric': 0.09974619289340102, 'fraction_numerical': 0.02233502538071066, 'mean_word_length': 4.413461538461538, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6316692', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1435, 'n_words': 434}