Files
microchip-application-bmd38…/main.c
T
2023-05-06 15:50:29 +08:00

118 lines
2.6 KiB
C

#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include "app_config.h"
#include "apply_old_config.h"
#include "sdk_config.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_freertos.h"
#include "FreeRTOS.h"
#include "task.h"
#ifdef __cplusplus
}
#endif
#define APP_BLE_CONN_CFG_TAG 1 /**< A tag identifying the SoftDevice BLE configuration. */
#define APP_BLE_OBSERVER_PRIO 3 /**< Application's BLE observer priority. You shouldn't need to modify this value. */
static void le_evt_handler(ble_evt_t const *p_ble_evt, void *p_context)
{
// TODO...
}
static void le_stack_Init(void)
{
ret_code_t err_code;
uint32_t ram_start = 0;
ble_cfg_t ble_cfg;
memset(&ble_cfg, 0x00, sizeof(ble_cfg));
ble_cfg.conn_cfg.conn_cfg_tag = APP_BLE_CONN_CFG_TAG;
ble_cfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = 8;
err_code = nrf_sdh_enable_request();
APP_ERROR_CHECK(err_code);
// Configure the BLE stack using the default settings.
// Fetch the start address of the application RAM.
err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
APP_ERROR_CHECK(err_code);
err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &ble_cfg, ram_start);
APP_ERROR_CHECK(err_code);
// Enable BLE stack.
err_code = nrf_sdh_ble_enable(&ram_start);
APP_ERROR_CHECK(err_code);
// Register a handler for BLE events.
NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, le_evt_handler, NULL);
}
void led1_task(void *pArg)
{
nrf_gpio_cfg_output(13);
for (;;)
{
NRF_LOG_INFO("led 1 off");
nrf_gpio_pin_set(13);
vTaskDelay(500);
NRF_LOG_INFO("led 1 on");
nrf_gpio_pin_clear(13);
vTaskDelay(500);
}
}
void led2_task(void *pArg)
{
nrf_gpio_cfg_output(14);
for (;;)
{
NRF_LOG_INFO("led 2 off");
nrf_gpio_pin_set(14);
vTaskDelay(125);
NRF_LOG_INFO("led 2 on");
nrf_gpio_pin_clear(14);
vTaskDelay(125);
}
}
int main(void)
{
NRF_LOG_INIT(NULL, 0);
NRF_LOG_DEFAULT_BACKENDS_INIT();
NRF_LOG_INFO("%s Build: %s %s", DEVICE_NAME, __TIME__, __DATE__);
le_stack_Init();
nrf_sdh_freertos_init(NULL, NULL);
xTaskCreate(led1_task, "led1_task", 160, NULL, 3, NULL);
xTaskCreate(led2_task, "led2_task", 160, NULL, 3, NULL);
vTaskStartScheduler();
for (;;)
{
__BKPT(255);
}
}