214 lines
5.9 KiB
C

/*
* File : main.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-5-30 Bernard the first version
*/
#include <rtthread.h>
#include <finsh.h>
#include "common.h"
#include "param_config.h"
#include "ble_pub.h"
#include "gpio_pub.h"
#include "drv_oled.h"
#include "app_ble.h"
#include "app_sdp.h"
#include "app_ble_init.h"
#include "rtos_pub.h"
#if (BLE_APP_SEC)
#include "app_sec.h"
#endif
#include "kernel_mem.h"
#include "rtthread.h"
#include "drv_iic.h"
#if defined(RT_USING_DFS_ROMFS)
#include <dfs_fs.h>
#endif
#if defined(PKG_USING_PLAYER)
#include "player.h"
#endif
#include "include.h"
#include "driver_pub.h"
#include "func_pub.h"
#include "app.h"
#include "ate_app.h"
#include "shell.h"
#include <fal.h>
#ifdef PKG_USING_RT_OTA
#include "rt_ota.h"
#endif
#include "sys_ctrl_pub.h"
static int wlan_app_init(void);
#include "app_temperature.h"
extern const struct romfs_dirent romfs_root;
#define DFS_ROMFS_ROOT (&romfs_root)
extern rt_err_t rt_audio_codec_hw_init(void);
extern int player_system_init(void);
extern void user_main( beken_thread_arg_t args );
extern int rt_hw_flash_disk_readonly_init(const char *name, uint32_t base, uint32_t sector_size, uint32_t capacity);
extern void rt_hw_wdg_start(int argc, char **argv);
extern int bk_wlan_dtim_rf_ps_mode_enable(void );
#define BUILD_UINT16(loByte, hiByte) \
((uint16_t)(((loByte) & 0x00FF) + (((hiByte) & 0x00FF) << 8)))
#define BK_ATT_DECL_PRIMARY_SERVICE_128 {0x00,0x28,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
#define BK_ATT_DECL_CHARACTERISTIC_128 {0x03,0x28,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
#define BK_ATT_DESC_CLIENT_CHAR_CFG_128 {0x02,0x29,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
#define WRITE_REQ_CHARACTERISTIC_128 {0x01,0xFF,0,0,0x34,0x56,0,0,0,0,0x28,0x37,0,0,0,0}
#define INDICATE_CHARACTERISTIC_128 {0x02,0xFF,0,0,0x34,0x56,0,0,0,0,0x28,0x37,0,0,0,0}
#define NOTIFY_CHARACTERISTIC_128 {0x03,0xFF,0,0,0x34,0x56,0,0,0,0,0x28,0x37,0,0,0,0}
static const uint8_t test_svc_uuid[16] = {0xFF,0xFF,0,0,0x34,0x56,0,0,0,0,0x28,0x37,0,0,0,0};
enum
{
TEST_IDX_SVC,
TEST_IDX_FF01_VAL_CHAR,
TEST_IDX_FF01_VAL_VALUE,
TEST_IDX_FF02_VAL_CHAR,
TEST_IDX_FF02_VAL_VALUE,
TEST_IDX_FF02_VAL_IND_CFG,
TEST_IDX_FF03_VAL_CHAR,
TEST_IDX_FF03_VAL_VALUE,
TEST_IDX_FF03_VAL_NTF_CFG,
TEST_IDX_NB,
};
extern bk_attm_desc_t test_att_db[TEST_IDX_NB];
extern void ble_set_notice_cb(ble_notice_cb_t func);
extern ble_err_t bk_ble_init(void);
extern void cli_ble_write_callback(write_req_t *write_req);
extern uint8_t cli_ble_read_callback(read_req_t *read_req);
extern void ble_notice_cb(ble_notice_t notice, void *param);
extern void ble_cmd_cb(ble_cmd_t cmd, ble_cmd_param_t *param);
extern uint8_t ble_active;
uint8_t actv_idx;
int main(int argc, char **argv)
{
/* mount ROMFS as root directory */
#if defined(RT_USING_DFS_ROMFS)
if (dfs_mount(RT_NULL, "/", "rom", 0, (const void *)DFS_ROMFS_ROOT) == 0)
{
rt_kprintf("ROMFS File System initialized!\n");
}
else
{
rt_kprintf("ROMFS File System initialized Failed!\n");
}
#endif
#if 0
/* mount sd card fat partition 1 as root directory */
saradc_config_vddram_voltage(PSRAM_VDD_3_3V);
if(dfs_mount("sd0", "/sd", "elm", 0, 0) == 0)
rt_kprintf("SD File System initialized!\n");
else
rt_kprintf("SD File System initialzation failed!\n");
#endif
#if 0
const struct fal_partition *dl_part = RT_NULL;
if ((dl_part = fal_partition_find(RT_BK_DL_PART_NAME)) != RT_NULL)
{
/* dump current firmware version. */
rt_kprintf("current image name: %s, version: %s, timestamp: %d \n", rt_ota_get_fw_dest_part_name(dl_part), rt_ota_get_fw_version(dl_part), rt_ota_get_fw_timestamp(dl_part));
rt_hw_flash_disk_readonly_init("flash0", dl_part->offset + 96, 512, dl_part->len - 1024);
/* mount sd card fat partition 1 as root directory */
if(dfs_mount("flash0", "/flash0", "elm", 0, 0) == 0)
rt_kprintf("FLASH File System initialized!\n");
else
rt_kprintf("FLASH File System initialzation failed!\n");
}
else
{
rt_kprintf("not found %s partition \n", RT_BK_DL_PART_NAME);
}
#endif
wlan_app_init();
#if defined(PKG_USING_PLAYER)
extern int player_codec_helixmp3_register(void);
extern int player_codec_beken_aac_register(void);
extern int player_codec_beken_m4a_register(void);
extern int player_codec_opencore_amr_register(void);
player_codec_helixmp3_register();
player_codec_beken_aac_register();
player_codec_beken_m4a_register();
player_codec_opencore_amr_register();
player_system_init();
#endif
#ifdef XIAOYA_OS
app_manage_init();
#endif
rt_hw_wdg_start(0,NULL);
return 0;
}
#ifdef BEKEN_USING_WLAN
extern void ate_app_init(void);
extern void ate_start(void);
static int wlan_app_init(void)
{
/* init ate mode check. */
ate_app_init();
if (get_ate_mode_state())
{
rt_kprintf("\r\n\r\nEnter automatic test mode...\r\n\r\n");
finsh_set_echo(0);
finsh_set_prompt("#");
ate_start();
}
else
{
rt_kprintf("Enter normal mode...\r\n\r\n");
app_start();
//iic_bus_attach();
temperature_init();
}
return 0;
}
#endif