📄 xe1205driver.c
字号:
SyncByte = 0;
for(ByteCounter = 0, RFFramePos = 0; ByteCounter < RFFrameSize; ){
if(!(RegPAIn & IRQ_1)){ // If FIFO not full send a new byte
if(SyncByte == SYNC_BYTE_FREQ){
if(EnableSyncByte){
SyncByte = 0;
SendByte(InvertByte(0x55));
ByteCounter--;
}
}
else{
if(EnableSyncByte){
SyncByte++;
}
SendByte(InvertByte(pRFFrame[RFFramePos++]));
}
ByteCounter++;
}
else{ // If FIFO is full, waits until it is no more full
do{
}while((RegPAIn & IRQ_1));
}
}
if(!(RegPAIn & IRQ_1)){
do{
SendByte(0);
}while(!(RegPAIn & IRQ_1));
}
// Select TX IRQ_1 source to TX stopped
WriteRegister(REG_IRQPARAM1, RF_IRQ1_TX_IRQ_TX_STOPPED);
do{
}while(!(RegPAIn & IRQ_1)); // Wait for TX stopped event
RFState |= RF_STOP;
RFState &= ~RF_TX_DONE;
*pReturnCode = OK;
} // void SendRfFrame(_U8 *buffer, _U8 size, _U8 *pReturnCode)
/*******************************************************************
** ReceiveRfFrame : Receives a RF frame **
********************************************************************
** In : - **
** Out : *buffer, size, *pReturnCode **
*******************************************************************/
void ReceiveRfFrame(_U8 *buffer, _U8 *size, _U8 *pReturnCode){
_U8 TempRFState;
*pReturnCode = RX_RUNNING;
TempRFState = RFState;
if(TempRFState & RF_STOP){
pRFFrame = buffer;
RFFramePos = 0;
RFFrameSize = 2;
SyncByte = 0;
WriteRegister(REG_IRQPARAM1, RegistersCfg[REG_IRQPARAM1] |/**/RF_IRQ0_RX_IRQ_WRITE_BYTE /**//** /| RF_IRQ1_RX_IRQ_FIFOFULL/**/);
WriteRegister(REG_IRQPARAM2, RegistersCfg[REG_IRQPARAM2] | RF_IRQ2_START_DETECT_CLEAR);
RegIrqEnLow |= 0x04; // Enables Port A pin 2 interrupt IRQ_0
SetRFMode(RF_RECEIVER);
EnableTimeOut(true);
RFState |= RF_BUSY;
RFState &= ~RF_STOP;
RFState &= ~RF_TIMEOUT;
return;
}
else if(TempRFState & RF_RX_DONE){
*size = RFFrameSize;
*pReturnCode = OK;
RFState |= RF_STOP;
EnableTimeOut(false);
RFState &= ~RF_RX_DONE;
RegIrqEnMid &= ~0x02; // Disables Port A pin 1 interrupt IRQ_1
RegIrqEnLow &= ~0x04; // Disables Port A pin 2 interrupt IRQ_0
SPINssData(1);
return;
}
else if(TempRFState & RF_ERROR){
RFState |= RF_STOP;
RFState &= ~RF_ERROR;
*pReturnCode = ERROR;
RegIrqEnMid &= ~0x02; // Disables Port A pin 1 interrupt IRQ_1
RegIrqEnLow &= ~0x04; // Disables Port A pin 2 interrupt IRQ_0
SPINssData(1);
return;
}
else if(TempRFState & RF_TIMEOUT){
RFState |= RF_STOP;
RFState &= ~RF_TIMEOUT;
EnableTimeOut(false);
*pReturnCode = RX_TIMEOUT;
RegIrqEnMid &= ~0x02; // Disables Port A pin 1 interrupt IRQ_1
RegIrqEnLow &= ~0x04; // Disables Port A pin 2 interrupt IRQ_0
SPINssData(1);
return;
}
} // void ReceiveRfFrame(_U8 *buffer, _U8 size, _U8 *pReturnCode)
/*******************************************************************
** SendByte : Sends a data to the transceiver trough the SPI **
** interface **
********************************************************************
** In : b **
** Out : - **
*******************************************************************/
/*******************************************************************
** Information **
********************************************************************
** This function has been optimized to send a byte to the **
** transceiver SPI interface as quick as possible by using **
** IO ports. **
** If the microcontroller has an SPI hardware interface there is **
** no need to optimize the function **
*******************************************************************/
void SendByte(_U8 b){
SPIInit();
SPINssConfig(1);
SPINssData(0);
SPIClock(0);
if (b & 0x80){
SPIMosi(1);
}
else{
SPIMosi(0);
}
SPIClock(1);
SPIClock(0);
if (b & 0x40){
SPIMosi(1);
}
else{
SPIMosi(0);
}
SPIClock(1);
SPIClock(0);
if (b & 0x20){
SPIMosi(1);
}
else{
SPIMosi(0);
}
SPIClock(1);
SPIClock(0);
if (b & 0x10){
SPIMosi(1);
}
else{
SPIMosi(0);
}
SPIClock(1);
SPIClock(0);
if (b & 0x08){
SPIMosi(1);
}
else{
SPIMosi(0);
}
SPIClock(1);
SPIClock(0);
if (b & 0x04){
SPIMosi(1);
}
else{
SPIMosi(0);
}
SPIClock(1);
SPIClock(0);
if (b & 0x02){
SPIMosi(1);
}
else{
SPIMosi(0);
}
SPIClock(1);
SPIClock(0);
if (b & 0x01){
SPIMosi(1);
}
else{
SPIMosi(0);
}
SPIClock(1);
SPIClock(0);
SPIMosi(0);
SPINssData(1);
} // void SendByte(_U8 b)
/*******************************************************************
** ReceiveByte : Receives a data from the transceiver trough the **
** SPI interface ** **
********************************************************************
** In : - **
** Out : b **
*******************************************************************/
/*******************************************************************
** Information **
********************************************************************
** This function has been optimized to receive a byte from the **
** transceiver SPI interface as quick as possible by using **
** IO ports. **
** If the microcontroller has an SPI hardware interface there is **
** no need to optimize the function **
*******************************************************************/
_U8 ReceiveByte(void){
_U8 inputByte = 0;
SPIInit();
SPINssConfig(1);
SPINssData(0);
SPIClock(0);
SPIClock(1);
if (SPIMisoTest()){
inputByte |= 0x80;
}
SPIClock(0);
SPIClock(1);
if (SPIMisoTest()){
inputByte |= 0x40;
}
SPIClock(0);
SPIClock(1);
if (SPIMisoTest()){
inputByte |= 0x20;
}
SPIClock(0);
SPIClock(1);
if (SPIMisoTest()){
inputByte |= 0x10;
}
SPIClock(0);
SPIClock(1);
if (SPIMisoTest()){
inputByte |= 0x08;
}
SPIClock(0);
SPIClock(1);
if (SPIMisoTest()){
inputByte |= 0x04;
}
SPIClock(0);
SPIClock(1);
if (SPIMisoTest()){
inputByte |= 0x02;
}
SPIClock(0);
SPIClock(1);
if (SPIMisoTest()){
inputByte |= 0x01;
}
SPIClock(0);
SPIMosi(0);
SPINssData(1);
return inputByte;
}
/*******************************************************************
** Transceiver specific functions **
*******************************************************************/
/*******************************************************************
** AutoFreqControl : Calibrates the receiver LO frequency to the **
** transmitter LO frequency **
********************************************************************
** In : - **
** Out : *pReturnCode **
*******************************************************************/
void AutoFreqControl(_U8 *pReturnCode){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -