a294aac9e0d2c57eb70480617916cea83040086c
[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   //1-out the buffer.
12   for(i=0;i<64;i++)
13     packet[i]=0xFF;
14   i=0;
15   
16   //Disable interrupts.
17   RFTXRXIE=0;
18   
19   //idle a bit.
20   RFST=RFST_SIDLE;
21   while(MARCSTATE!=MARC_STATE_IDLE);
22   
23   //Begin to receive.
24   RFST=RFST_SRX;
25   while(MARCSTATE!=MARC_STATE_RX);
26   
27   while(i<len+1){ //len+3 if status is appended.
28     while(!RFTXRXIF); //Wait for byte to be ready.
29     RFTXRXIF=0;      //Clear the flag.
30     
31     if (MARCSTATE == MARC_STATE_RX) {
32       packet[i]=RFD; //Grab the next byte.
33       i++;
34       len=packet[0];   //First byte of the packet is the length.
35     }else
36       HALT;
37
38   }
39   RFST = RFST_SIDLE; //End receive.
40   HALT;
41 }
42