From a327efd414deb43205cd00d78edc8d6ce0d1a897 Mon Sep 17 00:00:00 2001 From: shchen Date: Wed, 23 Dec 2020 16:31:47 +0800 Subject: [PATCH] ble demo --- customer_app/sdk_app_bledemo/Makefile | 40 ++ customer_app/sdk_app_bledemo/README.md | 52 ++ customer_app/sdk_app_bledemo/genromap | 3 + customer_app/sdk_app_bledemo/logo.png | Bin 0 -> 17129 bytes customer_app/sdk_app_bledemo/proj_config.mk | 56 ++ .../sdk_app_bledemo/sdk_app_bledemo/ble_app.h | 73 +++ .../sdk_app_bledemo/ble_appc.c | 332 ++++++++++++ .../sdk_app_bledemo/ble_apps.c | 354 ++++++++++++ .../sdk_app_bledemo/bouffalo.mk | 26 + .../sdk_app_bledemo/sdk_app_bledemo/main.c | 509 ++++++++++++++++++ 10 files changed, 1445 insertions(+) create mode 100644 customer_app/sdk_app_bledemo/Makefile create mode 100644 customer_app/sdk_app_bledemo/README.md create mode 100644 customer_app/sdk_app_bledemo/genromap create mode 100644 customer_app/sdk_app_bledemo/logo.png create mode 100644 customer_app/sdk_app_bledemo/proj_config.mk create mode 100644 customer_app/sdk_app_bledemo/sdk_app_bledemo/ble_app.h create mode 100644 customer_app/sdk_app_bledemo/sdk_app_bledemo/ble_appc.c create mode 100644 customer_app/sdk_app_bledemo/sdk_app_bledemo/ble_apps.c create mode 100644 customer_app/sdk_app_bledemo/sdk_app_bledemo/bouffalo.mk create mode 100644 customer_app/sdk_app_bledemo/sdk_app_bledemo/main.c diff --git a/customer_app/sdk_app_bledemo/Makefile b/customer_app/sdk_app_bledemo/Makefile new file mode 100644 index 00000000..6c8dfdbf --- /dev/null +++ b/customer_app/sdk_app_bledemo/Makefile @@ -0,0 +1,40 @@ +# +# This is a project Makefile. It is assumed the directory this Makefile resides in is a +# project subdirectory. +# + +PROJECT_NAME := sdk_app_bledemo +PROJECT_PATH := $(abspath .) +PROJECT_BOARD := evb +export PROJECT_PATH PROJECT_BOARD +#CONFIG_TOOLPREFIX := + +-include ./proj_config.mk + +ifeq ($(origin BL60X_SDK_PATH), undefined) +BL60X_SDK_PATH_GUESS ?= $(shell pwd) +BL60X_SDK_PATH ?= $(BL60X_SDK_PATH_GUESS)/../.. +$(info ****** Please SET BL60X_SDK_PATH ******) +$(info ****** Trying SDK PATH [$(BL60X_SDK_PATH)]) +endif + +COMPONENTS_NETWORK := sntp dns_server +COMPONENTS_BLSYS := bltime blfdt blmtd blota bloop loopadc looprt loopset +COMPONENTS_VFS := romfs +COMPONENTS_BLE := blecontroller blestack + +INCLUDE_COMPONENTS += freertos_riscv_ram bl602 bl602_std bl602_wifi bl602_wifidrv hal_drv lwip lwip_dhcpd mbedtls vfs yloop utils cli aws-iot httpc netutils blog blog_testc blsync_ble cjson +INCLUDE_COMPONENTS += easyflash4 +INCLUDE_COMPONENTS += $(COMPONENTS_NETWORK) +INCLUDE_COMPONENTS += $(COMPONENTS_BLSYS) +INCLUDE_COMPONENTS += $(COMPONENTS_VFS) +INCLUDE_COMPONENTS += $(PROJECT_NAME) + +ifeq ($(CONFIG_BT),1) +INCLUDE_COMPONENTS += $(COMPONENTS_BLE) +ifeq ($(CONFIG_BT_MESH),1) +INCLUDE_COMPONENTS += blemesh +endif +endif + +include $(BL60X_SDK_PATH)/make_scripts_riscv/project.mk diff --git a/customer_app/sdk_app_bledemo/README.md b/customer_app/sdk_app_bledemo/README.md new file mode 100644 index 00000000..52fa32cf --- /dev/null +++ b/customer_app/sdk_app_bledemo/README.md @@ -0,0 +1,52 @@ +# BLE Demo user guide + +This demo code button pin is IO12. Please add the following setting to corresponding dts file :this node feature is " button" and mode is " multipress". this node will trigger three event , customer can set "press time" setting. + + The central device will connect peripheral device when two devices is close to 5 cm to 10 cm ( Rssi < -20 ). + +```c +gpio2 { + status = "okay"; + pin = <12>; + feature = "button"; + active = "Hi"; + mode = "multipress"; + button { + debounce = <10>; + short_press_ms { + start = <100>; + end = <2000>; + kevent = <2>; + }; + long_press_ms { + start = <3000>; + end = <5000>; + kevent = <3>; + }; + longlong_press_ms { + start = <10000>; + kevent = <4>; + }; + trig_level = "Lo"; + }; + hbn_use = "disable"; +}; +``` + + + +## 1. Peripheral Function + +Short press button : Start Bluetooth Advertising. + +Longlong press button : Send notification when device state is connected. + +## 2. Central Function + +Long press button : Start Bluetooth Scanning. + +Longlong press button : Write data without response when device state is connected. + + + + \ No newline at end of file diff --git a/customer_app/sdk_app_bledemo/genromap b/customer_app/sdk_app_bledemo/genromap new file mode 100644 index 00000000..31d3ab20 --- /dev/null +++ b/customer_app/sdk_app_bledemo/genromap @@ -0,0 +1,3 @@ +#!/bin/sh +make CONFIG_CHIP_NAME=BL602 CONFIG_LINK_ROM=1 -j +exit $? diff --git a/customer_app/sdk_app_bledemo/logo.png b/customer_app/sdk_app_bledemo/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..859f106d513644593087d1a6fabf51d19a8f5767 GIT binary patch literal 17129 zcmV)wK$O3UP)Pyiqe(Qj?=dQ+Q(=#;&-$Y{y}5WANbd3)U+gi;&1R~(&!zZjq!vQ z!T;Q@sq>vSi^;^l%MEch-7bmy;7j^eZY&qk?Nfhdx+mQhK$m3De8$FN*a?mqjDw#9 zslCByTVJ@t7w+^&dqc^-U^tR6_(PFoQejfYL!QfOHW{;Q<~+AO*KM2SvE{oh75P~P zBcYlxOpoCaLa0xTqI7#Qa~`@QgXS~9fDlYr6x`~N){K#)wx?y_<+{#2jsC`-KrE4r zC$)GY34xq|v?VAejV2SrShX$InH&hk+x^jlExxVCI(D2K@C9QgW(^`*72tK+krJ*V zVgY2pQ-H~|gv7R7rPGdNuG@LhoSaLmz179eT&FG14Qi4h8)?E=oi=r7))}OzYUxu& zLRl2CI-km8c!5OSv$|rbCmk>jE{xhu-^^4u0BvsDwR!5~yyXDKN*9yt=%~3x>_58^YUp00D!r^)||?e+Ux{ZcMw1WJ@n3X;`L+1o*2A%>GMfMdsjPK(j7tRnXV z>tn2?Tfu_RL}Z{mweY(C|cAqS2$Tre6#(>bgrm;?GlX=-zGZ*go@P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+<1xHpzu46?-&a(0xtZne~ z?U;qc+Fvt%aD7E@F!tE4W>97hyPtBHOy&ZY8G||7L1yl<^4yE&W zktLEubOT8#LOt<6JZt1H80An%K)Z)P_UQx?X-Fk z=mQiJHan%+@x{oS>qnA2`$=%7-D0JWe-7&eZ98c_1tkd2ox8SuG_bZOWr83B5?_k*7tX zD;+iy>dOc~fI0@lOlJXp0)hQ68af3XfllYf8h)VV;OvGa0sV~DQiFT2MmoJ6a-Cp= znojS5@gw-uE9st`5-W(|!K4b!zEW;H=?l)75o#p#h<{>l4EM1P3hqi0>U=h-Vez)< zH`gy5!Ke71f=Y4u=%YmXLE=&ZykUnvltizkQqTA%y7zFD7NZ;ta@F$C)m;{Yk4S-( zm@Bz8sN~}IQnkfpl5OdNW{0HYd$ydzA_)0bm< zHx1F4Qhx3^^-x8j2V0uEfZIa4pZjr0xkqb7EI`iOHQu-~YOh{#`{H8JqpEk5v>%B}X%K2c zHI9bjTb?zt%XL9Gq%J9psF3+6K;aRhC%z4e(o{PSnubztH86EqEQTK|BL+8>m%ERQ zU4}$TkfwAOclmHss>GvI`ws0#=6v*I){`j+j@i`=WgbC;W{xtpbuoP^uaVB-Vy7}K zQlgFTq{ieZT{ftk1_z_4CmGlZBdJ0&nt7m%db2Srclr}#&?}KE!$}74DU^fSB=zi+ zAe6hF`llL{L%NdsL&Q_cIY-aYQwmS1kUlop;h}bIRh8zSPCKze?+huDs1xZ)<=)YU z>+qHs6sfvjYN&MN+OT^>)s${5z9iL!x|~%7V4HtvFX=rg4KhS;=mk+@T;WB=#)vi% zaFUcw3jry~D8p?~GN@sdYNgZRLT;dolp(BXxavqjRqp^b?sb5VT3lfonIqEzZ-y2a kX~Dc1YL%(O%xr=G4;g#44M%g6W&i*H07*qoM6N<$f(4s*IsgCw literal 0 HcmV?d00001 diff --git a/customer_app/sdk_app_bledemo/proj_config.mk b/customer_app/sdk_app_bledemo/proj_config.mk new file mode 100644 index 00000000..375b741e --- /dev/null +++ b/customer_app/sdk_app_bledemo/proj_config.mk @@ -0,0 +1,56 @@ +# +#compiler flag config domain +# +#CONFIG_TOOLPREFIX := +#CONFIG_OPTIMIZATION_LEVEL_RELEASE := 1 +#CONFIG_M4_SOFTFP := 1 + +# +#board config domain +# +CONFIG_BOARD_FLASH_SIZE := 2 + +#firmware config domain +# + +#set CONFIG_ENABLE_ACP to 1 to enable ACP, set to 0 or comment this line to disable +#CONFIG_ENABLE_ACP:=1 +CONFIG_BL_IOT_FW_AP:=1 +CONFIG_BL_IOT_FW_AMPDU:=0 +CONFIG_BL_IOT_FW_AMSDU:=0 +CONFIG_BL_IOT_FW_P2P:=0 +CONFIG_ENABLE_PSM_RAM:=1 +#CONFIG_ENABLE_CAMERA:=1 +CONFIG_ENABLE_BLSYNC:=1 +#CONFIG_ENABLE_VFS_SPI:=1 +CONFIG_ENABLE_VFS_ROMFS:=1 + +# set easyflash env psm size, only support 4K、8K、16K options +CONFIG_ENABLE_PSM_EF_SIZE:=16K + +CONFIG_FREERTOS_TICKLESS_MODE:=0 + +CONFIG_BT:=1 +CONFIG_BT_PERIPHERAL:=1 +CONFIG_BT_CENTRAL:=1 +CONFIG_BT_OBSERVER:=1 +CONFIG_BT_CONN:=1 +CONFIG_BLE_TP_SERVER:=1 +CONFIG_BT_SMP:=1 +CONFIG_BT_FIXED_PASSKEY:=1 +CONFIG_BT_SETTINGS:=1 +#CONFIG_BT_MESH := 1 +CONFIG_BLE_STACK_DBG_PRINT := 1 +CONFIG_BT_STACK_PTS := 0 +ifeq ($(CONFIG_BT_MESH),1) +CONFIG_BT_MESH_PB_ADV := 1 +CONFIG_BT_MESH_PB_GATT := 1 +CONFIG_BT_MESH_FRIEND := 1 +CONFIG_BT_MESH_LOW_POWER := 1 +CONFIG_BT_MESH_PROXY := 1 +CONFIG_BT_MESH_GATT_PROXY := 1 + +endif + +#blog enable components format :=blog_testc cli vfs helper +LOG_ENABLED_COMPONENTS:=blog_testc hal_drv loopset looprt bloop diff --git a/customer_app/sdk_app_bledemo/sdk_app_bledemo/ble_app.h b/customer_app/sdk_app_bledemo/sdk_app_bledemo/ble_app.h new file mode 100644 index 00000000..b27748a9 --- /dev/null +++ b/customer_app/sdk_app_bledemo/sdk_app_bledemo/ble_app.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2020 Bouffalolab. + * + * This file is part of + * *** Bouffalolab Software Dev Kit *** + * (see www.bouffalolab.com). + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of Bouffalo Lab nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __BLE_APP_H_ +#define __BLE_APP_H_ + + +#define NAME_LEN 30 +#define CHAR_SIZE_MAX 512 +#define BT_UUID_TEST BT_UUID_DECLARE_16(0xFFF0) +#define BT_UUID_TEST_RX BT_UUID_DECLARE_16(0xFFF1) +#define BT_UUID_TEST_TX BT_UUID_DECLARE_16(0xFFF2) + + +#define EV_BLE_TEST 0x0504 +#define BLE_ADV_START 0x01 +#define BLE_ADV_STOP 0x02 +#define BLE_DEV_CONN 0x03 +#define BLE_DEV_DISCONN 0x04 +#define BLE_SCAN_START 0x05 +#define BLE_SCAN_STOP 0x06 + +#define LED_RED_PIN (17) +#define LED_GREEN_PIN (14) +#define LED_BLUE_PIN (11) + +enum app_ble_role +{ + PERIPHERAL=1, + CENTRAL +}; + +void apps_ble_start (void); +void bleapps_adv_starting(void); +void bleapps_adv_stop(void); +void ble_bl_notify_task(void); +void ble_bl_disconnect(void); + + + +void ble_appc_start(void); +void start_scan(void); +void ble_appc_stopscan(void); +void bl_gatt_write_without_rsp(void); +void ble_appc_disconnected(void); + +#endif diff --git a/customer_app/sdk_app_bledemo/sdk_app_bledemo/ble_appc.c b/customer_app/sdk_app_bledemo/sdk_app_bledemo/ble_appc.c new file mode 100644 index 00000000..7dc8bbf3 --- /dev/null +++ b/customer_app/sdk_app_bledemo/sdk_app_bledemo/ble_appc.c @@ -0,0 +1,332 @@ +/* + * Copyright (c) 2020 Bouffblfolab. + * + * This file is part of + * *** Bouffblfolab Software Dev Kit *** + * (see www.bouffblfolab.com). + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materiblfs provided with the distribution. + * 3. Neither the name of Bouffblfo Lab nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHblfL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTblf, SPECIblf, EXEMPLARY, OR CONSEQUENTIblf + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "ble_app.h" +#include +#include +#include "bluetooth.h" +#include "ble_cli_cmds.h" +#include "hci_driver.h" +#include "ble_lib_api.h" +#include +#include +#include + +#include "conn.h" +#include "gatt.h" +#include "hci_core.h" +#include "uuid.h" +#include "oad_api.h" +#include "hal_pwm.h" +#include "hal_gpio.h" +#include "bl_gpio.h" +#include + + + +static struct bt_conn *default_conn; +static struct bt_uuid_16 uuid = BT_UUID_INIT_16(0); +static struct bt_gatt_discover_params discover_params; +static struct bt_gatt_subscribe_params subscribe_params; +static u16_t bt_gatt_write_without_hanle=0; + +static uint8_t notify_func(struct bt_conn *conn, + struct bt_gatt_subscribe_params *params, + const void *data, uint16_t length) +{ + + if(length!=0){ + + uint8_t *recv_buffer; + recv_buffer=pvPortMalloc(sizeof(uint8_t)*length); + memcpy(recv_buffer, data, length); + printf("ble notification="); + for (size_t i = 0; i < length; i++) + { + printf("0x%x ",recv_buffer[i]); + } + vPortFree(recv_buffer); + printf("\n"); + + } + + return BT_GATT_ITER_CONTINUE; +} +void bl_gatt_write_without_rsp(void) +{ + char data[10] = {0x00,0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}; + if(default_conn!=NULL){ + + bt_gatt_write_without_response(default_conn, bt_gatt_write_without_hanle, data, 10, 0); + + } + +} + + +void ble_appc_disconnected(void) +{ + if(default_conn!=NULL) + { + + printf("user disconnect\n"); + bt_conn_disconnect(default_conn,BT_HCI_ERR_REMOTE_USER_TERM_CONN); + aos_post_event(EV_BLE_TEST,BLE_DEV_DISCONN,NULL); + } +} +void ble_appc_stopscan(void) +{ + + printf("user stop scan\n"); + bt_le_scan_stop(); + aos_post_event(EV_BLE_TEST,BLE_SCAN_STOP,NULL); + +} +static uint8_t discover_func(struct bt_conn *conn, + const struct bt_gatt_attr *attr, + struct bt_gatt_discover_params *params) +{ + int err; + + if (!attr) { + printf("Discover complete\n"); + (void)memset(params, 0, sizeof(*params)); + return BT_GATT_ITER_STOP; + } + + printf("[ATTRIBUTE] handle %d\n", attr->handle); + + if (!bt_uuid_cmp(discover_params.uuid, BT_UUID_TEST)) { + + memcpy(&uuid, BT_UUID_TEST_RX, sizeof(uuid)); + discover_params.uuid = &uuid.uuid; + discover_params.start_handle = attr->handle + 1; + discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; + + err = bt_gatt_discover(conn, &discover_params); + if (err) { + printf("Discover failed (err %d)\n", err); + } + } else if (!bt_uuid_cmp(discover_params.uuid, + BT_UUID_TEST_RX)) { + memcpy(&uuid, BT_UUID_GATT_CCC, sizeof(uuid)); + discover_params.uuid = &uuid.uuid; + discover_params.start_handle = attr->handle + 2; + discover_params.type = BT_GATT_DISCOVER_DESCRIPTOR; + subscribe_params.value_handle = bt_gatt_attr_value_handle(attr); + + err = bt_gatt_discover(conn, &discover_params); + if (err) { + printf("Discover failed (err %d)\n", err); + } + } else if(!bt_uuid_cmp(discover_params.uuid, + BT_UUID_GATT_CCC)) { + subscribe_params.notify = notify_func; + subscribe_params.value = BT_GATT_CCC_NOTIFY; + subscribe_params.ccc_handle = attr->handle; + err = bt_gatt_subscribe(conn, &subscribe_params); + if (err && err != -EALREADY) { + printf("Subscribe failed (err %d)\n", err); + } else { + printf("[SUBSCRIBED]\n"); + bt_gatt_write_without_hanle=subscribe_params.ccc_handle+2; + } + + + return BT_GATT_ITER_STOP; + } + + return BT_GATT_ITER_STOP; +} + +static bool data_cb(struct bt_data *data, void *user_data) +{ + char *name = user_data; + u8_t len; + + switch (data->type) { + case BT_DATA_NAME_SHORTENED: + case BT_DATA_NAME_COMPLETE: + len = (data->data_len > NAME_LEN - 1)?(NAME_LEN - 1):(data->data_len); + memcpy(name, data->data, len); + return false; + default: + return true; + } +} + + +static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, + struct net_buf_simple *ad) +{ + char dev[BT_ADDR_LE_STR_LEN]; + char name[NAME_LEN]; + + struct bt_le_conn_param param = { + .interval_min = BT_GAP_INIT_CONN_INT_MIN, + .interval_max = BT_GAP_INIT_CONN_INT_MAX, + .latency = 0, + .timeout = 400, + }; + //struct bt_le_conn_param param; + bt_addr_le_to_str(addr, dev, sizeof(dev)); + + if (rssi < -20) + { + return; + } + /* We're only interested in connectable events */ + if (type == BT_LE_ADV_IND) { + + bt_le_scan_stop(); + printf("device_found ok\r\n"); + (void)memset(name, 0, sizeof(name)); + bt_data_parse(ad, data_cb, name); + printf("[DEVICE]: %s, AD evt type %u, AD data len %u, RSSI %i NAME=%s\n", + dev, type, ad->len, rssi,name); + + default_conn = bt_conn_create_le(addr, ¶m); + + if(!default_conn){ + printf("Connection failed\r\n"); + }else{ + printf("Connection pending\r\n"); + } + + } + +} + +void start_scan(void) +{ + int err; + struct bt_le_scan_param scan_param; + + scan_param.type=BT_LE_SCAN_TYPE_PASSIVE; + scan_param.filter_dup=0; + scan_param.interval=0x80; + scan_param.window=0x40; + err = bt_le_scan_start(&scan_param, device_found); + if (err) { + printf("Scanning failed to start (err %d)\n", err); + return; + } + aos_post_event(EV_BLE_TEST,BLE_SCAN_START,NULL); + printf("Scanning successfully started\n"); +} + +static void connected(struct bt_conn *conn, uint8_t conn_err) +{ + char addr[BT_ADDR_LE_STR_LEN]; + int err; + + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + if (conn_err) { + printf("Failed to connect to %s (%u)\n", addr, conn_err); + + bt_conn_unref(default_conn); + default_conn = NULL; + + + return; + } + + printf("Connected: %s\n", addr); + aos_post_event(EV_BLE_TEST,BLE_DEV_CONN,NULL); + if (conn == default_conn) { + memcpy(&uuid, BT_UUID_TEST, sizeof(uuid)); + discover_params.uuid = &uuid.uuid; + discover_params.func = discover_func; + discover_params.start_handle = 0x0001; + discover_params.end_handle = 0xffff; + discover_params.type = BT_GATT_DISCOVER_PRIMARY; + + err = bt_gatt_discover(default_conn, &discover_params); + if (err) { + printf("Discover failed(err %d)\n", err); + return; + } + } +} + +static void disconnected(struct bt_conn *conn, uint8_t reason) +{ + char addr[BT_ADDR_LE_STR_LEN]; + + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + printf("Disconnected: %s (reason 0x%02x)\n", addr, reason); + + if (default_conn != conn) { + return; + } + + bt_conn_unref(default_conn); + default_conn = NULL; + aos_post_event(EV_BLE_TEST,BLE_DEV_DISCONN,NULL); +} + +static struct bt_conn_cb conn_callbacks = { + .connected = connected, + .disconnected = disconnected, +}; + +static void bt_ready(void) +{ + start_scan(); +} + +static void ble_app_init(int err) +{ + if (err != 0) { + printf("BT FAILED started\n"); + }else{ + printf("BT SUCCESS started\n"); + bt_ready(); + } + +} + +void ble_appc_start(void) +{ + int err; + ble_controller_init(configMAX_PRIORITIES - 1); + // Initiblfize BLE Host stack + hci_driver_init(); + err = bt_enable(ble_app_init); + + if (err) { + printf("Bluetooth init failed (err %d)\n", err); + return; + } + bt_conn_cb_register(&conn_callbacks); + +} + diff --git a/customer_app/sdk_app_bledemo/sdk_app_bledemo/ble_apps.c b/customer_app/sdk_app_bledemo/sdk_app_bledemo/ble_apps.c new file mode 100644 index 00000000..f261a448 --- /dev/null +++ b/customer_app/sdk_app_bledemo/sdk_app_bledemo/ble_apps.c @@ -0,0 +1,354 @@ +/* + * Copyright (c) 2020 Bouffblfolab. + * + * This file is part of + * *** Bouffblfolab Software Dev Kit *** + * (see www.bouffblfolab.com). + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materiblfs provided with the distribution. + * 3. Neither the name of Bouffblfo Lab nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHblfL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTblf, SPECIblf, EXEMPLARY, OR CONSEQUENTIblf + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "ble_app.h" +#include +#include +#include "bluetooth.h" +#include "ble_cli_cmds.h" +#include "hci_driver.h" +#include "ble_lib_api.h" + +#include +#include + +#include "conn.h" +#include "gatt.h" +#include "hci_core.h" +#include "uuid.h" +#include "oad_api.h" +#include "hal_pwm.h" +#include "hal_gpio.h" +#include "bl_gpio.h" +#include +#include +#include + +static void ble_bl_ccc_cfg_changed(const struct bt_gatt_attr *attr, u16_t vblfue); +static int ble_blf_recv(struct bt_conn *conn, + const struct bt_gatt_attr *attr, const void *buf, + u16_t len, u16_t offset, u8_t flags); + + +static const struct bt_data ad[] = { + BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), + BT_DATA(BT_DATA_NAME_COMPLETE, "BL_602", 6), + BT_DATA(BT_DATA_MANUFACTURER_DATA, "BL_602", 6), + +}; +static struct bt_gatt_attr blattrs[]= { + BT_GATT_PRIMARY_SERVICE(BT_UUID_TEST), + + BT_GATT_CHARACTERISTIC(BT_UUID_TEST_RX, + BT_GATT_CHRC_NOTIFY, + BT_GATT_PERM_READ, + NULL, + NULL, + NULL), + + BT_GATT_CCC(ble_bl_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), + + BT_GATT_CHARACTERISTIC(BT_UUID_TEST_TX, + BT_GATT_CHRC_WRITE_WITHOUT_RESP, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, + NULL, + ble_blf_recv, + NULL) +}; +static struct bt_conn *ble_bl_conn=NULL; +static bool notify_flag=false; +static void ble_bl_ccc_cfg_changed(const struct bt_gatt_attr *attr, u16_t vblfue) +{ + if(vblfue == BT_GATT_CCC_NOTIFY) { + + printf("enable notify.\n"); + notify_flag=true; + + } else { + printf("disable notify.\n"); + notify_flag=false; + } + +} + + + +void ble_bl_notify_task(void) +{ + + char data[10] = {0x00,0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}; + if(ble_bl_conn!=NULL&¬ify_flag==true){ + printf("ble_bl_notify_task.\n"); + bt_gatt_notify(ble_bl_conn, &blattrs[1],data,10); + + } + +} +void ble_bl_disconnect(void) +{ + + + if(ble_bl_conn!=NULL) + { + + printf("user disconnect\n"); + bt_conn_disconnect(ble_bl_conn,BT_HCI_ERR_REMOTE_USER_TERM_CONN); + aos_post_event(EV_BLE_TEST,BLE_DEV_DISCONN,NULL); + } +} + +static int ble_blf_recv(struct bt_conn *conn, + const struct bt_gatt_attr *attr, const void *buf, + u16_t len, u16_t offset, u8_t flags) +{ + uint8_t *recv_buffer; + recv_buffer=pvPortMalloc(sizeof(uint8_t)*len); + memcpy(recv_buffer, buf, len); + printf("ble rx=%d\n",len); + for (size_t i = 0; i < len; i++) + { + printf("0x%x ",recv_buffer[i]); + } + vPortFree(recv_buffer); + printf("\n"); + return 0; +} + + + +struct bt_gatt_service ble_bl_server = BT_GATT_SERVICE(blattrs); + +static void bt_ready(void) +{ + + bt_set_name("blf_602"); + printf("Bluetooth initiblfized\n"); + bleapps_adv_starting(); + + +} + +void bleapps_adv_starting(void) +{ + int err; + + printf("Bluetooth Advertising start\n"); + err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); + if (err) { + printf("Advertising failed to start (err %d)\n", err); + + }else{ + + aos_post_event(EV_BLE_TEST,BLE_ADV_START,NULL); + } + +} +void bleapps_adv_stop(void) +{ + int err; + printf("Bluetooth Advertising stop\n"); + err =bt_le_adv_stop(); + if (err) { + printf("Advertising failed to stop (err %d)\n", err); + + }else{ + + aos_post_event(EV_BLE_TEST,BLE_ADV_STOP,NULL); + + } +} + + + +static void ble_app_init(int err) +{ + if (err != 0) { + printf("BT FAILED started\n"); + }else{ + printf("BT SUCCESS started\n"); + bt_ready(); + + } + +} + +static void bl_connected(struct bt_conn *conn, uint8_t err) +{ + struct bt_le_conn_param param; + param.interval_max=24; + param.interval_min=24; + param.latency=0; + param.timeout=600; + int update_err; + if (err) { + printf("Connection failed (err 0x%02x)\n", err); + } else { + printf("Connected\n"); + ble_bl_conn=conn; + update_err = bt_conn_le_param_update(conn, ¶m); + + if (err) { + printf("conn update failed (err %d)\r\n", err); + } else { + printf("conn update initiated\r\n"); + } + #if 0 + #if defined(CONFIG_BT_SMP) + bt_conn_set_security(conn, BT_SECURITY_L4); + #endif + #endif + aos_post_event(EV_BLE_TEST,BLE_DEV_CONN,NULL); + } +} + +static void bl_disconnected(struct bt_conn *conn, uint8_t reason) +{ + printf("Disconnected (reason 0x%02x)\n", reason); + aos_post_event(EV_BLE_TEST,BLE_DEV_DISCONN,NULL); +} + +static struct bt_conn_cb conn_callbacks = { + .connected = bl_connected, + .disconnected = bl_disconnected, +}; + + + + +static void ble_stack_start(void) +{ + // Initiblfize BLE controller + ble_controller_init(configMAX_PRIORITIES - 1); + // Initiblfize BLE Host stack + hci_driver_init(); + bt_enable(ble_app_init); + +} +#if defined(CONFIG_BT_SMP) + +static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) +{ + char addr[BT_ADDR_LE_STR_LEN]; + + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + printf("passkey_str is: %06u\r\n", passkey); +} + +static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey) +{ + char addr[BT_ADDR_LE_STR_LEN]; + + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + printf("Confirm passkey for %s: %06u\r\n", addr, passkey); + bt_conn_auth_passkey_confirm(conn); +} + +static void auth_passkey_entry(struct bt_conn *conn) +{ + char addr[BT_ADDR_LE_STR_LEN]; + + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + printf("Enter passkey for %s\r\n", addr); +} + +static void auth_cancel(struct bt_conn *conn) +{ + char addr[BT_ADDR_LE_STR_LEN]; + + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + printf("Pairing cancelled: %s\r\n", addr); +} + +static void auth_pairing_confirm(struct bt_conn *conn) +{ + char addr[BT_ADDR_LE_STR_LEN]; + + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + printf("Confirm pairing for %s\r\n", addr); + +} + +static void auth_pairing_complete(struct bt_conn *conn, bool bonded) +{ + char addr[BT_ADDR_LE_STR_LEN]; + + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + printf("%s with %s\r\n", bonded ? "Bonded" : "Paired", addr); +} + +static void auth_pairing_failed(struct bt_conn *conn, enum bt_security_err reason) +{ + char addr[BT_ADDR_LE_STR_LEN]; + + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + printf("Pairing failed with %s\r\n", addr); +} + +static struct bt_conn_auth_cb auth_cb_display = { + .passkey_display = auth_passkey_display, + .passkey_entry = auth_passkey_entry, + .passkey_confirm = auth_passkey_confirm, + .cancel = auth_cancel, + .pairing_confirm = auth_pairing_confirm, + .pairing_failed = auth_pairing_failed, + .pairing_complete = auth_pairing_complete, +}; +#endif + +void apps_ble_start(void) +{ + int err; + ble_stack_start(); + bt_conn_cb_register(&conn_callbacks); + err=bt_gatt_service_register(&ble_bl_server); + if (err==0) { + printf("bt_gatt_service_register ok\n"); + } else { + printf("bt_gatt_service_register err\n"); + + } + + + #if defined(CONFIG_BT_SMP) + err = bt_conn_auth_cb_register(&auth_cb_display); + + if(err){ + printf("Auth callback has blfready been registered\r\n"); + }else{ + printf("Register auth callback successfully\r\n"); + } + #endif +} + diff --git a/customer_app/sdk_app_bledemo/sdk_app_bledemo/bouffalo.mk b/customer_app/sdk_app_bledemo/sdk_app_bledemo/bouffalo.mk new file mode 100644 index 00000000..e12ff417 --- /dev/null +++ b/customer_app/sdk_app_bledemo/sdk_app_bledemo/bouffalo.mk @@ -0,0 +1,26 @@ +# +# "main" pseudo-component makefile. +# +# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) + +include $(BL60X_SDK_PATH)/components/network/ble/ble_common.mk + +ifeq ($(CONFIG_ENABLE_PSM_RAM),1) +CPPFLAGS += -DCONF_USER_ENABLE_PSRAM +endif + +ifeq ($(CONFIG_ENABLE_CAMERA),1) +CPPFLAGS += -DCONF_USER_ENABLE_CAMERA +endif + +ifeq ($(CONFIG_ENABLE_BLSYNC),1) +CPPFLAGS += -DCONF_USER_ENABLE_BLSYNC +endif + +ifeq ($(CONFIG_ENABLE_VFS_SPI),1) +CPPFLAGS += -DCONF_USER_ENABLE_VFS_SPI +endif + +ifeq ($(CONFIG_ENABLE_VFS_ROMFS),1) +CPPFLAGS += -DCONF_USER_ENABLE_VFS_ROMFS +endif diff --git a/customer_app/sdk_app_bledemo/sdk_app_bledemo/main.c b/customer_app/sdk_app_bledemo/sdk_app_bledemo/main.c new file mode 100644 index 00000000..7b60c62d --- /dev/null +++ b/customer_app/sdk_app_bledemo/sdk_app_bledemo/main.c @@ -0,0 +1,509 @@ +/* + * Copyright (c) 2020 Bouffalolab. + * + * This file is part of + * *** Bouffalolab Software Dev Kit *** + * (see www.bouffalolab.com). + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of Bouffalo Lab nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include "bl602_adc.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "hal_pwm.h" +#include +#include +#include +#include +#include +#include +#include "ble_lib_api.h" +#include "ble_app.h" +#include "hal_pds.h" +#include "bl_rtc.h" +#include "utils_string.h" + +extern uint8_t _heap_start; +extern uint8_t _heap_size; // @suppress("Type cannot be resolved") +extern uint8_t _heap_wifi_start; +extern uint8_t _heap_wifi_size; // @suppress("Type cannot be resolved") +static HeapRegion_t xHeapRegions[] = +{ + { &_heap_start, (unsigned int) &_heap_size}, //set on runtime + { &_heap_wifi_start, (unsigned int) &_heap_wifi_size }, + { NULL, 0 }, /* Terminates the array. */ + { NULL, 0 } /* Terminates the array. */ +}; + + +void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName ) +{ + puts("Stack Overflow checked\r\n"); + while (1) { + /*empty here*/ + } +} + +void vApplicationMallocFailedHook(void) +{ + printf("Memory Allocate Failed. Current left size is %d bytes\r\n", + xPortGetFreeHeapSize() + ); + while (1) { + /*empty here*/ + } +} + +void vApplicationIdleHook(void) +{ + + __asm volatile( + " wfi " + ); + + +} + +static void proc_hellow_entry(void *pvParameters) +{ + + vTaskDelay(500); + + while (1) { + printf("%s: RISC-V rv32imafc\r\n", __func__); + vTaskDelay(10000); + } + vTaskDelete(NULL); +} + + + + +static int get_dts_addr(const char *name, uint32_t *start, uint32_t *off) +{ + uint32_t addr = hal_board_get_factory_addr(); + const void *fdt = (const void *)addr; + uint32_t offset; + + if (!name || !start || !off) { + return -1; + } + + offset = fdt_subnode_offset(fdt, 0, name); + if (offset <= 0) { + log_error("%s NULL.\r\n", name); + return -1; + } + + *start = (uint32_t)fdt; + *off = offset; + + return 0; +} +static enum app_ble_role app_role; +static void event_cb_key_event(input_event_t *event, void *private_data) +{ + switch (event->code) { + case KEY_1: + { + printf("[KEY_1] [EVT] INIT DONE %lld\r\n", aos_now_ms()); + printf("short press \r\n"); + apps_ble_start(); + app_role=PERIPHERAL; + } + break; + case KEY_2: + { + printf("[KEY_2] [EVT] INIT DONE %lld\r\n", aos_now_ms()); + printf("long press \r\n"); + ble_appc_start(); + app_role=CENTRAL; + } + break; + case KEY_3: + { + printf("[KEY_3] [EVT] INIT DONE %lld\r\n", aos_now_ms()); + printf("longlong press \r\n"); + if(app_role==PERIPHERAL){ + + ble_bl_notify_task(); + }else{ + + bl_gatt_write_without_rsp(); + } + + } + break; + default: + { + printf("[KEY] [EVT] Unknown code %u, %lld\r\n", event->code, aos_now_ms()); + /*nothing*/ + } + } +} + +static void borad_rgb_init(void) +{ + + bl_gpio_enable_output(LED_RED_PIN,1,0); + bl_gpio_enable_output(LED_GREEN_PIN,1,0); + bl_gpio_enable_output(LED_BLUE_PIN,1,0); + bl_gpio_output_set(LED_RED_PIN,1); + bl_gpio_output_set(LED_GREEN_PIN,1); + bl_gpio_output_set(LED_BLUE_PIN,1); + +} +static void borad_rgb_off(void) +{ + + bl_gpio_output_set(LED_RED_PIN,1); + bl_gpio_output_set(LED_GREEN_PIN,1); + bl_gpio_output_set(LED_BLUE_PIN,1); + +} +static void event_cb_ble_event(input_event_t *event, void *private_data) +{ + switch (event->code) { + case BLE_ADV_START: + { + borad_rgb_off(); + printf("ble adv start \r\n"); + bl_gpio_output_set(LED_BLUE_PIN,0); + + + } + break; + case BLE_ADV_STOP: + { + printf("ble adv stop \r\n"); + borad_rgb_off(); + + } + break; + case BLE_DEV_CONN: + { + borad_rgb_off(); + bl_gpio_output_set(LED_GREEN_PIN,0); + + printf("ble dev connnected \r\n"); + + + } + break; + case BLE_DEV_DISCONN: + { + borad_rgb_off(); + bl_gpio_output_set(LED_RED_PIN,0); + + printf("ble dev disconnnected\r\n"); + vTaskDelay(5000); + if(app_role==PERIPHERAL){ + + bleapps_adv_starting(); + }else{ + + start_scan(); + } + } + break; + case BLE_SCAN_START: + { + borad_rgb_off(); + bl_gpio_output_set(LED_BLUE_PIN,0); + printf("ble dev scanning\r\n"); + } + break; + case BLE_SCAN_STOP: + { + borad_rgb_off(); + printf("ble dev stop scan\r\n"); + } + break; + default: + { + printf("[KEY] [EVT] Unknown code %u, %lld\r\n", event->code, aos_now_ms()); + /*nothing*/ + } + } +} + + + +static void aos_loop_proc(void *pvParameters) +{ + int fd_console; + uint32_t fdt = 0, offset = 0; + static StackType_t proc_stack_looprt[512]; + static StaticTask_t proc_task_looprt; + + /*Init bloop stuff*/ + looprt_start(proc_stack_looprt, 512, &proc_task_looprt); + loopset_led_hook_on_looprt(); + +// easyflash_init(); + vfs_init(); + vfs_device_init(); + + /* uart */ +#if 1 + if (0 == get_dts_addr("uart", &fdt, &offset)) { + vfs_uart_init(fdt, offset); + } +#else + vfs_uart_init_simple_mode(0, 7, 16, 2 * 1000 * 1000, "/dev/ttyS0"); +#endif + if (0 == get_dts_addr("gpio", &fdt, &offset)) { + fdt_button_module_init((const void *)fdt, (int)offset); + } + +#if 0 /* pwm */ + if (0 == get_dts_addr("pwm", &fdt, &offset)) { + vfs_pwm_init(fdt, offset); + } +#endif + aos_loop_init(); + + fd_console = aos_open("/dev/ttyS0", 0); + if (fd_console >= 0) { + printf("Init CLI with event Driven\r\n"); + aos_cli_init(0); + aos_poll_read_fd(fd_console, aos_cli_event_cb_read_get(), (void*)0x12345678); + } + + aos_register_event_filter(EV_KEY, event_cb_key_event, NULL); + aos_register_event_filter(EV_BLE_TEST, event_cb_ble_event, NULL); + //tsen_adc_init(); + + #if defined(CONFIG_BT_TL) + //uart's pinmux has been configured in vfs_uart_init(load uart1's pin info from devicetree) + uart_init(1); + ble_controller_init(configMAX_PRIORITIES - 1); + #endif + + aos_loop_run(); + + puts("------------------------------------------\r\n"); + puts("+++++++++Critical Exit From Loop++++++++++\r\n"); + puts("******************************************\r\n"); + vTaskDelete(NULL); +} + +void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) +{ + /* If the buffers to be provided to the Idle task are declared inside this + function then they must be declared static - otherwise they will be allocated on + the stack and so not exists after this function exits. */ + static StaticTask_t xIdleTaskTCB; + //static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ]; + static StackType_t uxIdleTaskStack[512]; + + /* Pass out a pointer to the StaticTask_t structure in which the Idle task's + state will be stored. */ + *ppxIdleTaskTCBBuffer = &xIdleTaskTCB; + + /* Pass out the array that will be used as the Idle task's stack. */ + *ppxIdleTaskStackBuffer = uxIdleTaskStack; + + /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer. + Note that, as the array is necessarily of type StackType_t, + configMINIMAL_STACK_SIZE is specified in words, not bytes. */ + //*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; + *pulIdleTaskStackSize = 512;//size 512 words is For ble pds mode, otherwise stack overflow of idle task will happen. +} + +/* configSUPPORT_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the +application must provide an implementation of vApplicationGetTimerTaskMemory() +to provide the memory that is used by the Timer service task. */ +void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize) +{ + /* If the buffers to be provided to the Timer task are declared inside this + function then they must be declared static - otherwise they will be allocated on + the stack and so not exists after this function exits. */ + static StaticTask_t xTimerTaskTCB; + static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ]; + + /* Pass out a pointer to the StaticTask_t structure in which the Timer + task's state will be stored. */ + *ppxTimerTaskTCBBuffer = &xTimerTaskTCB; + + /* Pass out the array that will be used as the Timer task's stack. */ + *ppxTimerTaskStackBuffer = uxTimerTaskStack; + + /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer. + Note that, as the array is necessarily of type StackType_t, + configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */ + *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; +} + +void user_vAssertCalled(void) __attribute__ ((weak, alias ("vAssertCalled"))); +void vAssertCalled(void) +{ + volatile uint32_t ulSetTo1ToExitFunction = 0; + + taskDISABLE_INTERRUPTS(); + while( ulSetTo1ToExitFunction != 1 ) { + __asm volatile( "NOP" ); + } +} + +static void _dump_boot_info(void) +{ + char chip_feature[40]; + const char *banner; + + puts("Booting BL602 Chip...\r\n"); + + /*Display Banner*/ + if (0 == bl_chip_banner(&banner)) { + puts(banner); + } + puts("\r\n"); + /*Chip Feature list*/ + puts("\r\n"); + puts("------------------------------------------------------------\r\n"); + puts("RISC-V Core Feature:"); + bl_chip_info(chip_feature); + puts(chip_feature); + puts("\r\n"); + + puts("Build Version: "); + puts(BL_SDK_VER); // @suppress("Symbol is not resolved") + puts("\r\n"); + + puts("Build Version: "); + puts(BL_SDK_VER); // @suppress("Symbol is not resolved") + puts("\r\n"); + + puts("PHY Version: "); + puts(BL_SDK_PHY_VER); // @suppress("Symbol is not resolved") + puts("\r\n"); + + puts("RF Version: "); + puts(BL_SDK_RF_VER); // @suppress("Symbol is not resolved") + puts("\r\n"); + + puts("Build Date: "); + puts(__DATE__); + puts("\r\n"); + puts("Build Time: "); + puts(__TIME__); + puts("\r\n"); + puts("------------------------------------------------------------\r\n"); + +} + +static void system_init(void) +{ + blog_init(); + bl_irq_init(); + bl_sec_init(); + bl_sec_test(); + bl_dma_init(); + bl_rtc_init(); + hal_boot2_init(); + + /* board config is set after system is init*/ + hal_board_cfg(0); +} + +static void system_thread_init() +{ + +} + + + +void bfl_main() +{ + + static StackType_t proc_hellow_stack[512]; + static StaticTask_t proc_hellow_task; + + static StackType_t aos_loop_proc_stack[1024]; + static StaticTask_t aos_loop_proc_task; + + bl_sys_early_init(); + + /*Init UART In the first place*/ + bl_uart_init(0, 16, 7, 255, 255, 2 * 1000 * 1000); + puts("Starting bl602 now....\r\n"); + + bl_sys_init(); + + _dump_boot_info(); + borad_rgb_init(); + vPortDefineHeapRegions(xHeapRegions); + printf("Heap %u@%p, %u@%p\r\n", + (unsigned int)&_heap_size, &_heap_start, + (unsigned int)&_heap_wifi_size, &_heap_wifi_start + ); + + system_init(); + system_thread_init(); + + puts("[OS] Starting proc_hellow_entry task...\r\n"); + xTaskCreateStatic(proc_hellow_entry, (char*)"hellow", 512, NULL, 15, proc_hellow_stack, &proc_hellow_task); + + puts("[OS] Starting aos_loop_proc task...\r\n"); + xTaskCreateStatic(aos_loop_proc, (char*)"event_loop", 1024, NULL, 15, aos_loop_proc_stack, &aos_loop_proc_task); + + puts("[OS] Starting OS Scheduler...\r\n"); + vTaskStartScheduler(); +}