Support for fixed length packets, shell code now installs to client/.
[goodfet] / shellcode / chipcon / cc1110 / reflex.c
1 #include <cc1110.h>
2 #include "cc1110-ext.h"
3
4 char __xdata at 0xfe00 packet[256] ;
5
6 void sleepMillis(int ms) {
7         int j;
8         while (--ms > 0) { 
9                 for (j=0; j<1200;j++); // about 1 millisecond
10         };
11 }
12
13 //! Reflexively jam on the present channel by responding to a signal with a carrier wave.
14 void main(){
15   unsigned char threshold=packet[0], i=0, rssi=0;;
16   
17   
18   //Disable interrupts.
19   RFTXRXIE=0;
20   
21   //idle a bit.
22   //RFST=RFST_SIDLE;
23   //while(MARCSTATE!=MARC_STATE_IDLE);
24
25   while(1){
26     //Wait for the transmission.
27     RFST=RFST_SRX;
28     while(MARCSTATE!=MARC_STATE_RX);
29     rssi=0;
30     //Wait for RSSI to settle.
31     sleepMillis(10);
32     //Delay until the RSSI is above the threshold.
33     while(rssi<threshold){
34       rssi=RSSI^0x80;
35       packet[0]=rssi;
36     }
37     
38     //idle a bit.
39     RFST=RFST_SIDLE;
40     while(MARCSTATE!=MARC_STATE_IDLE);
41     
42     
43     SYNC1=0xAA;
44     SYNC0=0xAA;
45     
46     //Transmit carrier for 10ms
47     RFST=RFST_STX;
48     while(MARCSTATE!=MARC_STATE_TX);
49     sleepMillis(10);
50     
51     //Carrier will clear when the loop continue,
52     //but we can HALT to give the host a chance to take over.
53     HALT;
54   }  
55   RFST = RFST_SIDLE; //End transmit.
56   
57   HALT;
58 }