Stair56E UART project

This commit is contained in:
2026-08-05 19:07:52 +08:00
parent 7ca1af130d
commit f5654b70cc
2500 changed files with 619007 additions and 282610 deletions
@@ -0,0 +1,150 @@
/*
* @Descripttion:
* @version:
* @Author: sueRimn
* @Date: 2024-05-09 11:45:27
* @LastEditors: sueRimn
* @LastEditTime: 2024-07-24 15:18:52
*/
#ifndef __APP_DATA_H__
#define __APP_DATA_H__
#include "rf_config.h"
#include "xc6xxx_rf_2_4g.h"
#include "xc_software_crc.h"
#include <stdint.h>
#define BEKEN (0)
#define PAN2416 (1)
#ifdef TELINK_MODE
#define COMPATILBE_MODE BEKEN
#endif
#ifdef BEKEN_MODE
#define COMPATILBE_MODE BEKEN
#endif
#ifdef PANCHIP_MODE
#define COMPATILBE_MODE PAN2416
#endif
#define RF_CONFIRMED_VALUE (5U)
/* 最大接收数据长度 */
#define BUFF_LEN_MAX (32U)
#define RF_RECV_AMX_LEN (BUFF_LEN_MAX)
#define RF_PRX_READ_RXFIFO_TIMER (RF_RECV_AMX_LEN)
#define BIT7 0x80
#define BIT6 0x40
#define BIT5 0x20
#define BIT4 0x10
#define BIT3 0x08
#define BIT2 0x04
#define BIT1 0x02
#define BIT0 0x01
/* 动态包位移长度,单位bit */
#if (BEKEN == COMPATILBE_MODE)
#define DATA_ANALYSIS_BIT_H (BIT7)
#define DATA_ANALYSIS_BIT_L (BIT0)
#define DATA_CONTROL_BIT (1U)
#define DATA_CONTROL_NOACK (1U) // 1-ack 0-noack
#elif (PAN2416 == COMPATILBE_MODE)
#define DATA_ANALYSIS_BIT_H (BIT7 | BIT6)
#define DATA_ANALYSIS_BIT_L (BIT0 | BIT1)
#define DATA_CONTROL_BIT (2U)
#define DATA_CONTROL_NOACK (0U) // 0-ack 1-noack
#endif
#define DATA_SPLICE_BIT (8U - DATA_CONTROL_BIT)
/* 地址长度 */
#define RF_ADDR_LEN XINCX_RF_TX_ADDR_WIDTH // 5U
/* 接收CRC+contorl字段长度 */
#define RF_RECV_EXTEN_LEN (3U)
/* CRC初始值 */
#if (1 == XINCX_2_4G_CRC_BYTE)
#define RF_CRC_INIT_VALUE (0xFF) // CRC8 0xFF CRC16 0xFFFF
#elif (2 == XINCX_2_4G_CRC_BYTE)
#define RF_CRC_INIT_VALUE (0xFFFF) // CRC8 0xFF CRC16 0xFFFF
#endif
/* 调制频偏 */
#if ((XINCX_RF_TRANS_RATE == DR_250K) && (PAN2416 == COMPATILBE_MODE))
#define RF_FREQ_DEV (0xb8) // 0x75
#define RF_FREQ_SEND_DEV (0x90) // 0xb8//0xa0
#define RF_FREQ_RECV_DEV (0x80) // 0x98//0xa0
#define ACK_DELAY (50) //(300)
#elif ((XINCX_RF_TRANS_RATE == DR_1M) && (PAN2416 == COMPATILBE_MODE))
#define RF_FREQ_DEV (0xd0) // 0xb8//0xa0
#define RF_FREQ_SEND_DEV (0xe0) // 0xb8//0xa0
#define RF_FREQ_RECV_DEV (0x80) // 0x98//0xa0
#define ACK_DELAY (300) //(300)
#elif ((XINCX_RF_TRANS_RATE == DR_1M) && (BEKEN == COMPATILBE_MODE))
#define RF_FREQ_DEV (0x80) // 0x75
#define RF_FREQ_SEND_DEV (0xd0) // 0xb8//0xa0
#define RF_FREQ_RECV_DEV (RF_FREQ_DEV) // 0x98//0xa0
#define ACK_DELAY (40)
#elif ((XINCX_RF_TRANS_RATE == DR_250K) && (BEKEN == COMPATILBE_MODE))
#define RF_FREQ_DEV (0x80) // 0x75
#define RF_FREQ_SEND_DEV (0xd0) // 0xb8//0xa0
#define RF_FREQ_RECV_DEV (RF_FREQ_DEV) // 0x98//0xa0
#define ACK_DELAY (0)
#endif
/* 磐启白化初始值 */
#define PANCHIP_WHITEN_INIT_VAL (0x7F)
/* ACK 长度 */
#define ACK_LEN (32U) // 32U
/* */
#define USB_TEST (1U)
/* 测试IO 使能 */
#define DEBUG_PIN (1U)
#define TEST_PIN_NO_USB (1U)
/* 测试IO */
#define TEST_PIN_1 GPIO_3
#define TEST_PIN_2 GPIO_6
#define TEST_PIN_3 GPIO_7
#define TEST_PIN_4 GPIO_8
#define TEST_PIN_5 GPIO_1
#define TEST_PIN_6 GPIO_4
#define TEST_PIN_7 GPIO_5
#define TEST_PIN_8 GPIO_0
/* ACK固定接收字节数 */
#define RF_RECV_TIMER \
(XINCX_2_4G_PREAMBLE_NUM + 1 + XINCX_RF_TX_ADDR_WIDTH + RF_PRX_READ_RXFIFO_TIMER + XINCX_2_4G_CRC_BYTE + 2 + 10)
/* 速率-bit占用时间 */
#if (XINCX_RF_TRANS_RATE == DR_2M)
#define BIT_TIMER (4U)
#elif (XINCX_RF_TRANS_RATE == DR_1M)
#define BIT_TIMER (8U)
#elif (XINCX_RF_TRANS_RATE == DR_250K)
#define BIT_TIMER (32U)
#elif (XINCX_RF_TRANS_RATE == DR_125K)
#define BIT_TIMER (64U)
#endif
extern uint8_t addr_buff[5];
extern uint8_t ack_buff[BUFF_LEN];
extern uint16_t rf_addr_crc;
extern uint8_t panchip_addr_whiten;
extern uint8_t panchip_contorl_whiten;
extern uint8_t rf_send_ack_stat;
void rf_enhanced_packet(uint8_t *buff, uint8_t buff_len);
uint16_t rf_recv_dyn_crc(uint8_t *buff, uint8_t buff_len);
uint16_t rf_enhanced_package_grouping(uint8_t *data_buff, uint8_t data_len);
uint8_t read_addr_wid(uint8_t *addr_buff);
void rf_addr_map(uint8_t *addr_buff);
uint8_t rf_enhanced_recv_data(uint8_t *buff);
#endif
@@ -0,0 +1,61 @@
#ifndef __APP_RF_H__
#define __APP_RF_H__
#include "app_data.h"
#include "rf_config.h"
//#include "rtt_platform.h"
#include "xc6xxx.h"
#include "xc6xxx_rf_2_4g.h"
#include "xc_software_crc.h"
typedef enum
{
RF_SEND_TIMER_INTER = 0,
RF_RECV_TIMER_INTER = 1,
RF_FREE_TIMER_INTER = 2
} rf_timer_stat_t; // PRX 状态
#define RECV_TIMERMS_OUT 1000 // 超时接收
//#define SEND_TIMERMS_CNT 10 * 1000 // 定时发射 ms
#define RECV_TIMERMS_CNT 50
#define ACK_SEND_TIMER 50
#define XC_SEND_NUM 1000 // 发射总包数
#define RF_TX_TIMERx TIMER0_IDX // 发射定时器号
#define RF_RX_TIMERx TIMER0_IDX // 接收定时器号
#define EXTEND_LEN (5)
extern uint8_t ret;
extern uint32_t count;
extern uint32_t send_ok;
extern uint32_t send_max;
extern bool rf_send_timer_flag;
extern bool rf_recv_timer_flag;
extern bool rf_prx_ack_flag;
extern rf_timer_stat_t timer_stat;
void timer_init(uint8_t timer_id, uint32_t timer_cnt);
void gpio_test(void);
void rf_debug_pin(uint8_t gpio_id);
uint16_t rf_get_addr_crc(void);
//void rf_buff_info(uint8_t *buff, uint8_t len);
void rf_rx_ack_payload_event(uint8_t *buff, uint8_t len);
void rf_set_agc(uint8_t adc_rssi_mean, uint8_t agc_gain_delay);
void rf_pwr_down_up(void);
// uint16_t rf_send_enhanced_data_cfg(uint8_t *buff, uint8_t len, uint8_t ack);
#if (XINCX_RF_COMPATIBILITY_MODE == PANCHIP_PACKET)
uint32_t rf_tx_manage(rf_data_typedef_t *rf_data);
void timer0_callback(void *context);
#endif
void xc_rf_send_ack(uint8_t *buff, uint8_t recv_len);
void rf_set_rx_mode(uint16_t channel, uint16_t fifo_len);
void rf_recv_sf_ack_payload(uint8_t *buff, uint8_t len);
uint8_t rf_recv_enhanced_data(uint8_t *buff);
void rf_set_agc_map(uint8_t agc_gain_1th, uint8_t agc_setp);
void rf_pwm_recv_data(void);
uint8_t rf_recv_addr(void);
#endif //__APP_RF_H__
@@ -0,0 +1,83 @@
/*!
* \file main.h
*
* \brief The head file of main.c
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H__
#define __MAIN_H__
#ifdef __cplusplus
extern "C" {
#endif
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include "xc6xxx.h"
#include "xc6xxx_rf_2_4g.h"
#include "rf_config.h"
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
#define DEBUG_LOG
#define RECV_TIMERMS_OUT 1000
#define SEND_TIMERMS_CNT 10
#define XC_SEND_NUM 1000U
#define RF_TX_TIMERx TIMER0_IDX
#define RF_RX_TIMERx TIMER0_IDX
#define RF_CONFIRMED_VALUE 2
/*------------------------------------------------------------------------------------
TypeDef
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
extern bool rf_send_timer_flag;
extern bool rf24g_handler_flag;
extern uint8_t recv_ack_buff[256];
extern uint8_t ack_buff[256];
extern uint32_t ack_payload_cnt;
extern uint32_t ack_payload_error;
/*------------------------------------------------------------------------------------
Exported Functions
-------------------------------------------------------------------------------------*/
void rf_tx_manage(void);
void rf_rx_manage(void);
void rf_buff_info(uint8_t *buff, uint8_t len);
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H__ */