📄 drv2_cc1000.c
字号:
RF_Tx_Buf[RFt_inp]=(uint8)(~(send_cnt+4)); //2byte for CRC_code, 2byte for MODULE_ID_ADDR
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
crc_data=MB_CRC16Check(((uint8*)RF_Tx_Buf+10),send_cnt); // attached CRC code
RF_Tx_Buf[send_cnt+10] =(uint8)(crc_data>>8); // 10 byte SYN flag
RF_Tx_Buf[send_cnt+1+10] =(uint8) crc_data;
//// only for debug
RF_Tx_Buf[send_cnt+12] =(uint8)(RF_ModuleAddress>>8); // 10 byte SYN flag
RF_Tx_Buf[send_cnt+1+12] =(uint8) RF_ModuleAddress;
////
RF_TxCounter = send_cnt+4+10; // 2bytes CRC check,2byte for MODULE_ID_ADDR,10 byte SYN flag.
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) DB_SendString("Time overflow in RF_SendString()");
WatchDogClear(); //clr watchdog
////
IRQDisable();
RF_makeSynFlag();
//// byte counter
// RF_Tx_Buf[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_Buf[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_Buf[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_Buf[RFt_inp]=0x0d;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0; //elarge the sending buffer
RF_TxCounter++;
RF_Tx_Buf[RFt_inp]=0x0a;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
////
RF_Tx_Buf[RFt_inp1]=(RF_TxCounter-10); // byte counter
RF_Tx_Buf[RFt_inp2]=(uint8)(~(RF_TxCounter-10)); // ~byte counter
////
IRQEnable(); // 使能IRQ中断
RFtoTXmode(); //initiate sending
}
/////////////////////////////////////////////////////////////////////////////////
//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) DB_SendString("Time overflow in RF_SendEnter()");
WatchDogClear(); //clr watchdog
////
IRQDisable();
RF_makeSynFlag();
//// byte counter
RF_Tx_Buf[RFt_inp]=0x02;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
//// byte counter check=~byte counter
RF_Tx_Buf[RFt_inp]=(uint8)(~0x02);
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
RF_Tx_Buf[RFt_inp]=0x0d;
RFt_inp++; if(RFt_inp>=TX_BUFFER_LEN) RFt_inp=0;
RF_TxCounter++;
RF_Tx_Buf[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_BufferFlag0==_DATA_OK){
r_BufferFlag0 = 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;
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_BufferFlag != _DATA_OK)) 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)) ; //DelayMS_(1);
if(mSecondTick<=1) DB_SendString("Time overflow in RFtoUart0()");
WatchDogClear(); //clr watchdog */
RF_BufferFlag = 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_Buf[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中断
Uart0SendChar(RFbuffer,RFbytecnt); // sending out via serial port0
}
}
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// receiving data from Uart0 and send it out via RF
void Uart1ToRF(void)
{
char buffer[RX_BUFFER_LEN];
char bytecnt;
char i;
if(RF_ModemState!=ENABLE_FLAG) return;
// wait to stop receiving
if(r_BufferFlag1==_DATA_OK){
r_BufferFlag1 = 0;
while(1){
bytecnt=r_count1;
DelayMS_(1);
//modified by Travis Feb.8,2006
// if((bytecnt==r_count1)|(r_count1>(RX_BUFFER_LEN-16-10))){
if((bytecnt==r_count1)||(r_count1>(RX_BUFFER_LEN-16-10))){
break; // wait to stop receiving
}
}
//// fetch data to buffer
IRQDisable();
bytecnt=r_count1;
r_count1=0; //r_count1=r_count1-bytecnt;
IRQEnable(); // 使能IRQ中断
if(bytecnt!=0){ // received new data
IRQDisable();
for(i=0;i<bytecnt;i++){
buffer[i]=r_buf1[r_outp1];
r_outp1++; if(r_outp1>=RX_BUFFER_LEN) r_outp1=0;
}
// if(r_count1==0) r_outp1=r_inp1; //a line the input and output pointer.
r_outp1=r_inp1; //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 RFtoUart1(void)
{
char RFbuffer[RX_BUFFER_LEN];
char RFbytecnt;
char i;
if((RF_ModemState != ENABLE_FLAG)||(RF_BufferFlag != _DATA_OK)) 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)) ; //DelayMS_(1);
if(mSecondTick<=1) DB_SendString("Time overflow in RFtoUart1()");
WatchDogClear(); //clr watchdog */
RF_BufferFlag = 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_Buf[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;
IRQEnable();
Uart1SendChar(RFbuffer,RFbytecnt); // sending out via serial port0
}
}
/////////////////////////////////////////////////////////////////////////////////
// start cc1000
void RF_StartCC1000(void)
{
uint8 TX_Calibration;
uint8 RX_Calibration;
#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()) TX_Calibration=0x00;
else TX_Calibration=0x5a;
////////////////////////////////////////////////
WakeUpCC1000ToRX(RxCurrent,RF_RxPll);
CalibrateCC1000();
////
SetupCC1000RX(RxCurrent,RF_RxPll);
if(!CalibrateCC1000()) RX_Calibration=0x00;
else RX_Calibration=0x5a;
////////////////////////////////////////////////
// user configurate the Mode of cc1000
RF_ManualConfig();
if(TX_Calibration==0x00) DB_SendString("TX Calibration failed.");
else DB_SendString("TX Calibration success.");
if(RX_Calibration==0x00) DB_SendString("RX Calibration failed.");
else DB_SendString("RX Calibration success.");
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
}
////////////////////////////////////////////////
void RF_UartBridge(void)
{
Uart1ToRF(); //for RF modem
RFtoUart1();
}
////////////////////////////////////////////////
void PrtRF_ChannelState(void)
{
char i;
DB_SendEnter(); //print a blank line
#ifdef EN_MULTI_RF_FREQUENCE
i = RF_ChannelID % MAX_RF_CHANNELS;
#else
i = 3;
#endif
switch (i) {
case 0:
DB_SendString("....RF_ch0 run in 429.483164MHz");
break;
case 1:
DB_SendString("....RF_ch1 run in 430.875231MHz");
break;
case 2:
DB_SendString("....RF_ch2 run in 432.009508MHz");
break;
// case 3:
// DB_SendString("RF_ch3 run in 433.265314MHz(old Version)");
// break;
case 4:
DB_SendString("....RF_ch4 run in 434.845200MHz");
break;
case 5:
DB_SendString("....RF_ch5 run in 435.979477MHz");
break;
default:
DB_SendString("....RF_ch3 run in 433.265314MHz(old version)");
break;
}
}
// end of file /////////////////////////////////
// end of file /////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -