eb722d16c27fcb12f20401bc32937e94a5d7431e
[goodfet] / shellcode / chipcon / cc1110 / rxpacket.c
1 #include <cc1110.h>
2 #include "cc1110-ext.h"
3
4 char __xdata at 0xfe00 packet[256] ;
5
6 //! Receives a packet out of the radio from 0xFE00.
7 void main(){
8   unsigned char len=16, i=0;
9   
10   //1-out the buffer.
11   for(i=0;i<64;i++)
12     packet[i]=0xFF;
13   i=0;
14   
15   //Disable interrupts.
16   RFTXRXIE=0;
17   
18   //idle a bit.
19   RFST=RFST_SIDLE;
20   while(MARCSTATE!=MARC_STATE_IDLE);
21   
22   //Begin to receive.
23   RFST=RFST_SRX;
24   while(MARCSTATE!=MARC_STATE_RX);
25   
26   while(i!=len+1){
27     while(!RFTXRXIF); //Wait for byte to be ready.
28     RFTXRXIF=0;      //Clear the flag.
29     
30     if (MARCSTATE == MARC_STATE_RX) {
31       packet[i]=RFD; //Grab the next byte.
32       //packet[i]=MARCSTATE;
33       //if(packet[i]!=0)
34         i++;
35       //len=packet[0];   //First byte of the packet is the length.
36     }else
37       HALT;
38
39   }
40   RFST = RFST_SIDLE; //End transmit.
41   HALT;
42 }