10ms reflex.
[goodfet] / shellcode / chipcon / cc1110 / rxpacket.c
1 #include <cc1110.h>
2 #include "cc1110-ext.h"
3
4 #define MAXLEN 0xFF
5 char __xdata at 0xfe00 packet[MAXLEN] ;
6
7 //! Receives a packet out of the radio from 0xFE00.
8 void main(){
9   unsigned char len=16, i=0;
10   
11   do{
12     //1-out the buffer.
13     for(i=0;i<64;i++)
14       packet[i]=0xFF;
15     i=0;
16     
17     //Disable interrupts.
18     RFTXRXIE=0;
19     
20     //idle a bit.
21     RFST=RFST_SIDLE;
22     while(MARCSTATE!=MARC_STATE_IDLE);
23     
24     //Begin to receive.
25     RFST=RFST_SRX;
26     while(MARCSTATE!=MARC_STATE_RX);
27     
28     if(PKTCTRL0&1){
29       //auto length
30       while(i<len+3){ //len+3 if status is appended.
31         while(!RFTXRXIF); //Wait for byte to be ready.
32         RFTXRXIF=0;      //Clear the flag.
33         
34         packet[i++]=RFD; //Grab the next byte.
35         len=packet[0];   //First byte of the packet is the length.
36       }
37     }else{
38       //Fixed length
39       packet[i++]=PKTLEN;
40       while(i<PKTLEN){
41         while(!RFTXRXIF); //Wait for byte to be ready.
42         RFTXRXIF=0;      //Clear the flag.
43         
44         packet[i++]=RFD; //Grab the next byte.
45       }
46     }
47     RFST = RFST_SIDLE; //End receive.
48     
49     //This while loop can be used for filtering.  Unused for now.
50   }while(0); //packet[0]==(char) 0x0f || packet[1]==(char) 0xFF || packet[9]==(char) 0x03);
51   
52   HALT;
53 }
54