Stair56E UART project
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
/**************************************************************************************************
|
||||
|
||||
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.
|
||||
|
||||
**************************************************************************************************/
|
||||
|
||||
/**************************************************************************************************
|
||||
INCLUDES
|
||||
**************************************************************************************************/
|
||||
#include "OSAL.h"
|
||||
#include "OSAL_Tasks.h"
|
||||
#include "hal_assert.h"
|
||||
#include "OSAL_PwrMgr.h"
|
||||
#include "xc6xxx.h"
|
||||
#include "hal_timer.h"
|
||||
|
||||
/* Application */
|
||||
#include "rf24_adv_demo.h"
|
||||
|
||||
/*********************************************************************
|
||||
GLOBAL VARIABLES
|
||||
*/
|
||||
|
||||
// The order in this table must be identical to the task initialization calls below in osalInitTask.
|
||||
__RAM_CODE const pTaskEventHandlerFn tasksArr[] =
|
||||
{
|
||||
RF24_ADV_ProcessEvent,
|
||||
};
|
||||
|
||||
__RAM_CODE const uint8_t tasksCnt = sizeof(tasksArr) / sizeof(tasksArr[0]);
|
||||
uint16_t *tasksEvents;
|
||||
|
||||
/*********************************************************************
|
||||
FUNCTIONS
|
||||
*********************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
@fn osalInitTasks
|
||||
|
||||
@brief This function invokes the initialization function for each task.
|
||||
|
||||
@param void
|
||||
|
||||
@return none
|
||||
*/
|
||||
void osalInitTasks(void)
|
||||
{
|
||||
uint8_t taskID = 0;
|
||||
tasksEvents = (uint16_t *)osal_mem_alloc(sizeof(uint16_t) * tasksCnt);
|
||||
/* The tasksEvents allocated pointer must be valid */
|
||||
if (tasksEvents != NULL)
|
||||
{
|
||||
osal_memset(tasksEvents, 0, (sizeof(uint16_t) * tasksCnt));
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_ASSERT_FORCED();
|
||||
}
|
||||
RF24_ADV_Demo_Init(taskID++);
|
||||
}
|
||||
|
||||
void osal_main(void)
|
||||
{
|
||||
osal_timer_init();
|
||||
osal_init_system();
|
||||
#if defined(POWER_SAVING)
|
||||
osal_pwrmgr_device(PWRMGR_BATTERY);
|
||||
#endif
|
||||
osal_start_system();
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*!
|
||||
* \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"
|
||||
#include "hal_sleep.h"
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Macros
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Variables
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Func Prototype
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Functions
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
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;
|
||||
clock_cfg.lfclk_src = CLOCK_LFCLK_SRC_RC;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
xc_clock_init_cfg(&clock_cfg);
|
||||
|
||||
SysTick_Config(xc_clock_hfclk_in_get() / 100);
|
||||
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
clock_init();
|
||||
#ifdef DEBUG_ENABLE
|
||||
app_uart_init();
|
||||
#endif
|
||||
system_sleep_init();
|
||||
DEBUG("Start running the application...\n");
|
||||
extern void osal_main(void);
|
||||
osal_main();
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/*!
|
||||
* \file gpio.c
|
||||
*
|
||||
* \brief Target gpio 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 "OSAL.h"
|
||||
#include "rf24_adv_demo.h"
|
||||
#include "xc6xxx_rf_ADV.h"
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Macros
|
||||
-------------------------------------------------------------------------------------*/
|
||||
#define RF_ADV_BASE 2400U
|
||||
#define RF_ADV_CHANNEL_37 2
|
||||
#define RF_ADV_CHANNEL_38 26
|
||||
#define RF_ADV_CHANNEL_39 80
|
||||
|
||||
#define ADV_BUFF_LEN XINCX_ADV_PIPE0_LEN
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Variables
|
||||
-------------------------------------------------------------------------------------*/
|
||||
uint8_t RF24_ADV_TaskID;
|
||||
uint8_t recv_adv_buf[ADV_BUFF_LEN] = {0};
|
||||
static uint8_t rf_adv_channel[] = {RF_ADV_CHANNEL_37, RF_ADV_CHANNEL_38, RF_ADV_CHANNEL_39};
|
||||
static uint8_t adv_index;
|
||||
uint8_t data_len = 0;
|
||||
uint32_t blecrc = 0;
|
||||
uint8_t rf_adv_crc_status = CRC_IDLE;
|
||||
/*------------------------------------------------------------------------------------
|
||||
Func Prototype
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Functions
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @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("***********************************************\n");
|
||||
LOGI("\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RF ADV data package filling
|
||||
* @param uint8_t * - buff
|
||||
* uint8_t - len
|
||||
* @return uint8_t - data len
|
||||
*/
|
||||
uint8_t rf_adv_packet(uint8_t *buff)
|
||||
{
|
||||
if (sizeof(buff) > ADV_LENGTH)
|
||||
{
|
||||
buff = NULL;
|
||||
return RF_FAIL;
|
||||
}
|
||||
|
||||
uint8_t l = 0;
|
||||
|
||||
buff[l++] = 0x42;
|
||||
buff[l++] = ADV_LENGTH - 5;
|
||||
|
||||
/* Simulate Bluetooth MAC address */
|
||||
uint8_t rf_adv_mac_addr[6] = {MAC_ADDR_0, MAC_ADDR_1, MAC_ADDR_2, MAC_ADDR_3, MAC_ADDR_4, MAC_ADDR_5};
|
||||
memcpy(&buff[l], rf_adv_mac_addr, sizeof(rf_adv_mac_addr));
|
||||
l += sizeof(rf_adv_mac_addr);
|
||||
|
||||
buff[l++] = 0x02;
|
||||
buff[l++] = 0x01;
|
||||
buff[l++] = 0x06;
|
||||
|
||||
buff[l++] = ADV_LENGTH - 15;
|
||||
|
||||
// Complete Local Name
|
||||
buff[l++] = 0x09;
|
||||
|
||||
/* Simulate Bluetooth broadcast data */
|
||||
uint8_t rf_adv_data_buff[26] = {"RF-ADV-TEST-123456789BLE52"};
|
||||
memcpy(&buff[l], rf_adv_data_buff, sizeof(rf_adv_data_buff));
|
||||
l += sizeof(rf_adv_data_buff);
|
||||
|
||||
/* CRC */
|
||||
buff[l++] = 0x55;
|
||||
buff[l++] = 0x55;
|
||||
buff[l++] = 0x55;
|
||||
|
||||
return l;
|
||||
}
|
||||
/**
|
||||
* @brief Rf adv tx event
|
||||
* @param void
|
||||
*
|
||||
* @retval void
|
||||
*/
|
||||
uint8_t len = 0;
|
||||
uint8_t buff[ADV_LENGTH];
|
||||
void rf_adv_tx_evevt(void)
|
||||
{
|
||||
/* Set testing frequency points */
|
||||
rf_set_channel(RF_ADV_BASE + rf_adv_channel[adv_index]);
|
||||
|
||||
/* Simulate Bluetooth broadcast data filling */
|
||||
len = rf_adv_packet(buff);
|
||||
|
||||
/* Simulate Bluetooth broadcast package software CRC */
|
||||
ble_crc(buff, len - 3, buff + len - 3);
|
||||
|
||||
/* Simulate Bluetooth broadcast package software whitening */
|
||||
ble_whiten(buff, len, bleWhitenStart(RF_ADV_BASE + rf_adv_channel[adv_index]));
|
||||
|
||||
/* Send data processing.if you dont need delay_ms(1) that need to use rf_tx_event to send*/
|
||||
rf_tx_packet(buff, len);
|
||||
|
||||
adv_index += 1;
|
||||
if (adv_index == sizeof(rf_adv_channel)) {
|
||||
adv_index = 0;
|
||||
}
|
||||
|
||||
delay_ms(1);
|
||||
}
|
||||
|
||||
void rf_adv_rx_evevt(void)
|
||||
{
|
||||
if ((recv_len != 0) && (rf24g_handler_flag))
|
||||
{
|
||||
/* Entering standby mode */
|
||||
CE_CTL_LOW;
|
||||
rf24g_handler_flag = false;
|
||||
|
||||
/* Whitening of packet software */
|
||||
blecrc = rf_adv_packet_whiten(&data_len);
|
||||
|
||||
/* Packet software CRC judgment */
|
||||
rf_adv_crc_status = rf_adv_crc(recv_adv_buf, &data_len, blecrc);
|
||||
if (rf_adv_crc_status == CRC_OK)
|
||||
{
|
||||
/* Only after 5 bytes is valid data */
|
||||
for (uint8_t i = 0; i < data_len + 5; i++)
|
||||
LOGI("%02x ", recv_adv_buf[i]);
|
||||
LOGI("\r\n");
|
||||
}
|
||||
|
||||
memset(recv_adv_buf, 0, sizeof(recv_adv_buf));
|
||||
recv_len = 0;
|
||||
|
||||
/* Entering the receiver */
|
||||
CE_CTL_HIGH;
|
||||
}
|
||||
}
|
||||
|
||||
void RF24_ADV_Demo_Init(uint8_t task_id)
|
||||
{
|
||||
RF24_ADV_TaskID = task_id;
|
||||
LOGI("rf24 adv demo init\n");
|
||||
|
||||
/* Simulate broadcast initialization */
|
||||
rf24g_adv_init();
|
||||
|
||||
/* Register information printing */
|
||||
rf_dump_log();
|
||||
|
||||
#if XINCX_ADV_MODE==1
|
||||
/* Set testing frequency points */
|
||||
rf_set_channel(XINCX_ADV_CHANNEL);
|
||||
|
||||
/* Enable RF24G interrupt */
|
||||
NVIC_EnableIRQ(RF24G_IRQn);
|
||||
|
||||
/* Entering the receiver */
|
||||
CE_CTL_HIGH;
|
||||
LOGI("************ADV Recv Start**************\r\n");
|
||||
|
||||
osal_set_event(RF24_ADV_TaskID, RF_ADV_RX_EVT);
|
||||
#else
|
||||
LOGI("************ADV Send Start**************\r\n");
|
||||
|
||||
rf_adv_tx_evevt();
|
||||
|
||||
osal_set_event(RF24_ADV_TaskID, RF_ADV_TX_EVT);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint16_t RF24_ADV_ProcessEvent(uint8_t task_id, uint16_t events)
|
||||
{
|
||||
if (task_id != RF24_ADV_TaskID)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (events & RF_ADV_TX_EVT)
|
||||
{
|
||||
rf_adv_tx_evevt();
|
||||
osal_start_reload_timer(RF24_ADV_TaskID, RF_ADV_TX_EVT, 9);
|
||||
return (events ^ RF_ADV_TX_EVT);
|
||||
}
|
||||
if (events & RF_ADV_RX_EVT)
|
||||
{
|
||||
rf_adv_rx_evevt();
|
||||
osal_set_event(RF24_ADV_TaskID, RF_ADV_RX_EVT);
|
||||
return (events ^ RF_ADV_RX_EVT);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user