Stair56E UART project
This commit is contained in:
@@ -0,0 +1,773 @@
|
||||
/*!
|
||||
* \file main.c
|
||||
*
|
||||
* \brief Target main implementation
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------------------------------
|
||||
INCLUDE HEADE FILES
|
||||
------------------------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Macros
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Variables
|
||||
-------------------------------------------------------------------------------------*/
|
||||
bool rf_timer_flag = false;
|
||||
uint32_t send_cnt = 0;
|
||||
|
||||
uint8_t rx_len, tx_len;
|
||||
uint32_t rx_cnt = 0;
|
||||
uint32_t tx_cnt = 0;
|
||||
uint8_t tx_buff[256] = {0};
|
||||
uint8_t rx_buff[256] = {0};
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Func Prototype
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Functions
|
||||
-------------------------------------------------------------------------------------*/
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief
|
||||
*
|
||||
* @param[in]
|
||||
* @param[in]
|
||||
****************************************************************************************
|
||||
*/
|
||||
void timer_init(uint8_t timer_id)
|
||||
{
|
||||
/* Timer for sleep-wake*/
|
||||
Timer_InitCfg_t timer_cfg;
|
||||
|
||||
timer_cfg.timer_src_clk = TIMER_CLK_SRC_32K;
|
||||
timer_cfg.timer_div_clk = TIMER_DIV_CLK_32000Hz;
|
||||
timer_cfg.timer_mode = TIMER_MODE_SINGLE;
|
||||
|
||||
xc_timer_init(timer_id, &timer_cfg);
|
||||
}
|
||||
|
||||
void timer_start(uint8_t timer_id, uint32_t timer_cnt)
|
||||
{
|
||||
uint32_t timerx_us = timer_cnt * 1000;
|
||||
xc_timer_set_value(timer_id, timerx_us);
|
||||
xc_timer_start(timer_id);
|
||||
}
|
||||
|
||||
void timer_stop(uint8_t timer_id)
|
||||
{
|
||||
xc_timer_stop(timer_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief timer0_Callback
|
||||
* @param void * - context
|
||||
*
|
||||
* @retval void
|
||||
*/
|
||||
void timer0_callback(void *context)
|
||||
{
|
||||
rf_timer_flag = true;
|
||||
}
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Clock Initialization
|
||||
*
|
||||
* @param[in]
|
||||
* @param[in]
|
||||
****************************************************************************************
|
||||
*/
|
||||
void clock_init(void)
|
||||
{
|
||||
CLOCK_InitCfg_t clock_cfg;
|
||||
|
||||
clock_cfg.hfclk_src = CLOCK_HFCLK_SRC_XTAL;
|
||||
clock_cfg.hfclk_in = CLOCK_HFCLK_IN_32M;
|
||||
#if (RC_32K)
|
||||
clock_cb.lfclk_src = CLOCK_LFCLK_SRC_RC;
|
||||
#endif //(RC_32K)
|
||||
|
||||
#if (XTAL_32K)
|
||||
clock_cb.lfclk_src = CLOCK_LFCLK_SRC_XTAL;
|
||||
#endif // (XTAL_32K)
|
||||
|
||||
#if (XTAL_32768K)
|
||||
clock_cb.lfclk_src = CLOCK_LFCLK_SRC_XTAL;
|
||||
#endif // (XTAL_32768K)
|
||||
|
||||
#ifdef XC62XX
|
||||
clock_cb.lfclk_src = CLOCK_LFCLK_SRC_RC;
|
||||
clock_cfg.lfclk_in = CLOCK_LFCLK_IN_32K;
|
||||
#else
|
||||
if (clock_cfg.lfclk_src == CLOCK_LFCLK_SRC_XTAL) {
|
||||
clock_cfg.lfclk_in = CLOCK_LFCLK_IN_32768;
|
||||
} else if (clock_cfg.lfclk_src == CLOCK_LFCLK_SRC_RC) {
|
||||
clock_cfg.lfclk_in = CLOCK_LFCLK_IN_32K;
|
||||
}
|
||||
#endif
|
||||
xc_clock_init_cfg(&clock_cfg);
|
||||
|
||||
SysTick_Config(xc_clock_hfclk_in_get() / 100);
|
||||
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
/**
|
||||
* @brief RF 2.4g register information printing
|
||||
* @param void
|
||||
* @retval void
|
||||
*/
|
||||
void rf_2M_reg_info(void)
|
||||
{
|
||||
/* Register information printing */
|
||||
LOGI("CFG_TOP: 0x%08x\r\n", XC_RF_2_4G->CFG_TOP);
|
||||
LOGI("TXPROC_CFG: 0x%08x\r\n", XC_RF_2_4G->TXPROC_CFG);
|
||||
LOGI("RXPROC_CFG_L: 0x%08x\r\n", XC_RF_2_4G->RXPROC_CFG_L);
|
||||
LOGI("RF_CH: 0x%08x\r\n", XC_RF_2_4G->RF_CH);
|
||||
LOGI("rccal_reg_l: 0x%08x\r\n", XC_BT_RF->rccal_reg_l);
|
||||
LOGI("ana2_reg_l: 0x%08x\r\n", XC_BT_RF->ana2_reg_l);
|
||||
LOGI("ana3_reg_l: 0x%08x\r\n", XC_BT_RF->ana3_reg_l);
|
||||
LOGI("ana4_reg_l: 0x%08x\r\n", XC_BT_RF->ana4_reg_l);
|
||||
LOGI("ana5_reg_l: 0x%08x\r\n", XC_BT_RF->ana5_reg_l);
|
||||
LOGI("ana14_reg_l: 0x%08x\r\n", XC_BT_RF->ana14_reg_l);
|
||||
LOGI("ana15_reg_l: 0x%08x\r\n", XC_BT_RF->ana15_reg_l);
|
||||
LOGI("ana16_reg_l: 0x%08x\r\n", XC_BT_RF->ana16_reg_l);
|
||||
LOGI("ana17_reg_l: 0x%08x\r\n", XC_BT_RF->ana17_reg_l);
|
||||
LOGI("ana18_reg_l: 0x%08x\r\n", XC_BT_RF->ana18_reg_l);
|
||||
LOGI("ana21_reg_l: 0x%08x\r\n", XC_BT_RF->ana21_reg_l);
|
||||
LOGI("AON_RF_AONREG: 0x%08x\r\n", cprao_aon_rf_aonreg_get()); // 0x36
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rf 2.4g dump log
|
||||
* @param void
|
||||
*
|
||||
* @retval void
|
||||
*/
|
||||
void rf_dump_log(void)
|
||||
{
|
||||
LOGI("***************** 2.4G Param ******************\n");
|
||||
LOGI("CFG_TOP: 0x%08x\r\n", XC_RF_2_4G->CFG_TOP);
|
||||
LOGI("EN_AA: 0x%08x\r\n", XC_RF_2_4G->EN_AA);
|
||||
LOGI("EN_RXADDR: 0x%08x\r\n", XC_RF_2_4G->EN_RXADDR);
|
||||
LOGI("SETUP_AW: 0x%08x\r\n", XC_RF_2_4G->SETUP_AW);
|
||||
LOGI("SETUP_RETR: 0x%08x\r\n", XC_RF_2_4G->SETUP_RETR);
|
||||
LOGI("RF_CH: 0x%08x\r\n", XC_RF_2_4G->RF_CH);
|
||||
LOGI("SETUP_RF: 0x%08x\r\n", XC_RF_2_4G->SETUP_RF);
|
||||
LOGI("STATUS: 0x%08x\r\n", XC_RF_2_4G->STATUS);
|
||||
LOGI("OBSERVE_TX: 0x%08x\r\n", XC_RF_2_4G->OBSERVE_TX);
|
||||
LOGI("RSSI: 0x%08x\r\n", XC_RF_2_4G->RSSI);
|
||||
LOGI("RX_ADDR_P0: 0x%02x %08x\r\n", 0xFF & (XC_RF_2_4G->RX_ADDR_P0_H), XC_RF_2_4G->RX_ADDR_P0_L);
|
||||
LOGI("RX_ADDR_P1: 0x%02x %08x\r\n", 0xFF & (XC_RF_2_4G->RX_ADDR_P1_H), XC_RF_2_4G->RX_ADDR_P1_L);
|
||||
LOGI("RX_ADDR_P2TOP5:0x%08x\r\n", XC_RF_2_4G->RX_ADDR_P2TOP5);
|
||||
LOGI("BER_RESULT: 0x%08x%08x\r\n", XC_RF_2_4G->BER_ERR_CNT, XC_RF_2_4G->BER_RECV_CNT);
|
||||
LOGI("AGC_SETTING: 0x%08x\r\n", XC_RF_2_4G->AGC_SETTING);
|
||||
LOGI("PGA_SETTING: 0x%02x %08x\r\n", ((XC_RF_2_4G->TX_ADDR_H) & 0xFF00) >> 8, XC_RF_2_4G->PGA_SETTING);
|
||||
LOGI("TX_ADDR: 0x%02x %08x\r\n", ((XC_RF_2_4G->TX_ADDR_H) & 0xFF), XC_RF_2_4G->TX_ADDR_L);
|
||||
LOGI("RX_PW_PX: 0x%04x %08x\r\n", 0xFFFF & (XC_RF_2_4G->RX_PW_Px_H), XC_RF_2_4G->RX_PW_Px_L);
|
||||
LOGI("STATUS_FIFO: 0x%08x\r\n", XC_RF_2_4G->STATUS_FIFO);
|
||||
LOGI("RSSIREC: 0x%08x\r\n", XC_RF_2_4G->RSSIREC);
|
||||
LOGI("TXPROC_CFG: 0x%08x\r\n", XC_RF_2_4G->TXPROC_CFG);
|
||||
LOGI("RXPROC_CFG: 0x%02x %08x\r\n", 0xFF & (XC_RF_2_4G->RXPROC_CFG_H), XC_RF_2_4G->RXPROC_CFG_L);
|
||||
LOGI("DYNPD: 0x%08x\r\n", XC_RF_2_4G->DYNPD);
|
||||
LOGI("FEATURE: 0x%08x\r\n", XC_RF_2_4G->FEATURE);
|
||||
LOGI("PGA_SETTING_H: 0x%08x\r\n", XC_RF_2_4G->TX_ADDR_H);
|
||||
LOGI("TX_POWER 0x%08x\r\n", (XC_BT_RF->ana21_reg_l >> 6) & 0x3f);
|
||||
LOGI("ana11_reg_l: 0x%08x\r\n", XC_BT_RF->ana11_reg_l);
|
||||
LOGI("***********************************************\n");
|
||||
LOGI("\r\n");
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
/**
|
||||
* @brief RF 2.4g data init
|
||||
* @param uint8_t * - buff
|
||||
* uint8 - len
|
||||
* @retval uint8_t - 0
|
||||
*/
|
||||
uint8_t rf_data_init(uint8_t *buff,uint16_t len)
|
||||
{
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
buff[i] = i;
|
||||
}
|
||||
return RF_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RF 2.4g tx manage
|
||||
* @param rf_data_typedef_t * - rf_data
|
||||
* @retval uint8_t - cnt
|
||||
*/
|
||||
void rf_tx_manage(void)
|
||||
{
|
||||
//if ((send_cnt < XC_SEND_NUM)) {
|
||||
rf_timer_flag = false;
|
||||
send_cnt += 1;
|
||||
/* Filling in software frame number */
|
||||
tx_buff[0] = send_cnt;
|
||||
|
||||
LOGI("send_cnt:%d\r\n", send_cnt);
|
||||
|
||||
rf_buff_info(tx_buff,tx_len);
|
||||
|
||||
/* data transmission */
|
||||
rf_tx_packet(tx_buff, tx_len);
|
||||
delay_ms(2);
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RF 2.4g rx manage
|
||||
* @param rf_data_typedef_t * - rf_data
|
||||
* @retval uint32_t - 0
|
||||
*/
|
||||
|
||||
#if !(XINCX_RF_NVIC_MODE)
|
||||
bool rf_rx_manage(void)
|
||||
{
|
||||
static uint32_t conut = 0;
|
||||
/* Receive event processing */
|
||||
uint8_t len = rf_rx_event(rx_buff);
|
||||
|
||||
/* Receiving end polling data processing */
|
||||
if (len != 0) {
|
||||
/* Entering standby mode */
|
||||
CE_CTL_LOW;
|
||||
|
||||
/* Receiving data processing */
|
||||
if (rx_buff[RF_CONFIRMED_VALUE] == RF_CONFIRMED_VALUE) {
|
||||
LOGI("%d\r\n", conut);
|
||||
}
|
||||
|
||||
rf_buff_info(rx_buff, len);
|
||||
/* Receive Count */
|
||||
conut += 1;
|
||||
|
||||
/* Receive read data buffer reset */
|
||||
memset(rx_buff, 0, len);
|
||||
len = 0;
|
||||
|
||||
/* Entering the receiver */
|
||||
CE_CTL_HIGH;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
bool rf_rx_manage(void)
|
||||
{
|
||||
static uint32_t conut = 0;
|
||||
if (rf24g_rx_irq_flag) {
|
||||
uint8_t len = recv_len;
|
||||
rf24g_rx_irq_flag = false;
|
||||
/* Entering standby mode */
|
||||
CE_CTL_LOW;
|
||||
|
||||
if ((len != 0) && (recv_buf[RF_CONFIRMED_VALUE] == RF_CONFIRMED_VALUE)) {
|
||||
LOGI("%d\r\n", recv_buf[0]);
|
||||
}
|
||||
rf_buff_info(recv_buf, len);
|
||||
/* Receive Count */
|
||||
conut += 1;
|
||||
LOGI("recv:%d\r\n", conut);
|
||||
|
||||
/* Receive read data buffer reset */
|
||||
memset(recv_buf, 0, len);
|
||||
len = 0;
|
||||
|
||||
/* Entering the receiver */
|
||||
CE_CTL_HIGH;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif //!(XINCX_RF_NVIC_MODE)
|
||||
|
||||
/**
|
||||
* @brief RF 2.4g buff info
|
||||
* @param uint8_t * - buff
|
||||
* uint8_t len
|
||||
* @retval void
|
||||
*/
|
||||
void rf_buff_info(uint8_t *buff, uint8_t len)
|
||||
{
|
||||
for (uint8_t i = 0; i < len; i++)
|
||||
LOGI("%02x ", buff[i]);
|
||||
LOGI("\r\n");
|
||||
}
|
||||
|
||||
void app_uart_init(void)
|
||||
{
|
||||
GPIO_InitCfg_t gpio_cfg = {0};
|
||||
|
||||
gpio_cfg.Mux = GPIO_Mux0;
|
||||
gpio_cfg.Pull = GPIO_PULLUP;
|
||||
gpio_cfg.Int = NOT_INT;
|
||||
gpio_cfg.FunSel = UART0_TX;
|
||||
|
||||
gpio_cfg.Pin = GPIO_18;
|
||||
gpio_cfg.Dir = GPIO_DIR_OUTPUT;
|
||||
xc_gpio_init(&gpio_cfg);
|
||||
|
||||
gpio_cfg.FunSel = UART0_RX;
|
||||
gpio_cfg.Pin = GPIO_19;
|
||||
gpio_cfg.Dir = GPIO_DIR_INPUT;
|
||||
xc_gpio_init(&gpio_cfg);
|
||||
|
||||
UART_InitCfg_t uart_cfg = {0};
|
||||
|
||||
uart_cfg.Parity = UART_PARITY_DISABLE;
|
||||
uart_cfg.StopBits = UART_STOP_1_BITS;
|
||||
uart_cfg.WordLength = UART_DATA_8_BITS;
|
||||
uart_cfg.BaudRate = UART_BAUDRATE_115200;
|
||||
uart_cfg.HardwareFlowControl = UART_HWFC_DISABLE;
|
||||
|
||||
xc_uart_init(UART0_IDX, &uart_cfg);
|
||||
}
|
||||
|
||||
static void system_sleep_init()
|
||||
{
|
||||
uint32_t wake_it_src;
|
||||
#if (USE_XIP == 1)
|
||||
#if (USE_ROM_FLASH)
|
||||
FMC_SPI_Init_Oprt();
|
||||
#else // (USE_ROM_FLASH)
|
||||
xc_fmc_spi_init_oprt();
|
||||
#endif // (USE_ROM_FLASH)
|
||||
#endif
|
||||
|
||||
#if (USE_XIP != 1)
|
||||
SPI_InitCfg_t spi_cfg = {0};
|
||||
spi_cfg.Mode = SPI_MODE_MASTER;
|
||||
spi_cfg.DataSize = SSI_CTRL0_DFS_LEN_8BIT;
|
||||
spi_cfg.Direction = SSI_CTRL0_TMOD_WR;
|
||||
spi_cfg.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
||||
spi_cfg.CLKPolarity = SSI_CTRL0_SCPOL_LOW;
|
||||
spi_cfg.CLKPhase = SPI_CPHA_LEAD;
|
||||
spi_cfg.FirstBit = SPI_FirstBit_MSB;
|
||||
|
||||
xc_spi_init(XC_SPI0, &spi_cfg);
|
||||
SPI_Flash_PowerDown(XC_SPI0);
|
||||
#endif
|
||||
xc_pwr_gpio_sleep_config();
|
||||
wake_it_src = GPIO_IRQn_WAKE | RTC_IRQn_WAKE|TIMER_AO0_IRQn_WAKE| TIMER0_IRQn_WAKE | MPU_IRQn_WAKE;
|
||||
xc_pwr_wake_it_set(wake_it_src);
|
||||
}
|
||||
|
||||
static void system_lightsleep_cfg()
|
||||
{
|
||||
#if (USE_XIP != 1)
|
||||
cprao_aon_puctrl1_set(0x4); /* puctrl1= 0x4 , SSI0RX must pulldown*/
|
||||
#endif
|
||||
cprao_aon_sys_time_set((RST_READY_TIME << 12) | (OSC32_STABLE_TIME));
|
||||
|
||||
xc_pwr_pd_lightsleep_set();
|
||||
xc_pwr_sleepsrc_mask_set(0x1e001e);
|
||||
xc_pwr_osc_off();
|
||||
}
|
||||
|
||||
void system_deepsleep_cfg()
|
||||
{
|
||||
#if (USE_XIP!=1)
|
||||
cprao_aon_puctrl1_set(0xf);
|
||||
#endif
|
||||
cprao_aon_sys_time_set((RST_READY_TIME<<12) | (OSC32_STABLE_TIME));
|
||||
xc_pwr_pd_deepsleep_set();
|
||||
delay_us(100);
|
||||
xc_pwr_sleepsrc_mask_set(0x1e001e);
|
||||
xc_pwr_osc_off();
|
||||
}
|
||||
|
||||
void DeepSleep_Demo()
|
||||
{
|
||||
|
||||
system_sleep_init();
|
||||
// PWRKEY Initialization is required after deep sleep wakeup
|
||||
xc_pwr_pwrkey_init();
|
||||
xc_pwr_pwrkey_deepsleep_wake_config(GPIO_2, DEEP_SLEEP_GPIO_WAKE_HIGH_LEVEL);
|
||||
xc_pwr_pwrkey_deepsleep_wake_config(GPIO_3, DEEP_SLEEP_GPIO_WAKE_LOW_LEVEL);
|
||||
system_deepsleep_cfg();
|
||||
|
||||
while(1)
|
||||
{
|
||||
xc_deep_sleep();
|
||||
}
|
||||
}
|
||||
|
||||
static void sleep_init(void)
|
||||
{
|
||||
system_sleep_init();
|
||||
system_lightsleep_cfg();
|
||||
/* Timer for sleep-wake*/
|
||||
Timer_InitCfg_t timer_cfg;
|
||||
|
||||
timer_cfg.timer_src_clk = TIMER_CLK_SRC_32K;
|
||||
timer_cfg.timer_div_clk = TIMER_DIV_CLK_32000Hz;
|
||||
timer_cfg.timer_mode = TIMER_MODE_SINGLE;
|
||||
|
||||
xc_timer_init(TIMER0_IDX, &timer_cfg);
|
||||
}
|
||||
|
||||
void xc_adc_powerdown(void);
|
||||
void xc_adc_wakeup(void);
|
||||
void xc_rc32k_soft_calib_disable(void);
|
||||
void xc_rc32k_soft_calib_enable(void);
|
||||
|
||||
void wakeup_timer_set(uint32_t time)
|
||||
{
|
||||
cprao_aon_reg1__timer_ao_sleep_clksw__setf(0);
|
||||
|
||||
AOTimer_InitCfg_t aotimer_cfg;
|
||||
aotimer_cfg.aotimer_mode = AOTIMER_MODE_CYCLE;
|
||||
|
||||
// Timer0 Config & Start
|
||||
xc_aotimer_init(AOTIMER0_IDX, &aotimer_cfg);
|
||||
xc_aotimer_set_value(AOTIMER0_IDX, time);
|
||||
xc_aotimer_start(AOTIMER0_IDX);
|
||||
|
||||
}
|
||||
|
||||
__RAM_CODE void xc_mcu_sleep(void)
|
||||
{
|
||||
xc_adc_powerdown();
|
||||
xc_pwr_usb_off();
|
||||
xc_pwr_rc16m_off();
|
||||
|
||||
xc_pwr_rc32k_calib_off();
|
||||
|
||||
xc_pwr_opa_tempsensor_off();
|
||||
xc_pwr_opa_volr_off();
|
||||
xc_pwr_revddldo_off();
|
||||
|
||||
xc_pwr_dcdc_close();
|
||||
xc_pwr_rfdigital_off();
|
||||
xc_pwr_rc32k_calib_off();
|
||||
cprao_aon_reg4__bb_coreldo_normal_sw_mux__setf(1);
|
||||
xc_pwr_modem_off();
|
||||
xc_pwr_pd_lightsleep_set();
|
||||
|
||||
#if (USE_XIP == 1)
|
||||
|
||||
#if (USE_ROM_FLASH)
|
||||
FMC_SPI_Flash_PowerDown();
|
||||
#else // (USE_ROM_FLASH)
|
||||
// xc_fmc_spi_flash_power_down();
|
||||
#endif // (USE_ROM_FLASH)
|
||||
xc_pwr_rom_off();
|
||||
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
// cpr_fmc_ctl_set(0x3000 | (1 << 9)); // close FMC
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
}
|
||||
#endif
|
||||
|
||||
// __disable_irq();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
|
||||
__WFI();
|
||||
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
|
||||
// cpr_fmc_ctl_set(0x3503);
|
||||
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
|
||||
xc_pwr_rom_on();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
}
|
||||
#if (USE_ROM_FLASH)
|
||||
FMC_SPI_Flash_WakeUp();
|
||||
#else // (USE_ROM_FLASH)
|
||||
// xc_fmc_spi_flash_wake_up();
|
||||
#endif // (USE_ROM_FLASH)
|
||||
|
||||
xc_pwr_ao_timer_pclk32m_Set();
|
||||
|
||||
// __enable_irq();
|
||||
|
||||
#ifdef USED_DCDC
|
||||
xc_pwr_dcdc_open();
|
||||
#endif
|
||||
|
||||
xc_pwr_modem_on();
|
||||
|
||||
xc_pwr_rfdigital_on();
|
||||
|
||||
xc_adc_wakeup();
|
||||
}
|
||||
|
||||
void Sleep_Demo()
|
||||
{
|
||||
uint32_t duration_timer = (500*1000); //500ms
|
||||
|
||||
xc_rc32k_calib_by_soft();
|
||||
sleep_init();
|
||||
|
||||
xc_fmc_spi_init_oprt();
|
||||
xc_fmc_spi_flash_wake_up();
|
||||
|
||||
while(1){
|
||||
// Checks for sleep have to be done with interrupt disabled
|
||||
GLOBAL_INT_DISABLE();
|
||||
xc_timer_set_value(TIMER0_IDX, duration_timer);
|
||||
xc_timer_start(TIMER0_IDX);
|
||||
|
||||
// Before you sleep, turn off the peripheral to make sure it doesn't generate interrupts,
|
||||
// and then turn it on again after you sleep up.
|
||||
// For example, timer interrupts
|
||||
|
||||
xc_rc32k_soft_calib_disable();
|
||||
|
||||
xc_mcu_sleep();
|
||||
|
||||
xc_timer_stop(TIMER0_IDX);
|
||||
xc_rc32k_soft_calib_enable();
|
||||
|
||||
GLOBAL_INT_RESTORE();
|
||||
// The delay can be omitted, rc32k will calibrate every time it wakes up, and it takes 2ms.
|
||||
delay_ms(3);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief main
|
||||
* @details
|
||||
* @param[in] void
|
||||
* @param[out] void
|
||||
* @retval int - 0
|
||||
* @retval void
|
||||
* @par identifier
|
||||
* reserve
|
||||
* @par other
|
||||
* void
|
||||
* @par change log
|
||||
* Alex created on 2023-05-31
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
|
||||
tx_len = BUFF_LEN;
|
||||
/* Clock initialization */
|
||||
clock_init();
|
||||
|
||||
|
||||
/* Serial port initialization */
|
||||
app_uart_init();
|
||||
|
||||
|
||||
#if SLEEP_DEMO == SLEEP_MODE
|
||||
xc_rc32k_calib_by_soft();
|
||||
system_sleep_init();
|
||||
system_lightsleep_cfg();
|
||||
xc_fmc_spi_init_oprt();
|
||||
xc_fmc_spi_flash_wake_up();
|
||||
#elif DEEPSLEEP_DEMO == SLEEP_MODE
|
||||
system_sleep_init();
|
||||
xc_pwr_pwrkey_init();
|
||||
system_deepsleep_cfg();
|
||||
#else
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* rf 2.4g initialization configuration */
|
||||
rf24g_init();
|
||||
|
||||
/* Set testing frequency points */
|
||||
rf_set_channel(XINCX_2_4G_CHANNEL);
|
||||
|
||||
#if (XINCX_RF_TRANS_RATE == DR_2M)
|
||||
/* Set 2M mode register configuration */
|
||||
/* Don't move this function interface */
|
||||
rf_2M_config();
|
||||
#endif //(XINCX_RF_TRANS_RATE == DR_2M)
|
||||
|
||||
#if (XINCX_RF_NVIC_MODE)
|
||||
/* Enable RF2.4G interrupts */
|
||||
NVIC_EnableIRQ(RF24G_IRQn);
|
||||
/* Configure the RF2.4G interrupt priority */
|
||||
NVIC_SetPriority(RF24G_IRQn, 0);
|
||||
#endif // XINCX_RF_NVIC_MODE
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
#if DEEPSLEEP_DEMO != SLEEP_MODE
|
||||
/* Register information printing */
|
||||
rf_dump_log();
|
||||
#endif
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
#if XINCX_RF_MODE
|
||||
/* Set emission interval */
|
||||
timer_init(RF_RX_TIMERx);
|
||||
|
||||
/* RX enters receiver */
|
||||
CE_CTL_HIGH;
|
||||
#else
|
||||
|
||||
/* Set emission interval */
|
||||
timer_init(RF_TX_TIMERx);
|
||||
|
||||
#endif // XINCX_RF_MODE
|
||||
for (;;) {
|
||||
|
||||
#if XINCX_RF_MODE
|
||||
|
||||
rf_timer_flag = false;
|
||||
/* timer start */
|
||||
timer_start(RF_RX_TIMERx, RECV_TIME_OUT);
|
||||
|
||||
while(rf_timer_flag == false)
|
||||
{
|
||||
/* receive */
|
||||
if(rf_rx_manage())
|
||||
{
|
||||
timer_stop(RF_RX_TIMERx);
|
||||
rf_timer_flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CE_CTL_LOW;
|
||||
#if SLEEP_DEMO == SLEEP_MODE
|
||||
// Checks for sleep have to be done with interrupt disabled
|
||||
GLOBAL_INT_DISABLE();
|
||||
|
||||
/* timer start */
|
||||
timer_start(RF_RX_TIMERx, RECV_SLEEP_DURATION);
|
||||
|
||||
xc_rc32k_soft_calib_disable();
|
||||
|
||||
xc_mcu_sleep();
|
||||
|
||||
xc_timer_stop(RF_RX_TIMERx);
|
||||
xc_rc32k_soft_calib_enable();
|
||||
delay_us(200);
|
||||
|
||||
GLOBAL_INT_RESTORE();
|
||||
#elif DEEPSLEEP_DEMO == SLEEP_MODE
|
||||
|
||||
wakeup_timer_set(RECV_DEEPSLEEP_DURATION*1000);
|
||||
xc_deep_sleep();
|
||||
#else
|
||||
rf_timer_flag = false;
|
||||
/* timer start */
|
||||
timer_start(RF_RX_TIMERx, RECV_NOSLEEP_DURATION);
|
||||
while(rf_timer_flag == false)
|
||||
{
|
||||
|
||||
}
|
||||
#endif /* SLEEP MODE */
|
||||
|
||||
CE_CTL_HIGH;
|
||||
|
||||
#else /* XINCX_RF_MODE */
|
||||
/* Launch data packaging filling */
|
||||
rf_data_init(tx_buff,tx_len);
|
||||
|
||||
/* sending */
|
||||
rf_tx_manage();
|
||||
|
||||
#if SLEEP_DEMO == SLEEP_MODE
|
||||
// Checks for sleep have to be done with interrupt disabled
|
||||
GLOBAL_INT_DISABLE();
|
||||
|
||||
/* timer start */
|
||||
timer_start(RF_TX_TIMERx, SEND_INTERVAL_SLEEP);
|
||||
|
||||
xc_rc32k_soft_calib_disable();
|
||||
|
||||
xc_mcu_sleep();
|
||||
|
||||
xc_timer_stop(RF_TX_TIMERx);
|
||||
xc_rc32k_soft_calib_enable();
|
||||
|
||||
GLOBAL_INT_RESTORE();
|
||||
#elif DEEPSLEEP_DEMO == SLEEP_MODE
|
||||
wakeup_timer_set(SEND_INTERVAL_DEEPSLEEP*1000);
|
||||
xc_deep_sleep();
|
||||
#else
|
||||
/* timer start */
|
||||
timer_start(RF_TX_TIMERx, SEND_INTERVAL_NOSLEEP);
|
||||
|
||||
while(rf_timer_flag == false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
rf_timer_flag = false;
|
||||
#endif /* SLEEP MODE */
|
||||
|
||||
#endif // XINCX_RF_MODE
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user