update 1.8

This commit is contained in:
qiyongshuang
2023-09-06 10:08:11 +08:00
parent b79c6ac80d
commit 64be955461
760 changed files with 42517 additions and 30957 deletions
+84 -16
View File
@@ -22,12 +22,64 @@
uint8_t taskID;
uint8_t TX_DATA[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
volatile uint8_t tx_end_flag=0;
volatile uint8_t rx_end_flag=0;
/*********************************************************************
* @fn RF_Wait_Tx_End
*
* @brief 手动模式等待发送完成,自动模式等待发送-接收完成,必须在RAM中等待,等待时可以执行用户代码,但需要注意执行的代码必须运行在RAM中,否则影响发送
*
* @return none
*/
__attribute__((section(".highcode")))
__attribute__((noinline))
void RF_Wait_Tx_End()
{
uint32_t i=0;
while(!tx_end_flag)
{
i++;
__NOP();
__NOP();
// 约5ms超时
if(i>(SystemCoreClock/1000))
{
tx_end_flag = TRUE;
}
}
}
/*********************************************************************
* @fn RF_Wait_Rx_End
*
* @brief 自动模式等待应答发送完成,必须在RAM中等待,等待时可以执行用户代码,但需要注意执行的代码必须运行在RAM中,否则影响发送
*
* @return none
*/
__attribute__((section(".highcode")))
__attribute__((noinline))
void RF_Wait_Rx_End()
{
uint32_t i=0;
while(!rx_end_flag)
{
i++;
__NOP();
__NOP();
// 约5ms超时
if(i>(SystemCoreClock/1000))
{
rx_end_flag = TRUE;
}
}
}
/*********************************************************************
* @fn RF_2G4StatusCallBack
*
* @brief RF status callback
* @Note Do not call RF receiving or sending APIs in this function directly,
* setting the event instead
* @brief RF 状态回调,此函数在中断中调用。注意:不可在此函数中直接调用RF接收或者发送API,需要使用事件的方式调用
* 在此回调中直接使用或调用函数涉及到的变量需注意,此函数在中断中调用。
*
* @param sta - State
* @param crc - CRC verification results
@@ -45,10 +97,12 @@ void RF_2G4StatusCallBack(uint8_t sta, uint8_t crc, uint8_t *rxBuf)
}
case TX_MODE_TX_FAIL:
{
tx_end_flag = TRUE;
break;
}
case TX_MODE_RX_DATA:
{
tx_end_flag = TRUE;
if (crc == 0) {
uint8_t i;
@@ -72,10 +126,12 @@ void RF_2G4StatusCallBack(uint8_t sta, uint8_t crc, uint8_t *rxBuf)
}
case TX_MODE_RX_TIMEOUT: // Timeout is about 200us
{
tx_end_flag = TRUE;
break;
}
case TX_MODE_HOP_SHUT:
{
tx_end_flag = TRUE;
PRINT("TX_MODE_HOP_SHUT...\n");
tmos_set_event(taskID, SBP_RF_CHANNEL_HOP_TX_EVT);
break;
@@ -86,6 +142,7 @@ void RF_2G4StatusCallBack(uint8_t sta, uint8_t crc, uint8_t *rxBuf)
if (crc == 0) {
uint8_t i;
RF_Wait_Rx_End();
PRINT("rx recv, rssi: %d\n", (int8_t)rxBuf[0]);
PRINT("len:%d-", rxBuf[1]);
@@ -102,21 +159,23 @@ void RF_2G4StatusCallBack(uint8_t sta, uint8_t crc, uint8_t *rxBuf)
PRINT("match type error\n");
}
}
tmos_set_event(taskID, SBP_RF_RF_RX_EVT);
break;
}
case RX_MODE_TX_FINISH:
{
tmos_set_event(taskID, SBP_RF_RF_RX_EVT);
rx_end_flag = TRUE;
break;
}
case RX_MODE_TX_FAIL:
{
tmos_set_event(taskID, SBP_RF_RF_RX_EVT);
rx_end_flag = TRUE;
break;
}
case RX_MODE_HOP_SHUT:
{
PRINT("RX_MODE_HOP_SHUT...\n");
rx_end_flag = TRUE;
tmos_set_event(taskID, SBP_RF_CHANNEL_HOP_RX_EVT);
break;
}
@@ -156,7 +215,11 @@ uint16_t RF_ProcessEvent(uint8_t task_id, uint16_t events)
{
RF_Shut();
TX_DATA[0]--;
RF_Tx(TX_DATA, 10, 0xFF, 0xFF);
tx_end_flag = FALSE;
if(!RF_Tx(TX_DATA, 10, 0xFF, 0xFF))
{
RF_Wait_Tx_End();
}
tmos_start_task(taskID, SBP_RF_PERIODIC_EVT, 1000);
return events ^ SBP_RF_PERIODIC_EVT;
}
@@ -165,6 +228,7 @@ uint16_t RF_ProcessEvent(uint8_t task_id, uint16_t events)
uint8_t state;
RF_Shut();
TX_DATA[0]++;
rx_end_flag = FALSE;
state = RF_Rx(TX_DATA, 10, 0xFF, 0xFF);
return events ^ SBP_RF_RF_RX_EVT;
}
@@ -192,6 +256,8 @@ uint16_t RF_ProcessEvent(uint8_t task_id, uint16_t events)
}
else
{
rx_end_flag = FALSE;
RF_Rx(TX_DATA, 10, 0xFF, 0xFF);
}
return events ^ SBP_RF_CHANNEL_HOP_RX_EVT;
@@ -216,22 +282,24 @@ void RF_Init(void)
// 0x55555555 and 0xAAAAAAAA are prohibited (recommended no more than 24 bit reversals, and no more than 6 consecutive 0 or 1)
rfConfig.accessAddress = 0x71764129;
rfConfig.CRCInit = 0x555555;
// rfConfig.Channel = 0;
rfConfig.ChannelMap = 0x1<<6;
rfConfig.ChannelMap = 0xFFFFFFFF;
rfConfig.LLEMode = LLE_MODE_AUTO;
rfConfig.rfStatusCB = RF_2G4StatusCallBack;
rfConfig.RxMaxlen = 251;
#if (CLK_OSC32K != 0)
//It is better to choose a shorter heartbeat interval for the internal clock.
rfConfig.HeartPeriod = 4;
#endif
state = RF_Config(&rfConfig);
PRINT("rf 2.4g init: %x\n", state);
{ // RX mode
PRINT("RX mode...\n");
tmos_set_event(taskID, SBP_RF_CHANNEL_HOP_RX_EVT);
}
// { // TX mode
// PRINT("TX mode...\n");
// tmos_set_event(taskID, SBP_RF_CHANNEL_HOP_TX_EVT);
// { // RX mode
// PRINT("RX mode...\n");
// tmos_set_event(taskID, SBP_RF_CHANNEL_HOP_RX_EVT);
// }
{ // TX mode
PRINT("TX mode...\n");
tmos_set_event(taskID, SBP_RF_CHANNEL_HOP_TX_EVT);
}
}
/******************************** endfile @ main ******************************/
+1
View File
@@ -51,6 +51,7 @@ void Main_Circulation(void)
*/
int main(void)
{
SystemCoreClockUpdate();
Delay_Init();
#ifdef DEBUG
USART_Printf_Init( 115200 );
-13
View File
@@ -22,7 +22,6 @@
void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void BB_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void LLE_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
/*********************************************************************
* @fn NMI_Handler
@@ -60,15 +59,3 @@ void BB_IRQHandler(void)
{
BB_IRQLibHandler();
}
/*********************************************************************
* @fn LLE_IRQHandler
*
* @brief LLE Interrupt for BLE.
*
* @return None
*/
void LLE_IRQHandler(void)
{
LLE_IRQLibHandler();
}
+2 -2
View File
@@ -10,8 +10,8 @@
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef CENTRAL_H
#define CENTRAL_H
#ifndef RF_PHY_H
#define RF_PHY_H
#ifdef __cplusplus
extern "C" {