📄 drv2_cc1000.c
字号:
RF_Tx_Buffer[RFt_inp]=0x5a;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
//
RF_Tx_Buffer[RFt_inp]=0x5a;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
//
RF_Tx_Buffer[RFt_inp]=0x5a;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
//
RF_Tx_Buffer[RFt_inp]=0x50;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
// synchronize semaphore
RF_Tx_Buffer[RFt_inp]=(uint8)(SYN_FLAG>>24);
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
//
RF_Tx_Buffer[RFt_inp]=(uint8)(SYN_FLAG>>16);
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
//
RF_Tx_Buffer[RFt_inp]=(uint8)(SYN_FLAG>>8);
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
//
RF_Tx_Buffer[RFt_inp]=(uint8)(SYN_FLAG);
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//sending anything to host without ending flag(such as CRC or ENTER)
//state :ok
////////////////////////////////////////////////////////////////////////////////
/*
void RF_SendingOver(void)
{
if(RF_ModemState!=ENABLE_FLAG) return;
// while((RF_TxCounter|RF_TxBitCounter)!=0);
WatchDogClear(); //clr watchdog
mSecondTick=WHILE_DELAY_TIME;
while(((RF_TxCounter|RF_TxBitCounter)!=0)&&(mSecondTick>1));
if(mSecondTick<=1) Uart0SendString("Time overflow in RF_SendingOver");
WatchDogClear(); //clr watchdog
}
*/
////////////////////////////////////////////////////////////////////////////////
//sending anything to host without ending flag(such as CRC or ENTER)
//state :ok
////////////////////////////////////////////////////////////////////////////////
void RF_SendChar(char *send_pt,uint8 send_cnt)
{
if(RF_ModemState!=ENABLE_FLAG) return;
// while((RF_TxCounter|RF_TxBitCounter)!=0);
WatchDogClear(); //clr watchdog
mSecondTick=WHILE_DELAY_TIME;
while(((RF_TxCounter|RF_TxBitCounter)!=0)&&(mSecondTick>1));
if(mSecondTick<=1) Uart0SendString("Time overflow in RF_SendChar");
WatchDogClear(); //clr watchdog
////
IRQDisable();
RF_makeSynFlag(); //10 bytes consumption(4+4+2)
//// byte counter
RF_Tx_Buffer[RFt_inp]=send_cnt;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
//// byte counter check=~(byte counter)
RF_Tx_Buffer[RFt_inp]=(uint8)(~send_cnt);
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
////
do{
RF_Tx_Buffer[RFt_inp]=*send_pt;
RFt_inp++;
if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0; //elarge the sending buffer
send_pt++;
RF_TxCounter++;
send_cnt--;
}while(send_cnt>0); // copy the string to t_buffer
////
IRQEnable(); // 使能IRQ中断
RFtoTXmode(); //initiate sending
}
//////////////////////////////////////////////////////////////////////////////
//sending string ending with ENTER to computer or host
//state :ok
//////////////////////////////////////////////////////////////////////////////
/*
void RF_SendString(char *send_pt)
{
uint8 RFt_inp1,RFt_inp2;
if(RF_ModemState!=ENABLE_FLAG) return;
// while((RF_TxCounter|RF_TxBitCounter)!=0);
WatchDogClear(); //clr watchdog
mSecondTick=WHILE_DELAY_TIME;
while(((RF_TxCounter|RF_TxBitCounter)!=0)&&(mSecondTick>1));
if(mSecondTick<=1) Uart0SendString("Time overflow in RF_SendString");
WatchDogClear(); //clr watchdog
////
IRQDisable();
RF_makeSynFlag();
//// byte counter
// RF_Tx_Buffer[RFt_inp]=send_cnt;
RFt_inp1 = RFt_inp;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
//// byte counter check=~(byte counter)
// RF_Tx_Buffer[RFt_inp]=(uint8)(~send_cnt);
RFt_inp2 = RFt_inp;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
////
do{
RF_Tx_Buffer[RFt_inp]=*send_pt;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0; //elarge the sending buffer
send_pt++;
RF_TxCounter++;
}while(*send_pt!=0); // copy the string to t_buffer
RF_Tx_Buffer[RFt_inp]=0x0d;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0; //elarge the sending buffer
RF_TxCounter++;
RF_Tx_Buffer[RFt_inp]=0x0a;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
////
RF_Tx_Buffer[RFt_inp1]=(RF_TxCounter-10); // byte counter
RF_Tx_Buffer[RFt_inp2]=(uint8)(~(RF_TxCounter-10)); // ~byte counter
////
IRQEnable(); // 使能IRQ中断
RFtoTXmode(); //initiate sending
}
////////////////////////////////////////////////////////////////////////////
//sending command package from t_buf0[0] to t_buf0[send_cnt+2] including CRC
//status :ok
*/
/**************************************************************************/
////////////////////////////////////////////////////////////////////////////
//send ENTER to host
//status: ok
///////////////////////////////////////////////////////////////////////////
/*
void RF_SendEnter(void)
{
if(RF_ModemState!=ENABLE_FLAG) return;
// while((RF_TxCounter|RF_TxBitCounter)!=0);
WatchDogClear(); //clr watchdog
mSecondTick=WHILE_DELAY_TIME;
while(((RF_TxCounter|RF_TxBitCounter)!=0)&&(mSecondTick>1));
if(mSecondTick<=1) Uart0SendString("Time overflow in RF_SendEnter");
WatchDogClear(); //clr watchdog
////
IRQDisable();
RF_makeSynFlag();
//// byte counter
RF_Tx_Buffer[RFt_inp]=0x02;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
//// byte counter check=~(byte counter)
RF_Tx_Buffer[RFt_inp]=(uint8)(~0x02);
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
RF_Tx_Buffer[RFt_inp]=0x0d;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
RF_Tx_Buffer[RFt_inp]=0x0a;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
////
IRQEnable(); // 使能IRQ中断
RFtoTXmode(); //initiate sending
}
*/
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// receiving data from Uart0 and send it out via RF
void Uart0ToRF(void)
{
char buffer[RX_BUFFER_LEN];
char bytecnt;
char i;
if(RF_ModemState!=ENABLE_FLAG) return;
// wait to stop receiving
if(r_ActiveFlag0==_DATA_AVAILABLE){
r_ActiveFlag0 = 0;
while(1){
bytecnt=r_count0;
DelayMS_(1);
//modified by Travis Feb.8,2006
// if((bytecnt==r_count0)|(r_count0>(RX_BUFFER_LEN-16-10))){
if((bytecnt==r_count0)||(r_count0>(RX_BUFFER_LEN-16-10))){
break; // wait to stop receiving
}
}
//// fetch data to buffer
IRQDisable();
bytecnt=r_count0;
r_count0=0; // r_count0=r_count0-bytecnt;
IRQEnable(); // 使能IRQ中断
if(bytecnt!=0){ // received new data
IRQDisable();
for(i=0;i<bytecnt;i++){
buffer[i]=r_buf0[r_outp0];
r_outp0++; if(r_outp0>=RX_BUFFER_LEN) r_outp0=0;
}
// if(r_count0==0) r_outp0=r_inp0; //a line the input and output pointer.
r_outp0=r_inp0; //a line the input and output pointer.
IRQEnable(); // 使能IRQ中断
RF_SendChar(buffer,bytecnt); // sending out via serial port0
}
}
}
///////////////////////////////////////////////////
// receiving data from Uart0 and send it out via RF
void RFtoUart0(void)
{
char RFbuffer[RX_BUFFER_LEN];
char RFbytecnt;
char i;
if((RF_ModemState!=ENABLE_FLAG)||(RF_ActiveFlag != _DATA_AVAILABLE)) return;
// RFtoRXmode();
// while((RF_RxSynSemaphore!=WAIT_SYN_F)&(CC1000Mode==RFinRX_MODE)){
// while((RF_RxSynSemaphore!=WAIT_SYN_F)&&(CC1000Mode==RFinRX_MODE))
/* WatchDogClear(); //clr watchdog
mSecondTick=WHILE_DELAY_TIME;
while(((RF_RxSynSemaphore!=WAIT_SYN_F)&&(CC1000Mode==RFinRX_MODE))&&(mSecondTick>1));
if(mSecondTick<=1) Uart0SendString("Time overflow in RFtoUart0()");
WatchDogClear(); //clr watchdog */
RF_ActiveFlag = 0;
//// fetch data to buffer
IRQDisable();
RFbytecnt=RF_RxCounter;
RF_RxCounter=0; // RF_RxCounter=RF_RxCounter-RFbytecnt;
IRQEnable(); // 使能IRQ中断
//modified by Travis Feb.8,2006
// if((RFbytecnt!=0)&(RFbytecnt<RX_BUFFER_LEN)){ // received new data
if((RFbytecnt!=0)&&(RFbytecnt<RX_BUFFER_LEN)){ // received new data
IRQDisable();
for(i=0;i<RFbytecnt;i++){
RFbuffer[i]=RF_Rx_Buffer[RFr_outp];
RFr_outp++; if(RFr_outp>=RX_BUFFER_LEN) RFr_outp=0;
}
// if(RF_RxCounter==0) RFr_outp=RFr_inp; //a line the input and output pointer.
RFr_outp=RFr_inp; //a line the input and output pointer.
IRQEnable(); // 使能IRQ中断
Uart0SendingChar(RFbuffer,RFbytecnt); // sending out via serial port0
}
}
/////////////////////////////////////////////////
// start cc1000
void RF_StartCC1000(void)
{
#ifdef ENABLE_LPC_WATCHDOG
WatchDog_Start(3000); // watchDog reset time 4 seconds
#endif // ENABLE_LPC_WATCHDOG
DelayMS_(2000);
#ifdef ENABLE_LPC_WATCHDOG
WatchDog_Start(5000); // watchDog reset time 4 seconds
#endif // ENABLE_LPC_WATCHDOG
InitCC1000Pin();
SetupCC1000PD();
Reset_CC1000();
DefaultSettings();
////////////////////////////////////////////////
WakeUpCC1000ToTX(TxCurrent,RF_TxPll);
CalibrateCC1000();
////
SetupCC1000TX(TxCurrent,RF_TxPll);
if(!CalibrateCC1000()){
Uart0SendString("TX Calibration failed");
}else{
Uart0SendString("TX Calibration success");
}
////////////////////////////////////////////////
WakeUpCC1000ToRX(RxCurrent,RF_RxPll);
CalibrateCC1000();
////
SetupCC1000RX(RxCurrent,RF_RxPll);
if(!CalibrateCC1000()){
Uart0SendString("RX Calibration failed");
}else{
Uart0SendString("RX Calibration success");
}
////////////////////////////////////////////////
// user configurate the Mode of cc1000
RF_ManualConfig();
PrintRF_Mode();
// Now the CC1000 is calibrated for both RX and TX, we do not need to recalibrate
// unless the frequency is changed, the temperature changes by 40 degrees C
// or if the supply voltage changes by more than 0.5V
}
// end of file //////////////////////////////////////////////////////////////////
// end of file //////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -