#include "hal.h" #include "LT89xx_rf.h" #include "LT89xx_def.h" #include "LT89xx_rf_cfg.h" #include "LT89xx.h" #include "V2RFEncoding.h" #include "task.h" #define RF_FREQ_0 2402UL extern Sync_Word Tx_Sync_Word ; //发送SYNC_WORD Sync_Word Tx_Sync_Word = { 0x7236, 0x1809, }; //发送频率 uint16_t Tx_Freq[] = {RF_FREQ_0+0x0F,RF_FREQ_0+0x23, RF_FREQ_0+0x37}; //接收同步字和频率 //接收通道 6个 LT89XX_Sync_Word_Channel Rx_Sync_Word_Channel[] = { { 0x7236, 0x1809, RF_FREQ_0+0x88-0x80 //RF_FREQ_0+0x08 }, //Dual white FUT091 //8 mode FUT089 //99 mode { 0x147A, 0x258B, RF_FREQ_0+0x89-0x80 //RF_FREQ_0+0x09 }, { 0x7236, 0x1809, RF_FREQ_0+0xA7-0x80 //RF_FREQ_0+0x27 }, { 0x147A, 0x258B, RF_FREQ_0+0xA8-0x80 //RF_FREQ_0+0x28 }, { 0x7236, 0x1809, RF_FREQ_0+0xC6-0x80 //RF_FREQ_0+0x46 }, { 0x147A, 0x258B, RF_FREQ_0+0xC7-0x80 //RF_FREQ_0+0x47 }, }; void StartTaskLT89XX(void); void SetSyncWord(uint16_t Sync_word_High,uint16_t Sync_word_Low) { LT_WriteReg2(REG36_SYNC_WORD_15_00,Sync_word_Low); //SYNC_WORD LT_WriteReg2(REG39_SYNC_WORD_63_48,Sync_word_High); } void Reset_FIFO_PTR(void) { LT_WriteReg(REG52_W_R_PTR, 0x80, 0x80); //收发FIFO 指针数据复位 } void LT8920_TxData(uint8_t* pBuf,uint8_t len ,uint16_t FreqChannel) { FreqChannel-=RF_FREQ_0; LT_WriteReg(REG07_W_R_EN, 0x00, 00); //停止收发, Reset_FIFO_PTR(); LT_WriteBuf(50,pBuf,len); LT_WriteReg(REG07_W_R_EN, 0x01, FreqChannel); //启动接收 ,写入频率 } void StartRxData(uint16_t FreqChannel,uint16_t Sync_word_High,uint16_t Sync_word_Low) { FreqChannel-=RF_FREQ_0; LT_WriteReg(REG07_W_R_EN, 0x00, 00); //停止收发, SetSyncWord(Sync_word_High,Sync_word_Low); Reset_FIFO_PTR(); LT_WriteReg(REG07_W_R_EN, 0x00, FreqChannel|0x80); //启动接收 ,写入频率 //REG07_W_R_EN 收发和频率 //0X24 36 //SYNC_WORD[15:0] //0X27 39 //SYNC_WORD[63:48] //0X34 52 //清除收发FIFO } void StopTxRxData(void) { LT_WriteReg(REG07_W_R_EN, 0x00, 00); //停止收发, } uint8_t LT8920_RxData(uint8_t* pBuf,uint8_t *len ) { uint8_t RegH,RegL; int result = LT_GetPKT(); if(result) { LT_Readreg(48,&RegH,&RegL); if((RegH&0x80)==0) { result = LT_ReadBuf(50,pBuf); *len = result; //收到数据退出 _nop_(); } } return result; } AL_STATIC uint8_t RxData[32]; void TaskLT89xx_thread_entry(void *arg); AL_STATIC struct rt_thread rtTaskLT89XX; //AL_STATIC uint32_t TaskLT89XX_stack[128]; AL_STATIC uint8_t TaskLT89XX_stack[512]; AL_STATIC uint8_t priorityLt89XX = 4; void StartTaskLT89XX(void) { rt_thread_init(&rtTaskLT89XX, "TaskLT89XX",TaskLT89xx_thread_entry, RT_NULL, TaskLT89XX_stack, sizeof(TaskLT89XX_stack), priorityLt89XX, 10); rt_thread_startup(&rtTaskLT89XX); } void TaskLT89xxRxData(void *arg, uint16_t FreqChannel, uint16_t Sync_word_High, uint16_t Sync_word_Low, uint8_t* pBuf, uint8_t *len1, uint8_t TimeOut ) { uint8_t Rx_TimeOut = 0; _nop_(); *len1 = 0; while(1) { StartRxData(FreqChannel,Sync_word_High,Sync_word_Low); while(1) { _nop_(); if(LT_GetPKT()) { uint8_t RegH,RegL; LT_Readreg(48,&RegH,&RegL); if((RegH&0x80)==0) { *len1 = LT_ReadBuf(50,pBuf); } _nop_(); return ; //收到数据退出 } Rx_TimeOut++; if(Rx_TimeOut>TimeOut) //下一次是2ms后 { Rx_TimeOut = 0; return; //长期没有收到数据,重新开始 } else { rt_thread_mdelay(1); //记录下次进入点,下次从此开始 } } } } void TaskLT89xx_thread(void *arg) { uint8_t len = 0; uint16_t i = 0; uint16_t j = 0; uint16_t count = 0; uint16_t freq = 0; uint16_t sync_word_high = 0; uint16_t sync_word_low = 0; i = 0; j = 0; count = 0; len = 0; freq = 0; sync_word_high = 0; sync_word_low = 0; for(i=0;i0) { StopTxRxData(); sync_word_high = Tx_Sync_Word.Sync_Word_63_48; sync_word_low = Tx_Sync_Word.Sync_Word_15_00; SetSyncWord(sync_word_high,sync_word_low); StopTxRxData(); Reset_FIFO_PTR(); do { for(j=0;j100) { StartRxData(RF_FREQ); Rx_TimeOut = 0; _nop_(); } } while(1) { printf("Hello world!"); rt_thread_mdelay(0); } } int SIMULATOR = 0; PT_THREAD(TaskLT89xxRxData(struct pt *pt1, uint16_t FreqChannel, uint16_t Sync_word_High, uint16_t Sync_word_Low, uint8_t* pBuf, uint8_t *len1, uint8_t TimeOut )) { static uint8_t Rx_TimeOut = 0; _nop_(); PT_BEGIN(pt1); while(1) { StartRxData(FreqChannel,Sync_word_High,Sync_word_Low); while(1) { _nop_(); if(LT_GetPKT()) { uint8_t RegH,RegL; LT_Readreg(48,&RegH,&RegL); if((RegH&0x80)==0) { *len1 = LT_ReadBuf(50,pBuf); DecodePackage(pBuf,*len1); } PT_EXIT(pt1); //收到数据退出 } if(SIMULATOR) { SIMULATOR = 0; *len1 = 9; } Rx_TimeOut++; if(Rx_TimeOut>TimeOut) //下一次是2ms后 { Rx_TimeOut = 0; PT_EXIT(pt1); //长期没有收到数据,重新开始 } else { PT_YIELD(pt1); //记录下次进入点,下次从此开始 } } } PT_END(pt1); } PT_THREAD(TaskLT89xx_thread(struct pt *pt1)) { static uint8_t len = 0; static uint16_t i = 0; static uint16_t j = 0; static uint16_t count = 0; static uint16_t freq = 0; static uint16_t sync_word_high = 0; static uint16_t sync_word_low = 0; static struct pt ptRxData; PT_BEGIN(pt1); i = 0; j = 0; count = 0; len = 0; freq = 0; sync_word_high = 0; sync_word_low = 0; for(i=0;i0) { StopTxRxData(); sync_word_high = Tx_Sync_Word.Sync_Word_63_48; sync_word_low = Tx_Sync_Word.Sync_Word_15_00; SetSyncWord(sync_word_high,sync_word_low); StopTxRxData(); Reset_FIFO_PTR(); do { for(j=0;j