代码拉取完成,页面将自动刷新
/*
* INCLUDE FILES
****************************************************************************************
*/
#include <stdio.h>
#include <string.h>
#include "gap_api.h"
#include "gatt_api.h"
#include "os_timer.h"
#include "os_mem.h"
#include "sys_utils.h"
#include "button.h"
#include "jump_table.h"
#include "user_task.h"
#include "driver_plf.h"
#include "driver_system.h"
#include "driver_i2s.h"
#include "driver_pmu.h"
#include "driver_uart.h"
#include "driver_rtc.h"
#include "driver_flash.h"
#include "driver_efuse.h"
#include "flash_usage_config.h"
#include "ble_simple_peripheral.h"
#include "simple_gatt_service.h"
/*
* LOCAL VARIABLES
*/
const struct jump_table_version_t _jump_table_version __attribute__((section("jump_table_3"))) =
{
.firmware_version = 0x00000000,
};
const struct jump_table_image_t _jump_table_image __attribute__((section("jump_table_1"))) =
{
.image_type = IMAGE_TYPE_APP,
.image_size = 0x19000,
};
__attribute__((section("ram_code"))) void pmu_gpio_isr_ram(void)
{
uint32_t gpio_value = ool_read32(PMU_REG_GPIOA_V);
button_toggle_detected(gpio_value);
ool_write32(PMU_REG_PORTA_LAST, gpio_value);
}
/*********************************************************************
* @fn user_custom_parameters
*
* @brief initialize several parameters, this function will be called
* at the beginning of the program.
*
* @param None.
*
*
* @return None.
*/
void user_custom_parameters(void)
{
struct chip_unique_id_t id_data;
efuse_get_chip_unique_id(&id_data);
__jump_table.addr.addr[0] = 0xBD;
__jump_table.addr.addr[1] = 0xAD;
__jump_table.addr.addr[2] = 0xD0;
__jump_table.addr.addr[3] = 0xF0;
__jump_table.addr.addr[4] = 0x17;
__jump_table.addr.addr[5] = 0x20;
id_data.unique_id[5] |= 0xc0; // random addr->static addr type:the top two bit must be 1.
memcpy(__jump_table.addr.addr,id_data.unique_id,6);
__jump_table.system_clk = SYSTEM_SYS_CLK_48M;
jump_table_set_static_keys_store_offset(JUMP_TABLE_STATIC_KEY_OFFSET);
ble_set_addr_type(BLE_ADDR_TYPE_PUBLIC);
retry_handshake();
}
/*********************************************************************
* @fn user_entry_before_sleep_imp
*
* @brief Before system goes to sleep mode, user_entry_before_sleep_imp()
* will be called, MCU peripherals can be configured properly before
* system goes to sleep, for example, some MCU peripherals need to be
* used during the system is in sleep mode.
*
* @param None.
*
*
* @return None.
*/
__attribute__((section("ram_code"))) void user_entry_before_sleep_imp(void)
{
uart_putc_noint_no_wait(UART1, 's');
}
/*********************************************************************
* @fn user_entry_after_sleep_imp
*
* @brief After system wakes up from sleep mode, user_entry_after_sleep_imp()
* will be called, MCU peripherals need to be initialized again,
* this can be done in user_entry_after_sleep_imp(). MCU peripherals
* status will not be kept during the sleep.
*
* @param None.
*
*
* @return None.
*/
__attribute__((section("ram_code"))) void user_entry_after_sleep_imp(void)
{
/* set PA2 and PA3 for AT command interface */
//system_set_port_pull(GPIO_PA2, true);
//system_set_port_mux(GPIO_PORT_A, GPIO_BIT_2, PORTA2_FUNC_UART1_RXD);
system_set_port_mux(GPIO_PORT_A, GPIO_BIT_3, PORTA3_FUNC_UART1_TXD);
uart_init(UART1, BAUD_RATE_115200);
//NVIC_EnableIRQ(UART1_IRQn);
uart_putc_noint_no_wait(UART1, 'w');
// Do some things here, can be uart print
NVIC_EnableIRQ(PMU_IRQn);
}
/*********************************************************************
* @fn user_entry_before_ble_init
*
* @brief Code to be executed before BLE stack to be initialized.
* Power mode configurations, PMU part driver interrupt enable, MCU
* peripherals init, etc.
*
* @param None.
*
*
* @return None.
*/
void user_entry_before_ble_init(void)
{
/* set system power supply in BUCK mode */
pmu_set_sys_power_mode(PMU_SYS_POW_BUCK);
#ifdef FLASH_PROTECT
flash_protect_enable(1);
#endif
pmu_enable_irq(PMU_ISR_BIT_ACOK
| PMU_ISR_BIT_ACOFF
| PMU_ISR_BIT_ONKEY_PO
| PMU_ISR_BIT_OTP
| PMU_ISR_BIT_LVD
| PMU_ISR_BIT_BAT
| PMU_ISR_BIT_ONKEY_HIGH);
NVIC_EnableIRQ(PMU_IRQn);
// Enable UART print.
//system_set_port_pull(GPIO_PA2, true);
//system_set_port_mux(GPIO_PORT_A, GPIO_BIT_2, PORTA2_FUNC_UART1_RXD);
system_set_port_mux(GPIO_PORT_A, GPIO_BIT_3, PORTA3_FUNC_UART1_TXD);
uart_init(UART1, BAUD_RATE_115200);
}
/*********************************************************************
* @fn user_entry_after_ble_init
*
* @brief Main entrancy of user application. This function is called after BLE stack
* is initialized, and all the application code will be executed from here.
* In that case, application layer initializtion can be startd here.
*
* @param None.
*
*
* @return None.
*/
void user_entry_after_ble_init(void)
{
co_printf("BLE Peripheral\r\n");
#if 1
system_sleep_disable(); //disable sleep
#else
if(__jump_table.system_option & SYSTEM_OPTION_SLEEP_ENABLE) //if sleep is enalbed, delay 3s for JLINK
{
co_printf("\r\na");
co_delay_100us(10000);
co_printf("\r\nb");
co_delay_100us(10000);
co_printf("\r\nc");
co_delay_100us(10000);
co_printf("\r\nd");
}
#endif
// User task initialization, for buttons.
user_task_init();
// Application layer initialization, can included bond manager init,
// advertising parameters init, scanning parameter init, GATT service adding, etc.
simple_peripheral_init();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。