MXC-A36-Demo/MCU/examples/application/ble_simple_periphreal/Src/app_btdm.c

108 lines
2.7 KiB
C
Raw Permalink Normal View History

#include "app_config.h"
#include "app_task.h"
#include "app_btdm.h"
#include "app_ble.h"
#include "controller.h"
#include "host.h"
typedef int32_t app_btdm_ret_t;
static const uint8_t bt_addr[] = {0x12, 0x00, 0x12, 0x12, 0x12, 0x12};
static const uint8_t ble_public_addr[] = {0x13, 0x00, 0x12, 0x12, 0x12, 0x12};
static const uint8_t ble_static_addr[] = {0x13, 0x00, 0x12, 0x12, 0x12, 0xc2};
void app_btdm_start(void)
{
app_ble_init();
}
void host_ready_cb(void)
{
struct app_task_event *event;
/* notify application BTDM stack is ready. */
event = app_task_event_alloc(APP_TASK_EVENT_HOST_INITED, 0, true);
app_task_event_post(event, false);
}
void app_btdm_init(void)
{
/* prepare for BTDM stack */
#if defined(__CC_ARM) || defined(__ARMCC_VERSION)
extern uint8_t CONTROLLER_CODE_OTA_BASE;
uint32_t controller_code_base_addr = (uint32_t)&CONTROLLER_CODE_OTA_BASE;
controller_start(BTDM_STACK_HCI_BAUDRATE, ble_public_addr, bt_addr, controller_code_base_addr);
#elif defined(__GNUC__) || defined(__ICCARM__)
extern const uint8_t controller_code_buffer[];
controller_start(BTDM_STACK_HCI_BAUDRATE, ble_public_addr, bt_addr, (uint32_t)&controller_code_buffer[0]);
#else
#error "not supported platform"
#endif
host_ble_start(BTDM_STACK_HCI_BAUDRATE, HOST_TASK_STACK_SIZE, HOST_TASK_PRIORITY, ble_static_addr);
/*
* init MCU->BT pin, configure PMU_PIN_8 output BBG_EN signal, this pin is used to
* notice BT core that MCU is in working mode.
*/
ool_write(PMU_REG_DIAG_CTRL, 0x82);
ool_write(PMU_REG_PIN_IOMUX_H, 0x03);
/* disable PMU pin input as default setting */
ool_write16(PMU_REG_PIN_INPUT_EN, 0x0002);
/*
* init BT->MCU pin, system should not enter sleep mode when this pin is low level.
* This pin is used by BT core to notice MCU than BT core is in working mode.
*/
system_prevent_sleep_set(SYSTEM_PREVENT_SLEEP_TYPE_HCI_RX);
pmu_gpio_int_init(PMU_PIN_9, PMU_GPIO_PULL_UP, 0);
pmu_enable_isr(PMU_GPIO_PMU_INT_MSK_BIT);
NVIC_SetPriority(PMU_IRQn, 4);
NVIC_EnableIRQ(PMU_IRQn);
}
app_btdm_ret_t app_btdm_ble_adv_start(uint16_t dur)
{
return -1;
}
app_btdm_ret_t app_btdm_ble_adv_stop(void)
{
return -1;
}
app_btdm_ret_t app_btdm_ble_disconnect(void)
{
return -1;
}
app_btdm_ret_t app_btdm_bt_access_mode_set(uint8_t mode)
{
return -1;
}
app_btdm_ret_t app_btdm_bt_scan_start(uint16_t dur)
{
return -1;
}
app_btdm_ret_t app_btdm_bt_scan_stop(void)
{
return -1;
}
app_btdm_ret_t app_btdm_bt_connect(uint8_t *peer_addr)
{
return -1;
}
app_btdm_ret_t app_btdm_bt_disconnect(void)
{
return -1;
}
app_btdm_ret_t app_btdm_bt_profile_enable(uint16_t profiles)
{
return -1;
}