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