6bfec59ac648dd3441e252d5efa4a3a0d527f94a
[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     rssi=0;
29     //Wait for RSSI to settle.
30     sleepMillis(10);
31     //Delay until the RSSI is above the threshold.
32     while(rssi<threshold){
33       rssi=RSSI^0x80;
34       packet[0]=rssi;
35     }
36     
37     //idle a bit.
38     RFST=RFST_SIDLE;
39     while(MARCSTATE!=MARC_STATE_IDLE);
40     
41     
42     SYNC1=0xAA;
43     SYNC0=0xAA;
44     
45     //Transmit carrier for 10ms
46     RFST=RFST_STX;
47     while(MARCSTATE!=MARC_STATE_TX);
48     sleepMillis(10);
49     
50     //Carrier will clear when the loop continue,
51     //but we can HALT to give the host a chance to take over.
52     HALT;
53   }  
54   RFST = RFST_SIDLE; //End transmit.
55   
56   HALT;
57 }