-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.c
202 lines (156 loc) · 6.26 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**************************************************************************************************
Phyplus Microelectronics Limited confidential and proprietary.
All rights reserved.
IMPORTANT: All rights of this software belong to Phyplus Microelectronics
Limited ("Phyplus"). Your use of this Software is limited to those
specific rights granted under the terms of the business contract, the
confidential agreement, the non-disclosure agreement and any other forms
of agreements as a customer or a partner of Phyplus. You may not use this
Software unless you agree to abide by the terms of these agreements.
You acknowledge that the Software may not be modified, copied,
distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
(BLE) integrated circuit, either as a product or is integrated into your
products. Other than for the aforementioned purposes, you may not use,
reproduce, copy, prepare derivative works of, modify, distribute, perform,
display or sell this Software and/or its documentation for any purposes.
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
**************************************************************************************************/
#include "bus_dev.h"
#include "gpio.h"
#include "clock.h"
#include "timer.h"
#include "jump_function.h"
#include "pwrmgr.h"
#include "mcu.h"
#include "gpio.h"
#include "rf_phy_driver.h"
#include "flash.h"
#include "version.h"
#define DEFAULT_UART_BAUD 115200
/*********************************************************************
LOCAL FUNCTION PROTOTYPES
*/
/*********************************************************************
EXTERNAL FUNCTIONS
*/
extern void init_config(void);
extern int app_main(void);
extern void hal_rom_boot_init(void);
/*********************************************************************
OSAL LARGE HEAP CONFIG
*/
#define LARGE_HEAP_SIZE (1*1024)
ALIGN4_U8 g_largeHeap[LARGE_HEAP_SIZE];
/*********************************************************************
GLOBAL VARIABLES
*/
volatile uint8 g_clk32K_config;
volatile sysclk_t g_spif_clk_config;
/*********************************************************************
EXTERNAL VARIABLES
*/
extern uint32_t __initial_sp;
static void hal_low_power_io_init(void)
{
//========= pull all io to gnd by default
ioinit_cfg_t ioInit[]=
{
//TSOP6252 10 IO
{GPIO_P02, GPIO_FLOATING },/*SWD*/
{GPIO_P03, GPIO_FLOATING },/*SWD*/
{GPIO_P09, GPIO_FLOATING },/*UART TX*/
{GPIO_P10, GPIO_FLOATING },/*UART RX*/
{GPIO_P11, GPIO_FLOATING },
{GPIO_P14, GPIO_FLOATING },
{GPIO_P15, GPIO_FLOATING },
{GPIO_P16, GPIO_FLOATING },
{GPIO_P18, GPIO_FLOATING },
{GPIO_P20, GPIO_FLOATING },
#if(SDK_VER_CHIP==__DEF_CHIP_QFN32__)
//6222 23 IO
{GPIO_P00, GPIO_PULL_DOWN },
{GPIO_P01, GPIO_PULL_DOWN },
{GPIO_P07, GPIO_PULL_DOWN },
{GPIO_P17, GPIO_FLOATING },/*32k xtal*/
{GPIO_P23, GPIO_PULL_DOWN },
{GPIO_P24, GPIO_PULL_DOWN },
{GPIO_P25, GPIO_PULL_DOWN },
{GPIO_P26, GPIO_PULL_DOWN },
{GPIO_P27, GPIO_PULL_DOWN },
{GPIO_P31, GPIO_PULL_DOWN },
{GPIO_P32, GPIO_PULL_DOWN },
{GPIO_P33, GPIO_PULL_DOWN },
{GPIO_P34, GPIO_PULL_DOWN },
#endif
};
for(uint8_t i=0; i<sizeof(ioInit)/sizeof(ioinit_cfg_t); i++)
hal_gpio_pull_set(ioInit[i].pin,ioInit[i].type);
DCDC_CONFIG_SETTING(0x0a);
DCDC_REF_CLK_SETTING(1);
DIG_LDO_CURRENT_SETTING(0x01);
hal_pwrmgr_RAM_retention(RET_SRAM0);
hal_pwrmgr_RAM_retention_set();
hal_pwrmgr_LowCurrentLdo_enable();
}
static void ble_mem_init_config(void)
{
osal_mem_set_heap((osalMemHdr_t*)g_largeHeap, LARGE_HEAP_SIZE);
}
static void hal_rfphy_init(void)
{
//============config the txPower
g_rfPhyTxPower = RF_PHY_TX_POWER_N2DBM ;
//============config BLE_PHY TYPE
g_rfPhyPktFmt = PKT_FMT_BLE1M;
//============config RF Frequency Offset
g_rfPhyFreqOffSet =RF_PHY_FREQ_FOFF_00KHZ;
//============config xtal 16M cap
XTAL16M_CAP_SETTING(0x09);
XTAL16M_CURRENT_SETTING(0x01);
hal_rom_boot_init();
NVIC_SetPriority((IRQn_Type)BB_IRQn, IRQ_PRIO_REALTIME);
NVIC_SetPriority((IRQn_Type)TIM1_IRQn, IRQ_PRIO_HIGH); //ll_EVT
NVIC_SetPriority((IRQn_Type)TIM2_IRQn, IRQ_PRIO_HIGH); //OSAL_TICK
NVIC_SetPriority((IRQn_Type)TIM4_IRQn, IRQ_PRIO_HIGH); //LL_EXA_ADV
//ble memory init and config
ble_mem_init_config();
}
static void hal_init(void)
{
hal_low_power_io_init();
clk_init(g_system_clk); //system init
hal_rtc_clock_config((CLK32K_e)g_clk32K_config);
hal_pwrmgr_init();
xflash_Ctx_t cfg =
{
.spif_ref_clk = SYS_CLK_RC_32M,
.rd_instr = XFRD_FCMD_READ_DUAL
};
hal_spif_cache_init(cfg);
hal_gpio_init();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
int main(void)
{
g_system_clk = SYS_CLK_XTAL_16M;//SYS_CLK_XTAL_16M;//SYS_CLK_DLL_64M;
g_clk32K_config = CLK_32K_RCOSC;//CLK_32K_XTAL;//CLK_32K_XTAL,CLK_32K_RCOSC
drv_irq_init();
init_config();
hal_rfphy_init();
hal_init();
#if(_BUILD_FOR_DTM_==1)
rf_phy_direct_test();
#endif
app_main();
}
///////////////////////////////////// end ///////////////////////////////////////