Ejemplo n.º 1
0
PROCESS_THREAD(interferer_example, ev, data)
{
 PROCESS_EXITHANDLER()  
 PROCESS_BEGIN();

 // Initial configurations on CC2420: channel and tx power
 watchdog_stop();
 cc2420_set_txpower(CC2420_TXPOWER_MAX);
 cc2420_set_channel(INTERFERED_CHANNEL);
 printf("HandyMote: interfering continuously with random power\n");
 
 // Interfering continuously with random power
 CC2420_SPI_ENABLE();
 set_jammer(CARRIER_TYPE);
 int randelay, randpower;
 while(1){
	 randpower = random_value(MIN_POWER,MAX_POWER);
	 randelay = random_value(MIN_TIME,MAX_TIME);	 
	 power_jammer(randpower);
	 clock_delay(randelay);
 }
 CC2420_SPI_DISABLE();

 PROCESS_WAIT_EVENT();  
 PROCESS_END();
}
Ejemplo n.º 2
0
void FAST2420_READ_FIFO_BYTE(TiSpiAdapter * spi,uint8 *b)
   {
        CC2420_SPI_ENABLE();
        FAST2420_RX_ADDR(spi,CC2420_RXFIFO);
        spi_get(spi,(char*)b);
        CC2420_SPI_DISABLE();
    }
Ejemplo n.º 3
0
void FAST2420_GETREG(TiSpiAdapter * spi,uint8 a,uint16 *v)
    {
        CC2420_SPI_ENABLE();
        FAST2420_RX_ADDR(spi,a);
        FASTSPI_RX_WORD(spi,v);
        CC2420_SPI_DISABLE();

    }
Ejemplo n.º 4
0
void FAST2420_READ_FIFO_NO_WAIT(TiSpiAdapter * spi,uint8 *p, uint8 c)
    {
        uint8 n = 0;
        CC2420_SPI_ENABLE();
        FAST2420_RX_ADDR(spi,CC2420_RXFIFO);
        for (n = 0; n < (c); n++) {
            spi_get(spi,(char*)(p + n));
        }
        CC2420_SPI_DISABLE();
    }
Ejemplo n.º 5
0
void FAST2420_WRITE_FIFO(TiSpiAdapter * spi,uint8 *p,uint8 c)
    {
        uint8 n = 0;
        CC2420_SPI_ENABLE();
        FAST2420_TX_ADDR(spi,CC2420_TXFIFO);
        for (n = 0; n < (c); n++) {
            spi_put(spi,((BYTE*)(p))[n]);
        }
        CC2420_SPI_DISABLE();
    }
Ejemplo n.º 6
0
void FAST2420_SETREG(TiSpiAdapter * spi,uint8 a,uint16 v)
    {

        CC2420_SPI_ENABLE();
		//led_on( LED_YELLOW ); // debug only
        FAST2420_TX_ADDR(spi,a);
        FASTSPI_TX_WORD(spi, v);
        CC2420_SPI_DISABLE();

    }
Ejemplo n.º 7
0
// @modified by zhangwei on 20070701
// to support return  value
//
uint8 FAST2420_STROBE(TiSpiAdapter * spi,uint8 s)
	{
		uint8 status;
        CC2420_SPI_ENABLE();
		//spi_open( spi, 0 );
        status = FAST2420_TX_ADDR(spi,s);
		//spi_close( spi );
        CC2420_SPI_DISABLE();
		return status;
    }
Ejemplo n.º 8
0
void FAST2420_READ_RAM_LE(TiSpiAdapter * spi,uint8 *p,uint16 a,uint8 c)
   {
   	uint8 n;
        CC2420_SPI_ENABLE();
        spi_put(spi,0x80 | (a & 0x7F));
        spi_put(spi,((a >> 1) & 0xC0) | 0x20);
        for (n = 0; n < (c); n++) {
            spi_get(spi,(char*)(p + n));
        }
        CC2420_SPI_DISABLE();
    }
Ejemplo n.º 9
0
void FAST2420_WRITE_RAM_LE(TiSpiAdapter * spi,uint16 *p,uint16 a,uint8 c)
    {
    	uint8 n;
        CC2420_SPI_ENABLE();
        spi_put(spi,0x80 | (a & 0x7F));
        spi_put(spi,(a >> 1) & 0xC0);
        for (n = 0; n < (c); n++) {
            spi_put(spi,((BYTE*)(p))[n]);
        }
        CC2420_SPI_DISABLE();
    }
Ejemplo n.º 10
0
void FAST2420_READ_FIFO_GARBAGE(TiSpiAdapter * spi,uint8 c)
    {
        uint8 n = 0;
        char  value;
        CC2420_SPI_ENABLE();
        FAST2420_RX_ADDR(spi,CC2420_RXFIFO);
        for (n = 0; n < (c); n++) {
            FAST2420_RX_GARBAGE(spi, &value);
        }
        CC2420_SPI_DISABLE();
    }
Ejemplo n.º 11
0
void FAST2420_READ_FIFO(TiSpiAdapter * spi,uint8 *p,uint8 c)
    {
        uint8 n = 0;

        CC2420_SPI_ENABLE();
        FAST2420_RX_ADDR(spi,CC2420_RXFIFO);
        for (n = 0; n < (c); n++) {
            while (!VALUE_OF_FIFO());
            spi_get(spi,(char*)(p + n));
        }
        CC2420_SPI_DISABLE();
    }
// Set the channel fast and discard the first wrong readings
void my_set_channel(int ch)
{
  int k, temp;
  SPI_SETCHANNEL_SUPERFAST(357+((ch-11)*5)); // Approx. 292 us
  // Discard first 16 bad readings
  CC2420_SPI_ENABLE();
  for (k=0; k<=16; k++) {
    MY_FASTSPI_GETRSSI(temp);
  }
  clock_delay(1);
  CC2420_SPI_DISABLE();
}
Ejemplo n.º 13
0
void FAST2420_READ_RAM(TiSpiAdapter * spi,uint8 *p,uint16 a,uint8 c)
    {
    	uint8 n;
        CC2420_SPI_ENABLE();
        spi_put(spi,0x80 | (a & 0x7F));
        spi_put(spi,((a >> 1) & 0xC0) | 0x20);
        n = c;
        do {
            spi_get(spi,(char*)(p + (--n)));
        } while (n);
        CC2420_SPI_DISABLE();
    }
Ejemplo n.º 14
0
void FAST2420_WRITE_RAM(TiSpiAdapter * spi,uint16 *p,uint16 a,uint8 c)
   {
   	uint8 n;
        CC2420_SPI_ENABLE();
        spi_put(spi,0x80 | (a & 0x7F));
        spi_put(spi,(a >> 1) & 0xC0);
        n = c;
        do {
            spi_put(spi,((BYTE*)(p))[--n]);
        } while (n);
        CC2420_SPI_DISABLE();
    }
PROCESS_THREAD(interferer_example, ev, data)
{
 PROCESS_EXITHANDLER()  
 PROCESS_BEGIN();
 
 static struct etimer et;
 //powertrace_start(CLOCK_SECOND * 2);

 // Initial configurations on CC2420: channel and tx power
 watchdog_stop();
 cc2420_set_txpower(power);
 cc2420_set_channel(26);
 //printf("interfering with periodic interference\n"); 
 // Continuous Interference
 
 CC2420_SPI_ENABLE();
 
 //SPI_SET_UNMODULATED(0x1800,0x0100,0x0508,0x0004);
 SPI_SET_MODULATED(0x050C);
 
 //powertrace_start(CLOCK_SECOND*2);

 while(1){	
 
 for(power=3; power<32; power+=4){
 SPI_SET_TXPOWER((0xa0ff & 0xffe0) | (power & 0x1f));
 etimer_set(&et, CLOCK_SECOND/1000);
 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
 //printf ("transmit power = %d\n",power);
 }
 
 for(power=27; power>3; power-=4){
 SPI_SET_TXPOWER((0xa0ff & 0xffe0) | (power & 0x1f));
 etimer_set(&et, CLOCK_SECOND/1000);
 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
 //printf ("transmit power = %d\n",power);
 }
 
 for(power=3; power<32; power+=2){
 SPI_SET_TXPOWER((0xa0ff & 0xffe0) | (0 & 0x1f));
 etimer_set(&et, CLOCK_SECOND/1000);
 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
 //printf ("transmit power = %d\n",power);
 }
 
} 
 CC2420_SPI_DISABLE();
 void powertrace_stop(void); 
 PROCESS_WAIT_EVENT();  
 PROCESS_END();
}
Ejemplo n.º 16
0
/*---------------------------------------------------------------------------*/
void
cc2420_arch_init(void)
{
  spi_init();

  /* all input by default, set these as output */
  CC2420_CSN_PORT(DIR) |= BV(CC2420_CSN_PIN);
  CC2420_VREG_PORT(DIR) |= BV(CC2420_VREG_PIN);
  CC2420_RESET_PORT(DIR) |= BV(CC2420_RESET_PIN);

#if CONF_SFD_TIMESTAMPS
  cc2420_arch_sfd_init();
#endif

  CC2420_SPI_DISABLE();                /* Unselect radio. */
}
Ejemplo n.º 17
0
PROCESS_THREAD(scanning, ev, data)
{
 PROCESS_BEGIN();
 
 // Initial operations
 leds_off(LEDS_ALL);
 watchdog_stop(); 
 
 // Avoiding wrong RSSI readings
 unsigned temp;
 CC2420_READ_REG(CC2420_AGCTST1, temp);
 CC2420_WRITE_REG(CC2420_AGCTST1, (temp + (1 << 8) + (1 << 13))); 
 
 // Selecting the channel	
 SPI_SETCHANNEL_SUPERFAST(357+((CHANNEL-11)*5));
 
 // Avoiding the initial wrong readings by discarding the wrong readings
 CC2420_SPI_ENABLE();
 unsigned long k=0;
 for (k=0; k<=15; k++) {MY_FASTSPI_GETRSSI(temp);}
 CC2420_SPI_DISABLE(); 
 
 static struct etimer et;
 while(1){
	 	 
	 #if VERBOSE
	 printf("#START (dBm: occurrencies)\n");
	 #endif
	 
	 // Resetting everything
	 for(k=0;k<BUFFER_SIZE;k++){	
		buffer0[k] = 0;
	 }
	 
	 dint();				// Disable interrupts
	 boost_cpu(); 			// Temporarily boost CPU speed
	 CC2420_SPI_ENABLE(); 	// Enable SPI
	
	 // Actual scanning 
	 static signed char rssi;
	 for(k=0; k<MAX_VALUE; k++){		
		MY_FASTSPI_GETRSSI(rssi);	
		buffer0[rssi+55]++;
	 }	
 
	 CC2420_SPI_DISABLE();	// Disable SPI
	 restore_cpu();			// Restore CPU speed
	 eint(); 				// Re-enable interrupts
 
	 // Printing the stored values in compressed form 
	 unsigned long sum_cca = 0;
	 unsigned long max = 0, max_value = 0;
	 for(temp=0; temp<BUFFER_SIZE; temp++) {	
		sum_cca += (temp * buffer0[temp]);
		if(buffer0[temp] > max){
			max = buffer0[temp];
			max_value = temp;
		}		
	 }
	 
	 // Printing the results of the CCA
	 float f_cca = (((float) sum_cca*1.0000) / MAX_VALUE)-100.0000;		
	 #if VERBOSE
		printf("Average noise: %ld.%04u\nStatistic Mode noise: %ld\n", (long) f_cca, (unsigned)((f_cca-floor(f_cca))*10000), max_value-100);
	 #else
		printf("%ld.%04u\n", (long) f_cca, (unsigned)((f_cca-floor(f_cca))*10000));
	 #endif
	 
	 #if VERBOSE
		printf("#END\n");
	 #endif
	 
	 // Waiting for timer
	 etimer_set(&et, PERIOD_TIME);
	 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));	
 
 }
 
 PROCESS_WAIT_EVENT();
 
 PROCESS_END();
}
Ejemplo n.º 18
0
PROCESS_THREAD(markov_process, ev, data) {
    int new_state = b[0];
    int i,j;

    PROCESS_BEGIN();

    //etimer_set(&et, CLOCK_SECOND);
    //PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    // Initial configurations  on CC2420
    cc2420_set_txpower(MAX_POWER);
    cc2420_set_channel(INTERFERED_CHANNEL);
    watchdog_stop();

    printf("RAND_MAX %d INTMAX %d\n", RANDOM_RAND_MAX, INT_MAX);
    random_init(19);


    /* XXX should use formula */
    W[0]= 31;
    W[1]= 62;
    W[2]= 124;
    W[3]= 248;
    W[4]= 496;
    W[5]= 992;
    W[6]= 1023;
    W[7]= 1023;

    for(i=0; i<NRSTATES; i++) {
        b[i] = bSTATE_MIN+i;
        B[i] = BSTATE_MIN+i;
        bctr[i] = 0;
        Bctr[i] = 0;
        ALFA[i] = 2.0/((float)W[i]);
        BETA[i] = 2.0/((float)(W[i]-1));
    }

    printf("a %d, b %d, c %d d %d BETA1 %d\n",
           100*((1-P)*ALFA[0]),
           100*((1-P)*(1-ALFA[0])),
           100*(P*ALFA[1]),
           100*(P*(1-ALFA[1])),
           100*BETA[1]);


    /* this is the first "dry" run where we compute the state for
       the real run */
    new_state = b[0];
    for(i=0; i<SAVESTATES; i++) {
        sstate [i] = 0;
        visits[i] = 0;
    }
    while (cs<SAVESTATES) {
        new_state = compute_state(new_state);
    }
    new_state = b[0];

    /* now we start the real run */
    cur_state = 0;
    cur_visits = 0;

    CC2420_SPI_ENABLE();

#if 0
    while (cs<) {
        ctr++;
        if (ctr % 100 == 0) {
            int ctr_sum = 0;
            printf("time %f\n", time);
            float b = 0;
            for(i=bSTATE_MIN; i<bSTATE_MIN+NRSTATES; i++) {
                printf("counter[%d]: %d\n", i, bctr[i]);
                ctr_sum += bctr[i];
                b += timeb[i];
            }
            for(i= 0; i<NRSTATES; i++) {
                printf("counter[%d]: %d\n", i, Bctr[i]);
                ctr_sum += Bctr[i];
            }
            b = b / time;
            printf("counter %d percent in b: %f\n", ctr_sum, b);
        }
        if (ctr > MAX) {
            int ctr_sum = 0;
            float b = 0;
            for(i=bSTATE_MIN; i<bSTATE_MIN+NRSTATES; i++) {
                printf("counter[%d]: %d\n", i, bctr[i]);
                ctr_sum += bctr[i];
            }
            for(i= 0; i<NRSTATES; i++) {
                printf("counter[%d]: %d\n", i, Bctr[i]);
                ctr_sum += Bctr[i];
            }
            printf("counter %d percent in b: %f\n", ctr_sum, b);
            printf("ctrs: b0 %d B0 %d b1 %d B1 %d b5 %d B5 %d\n",
                   bctr[0], Bctr[0], bctr[1], Bctr[1], bctr[5], Bctr[5]);
            exit(1);
        }
        update_state();
    }
#endif
    printf("after modelling\n");
    j=0;
    for(i=0; i<SAVESTATES; i++) {
        //printf("state %d visits% d\n", sstate[i], visits[i]);
        j += visits[i];
    }
    printf("sum visits %d\n", j);
    /* correct very first state */
    if (visits[0] == 0)
        visits[0] = 1;

    ctr = 0;
    printf("--------- real run -------------\n");
    update_state();

    CC2420_SPI_DISABLE();
    PROCESS_END();
}
Ejemplo n.º 19
0
// Updates the SPI status byte
void FAST2420_UPD_STATUS(TiSpiAdapter * spi,uint8 *s)
    {
        CC2420_SPI_ENABLE();
        spi_get(spi,(char*)s);
        CC2420_SPI_DISABLE();
    }
Ejemplo n.º 20
0
PROCESS_THREAD(scanning, ev, data)
{
    PROCESS_BEGIN();

// Initial operations
    leds_off(LEDS_ALL);
    watchdog_stop();

// Avoiding wrong RSSI readings
    unsigned temp;
    CC2420_READ_REG(CC2420_AGCTST1, temp);
    CC2420_WRITE_REG(CC2420_AGCTST1, (temp + (1 << 8) + (1 << 13)));

// Selecting the channel
    SPI_SETCHANNEL_SUPERFAST(357+((CHANNEL-11)*5));

// Avoiding the initial wrong readings by discarding the wrong readings
    CC2420_SPI_ENABLE();
    int k=0;
    for (k=0; k<=15; k++) {
        MY_FASTSPI_GETRSSI(temp);
    }
    CC2420_SPI_DISABLE();

    static struct etimer et;
    while(1) {

        // Resetting everything
        for(k=0; k<(BUFFER_SIZE/2); k++) {
            buffer1[k] = 0;
            buffer0[k] = 0;
        }

        printf("#START [dBm: occurrencies]\n");

        dint();				// Disable interrupts
        boost_cpu(); 			// Temporarily boost CPU speed
        CC2420_SPI_ENABLE(); 	// Enable SPI

        // Actual scanning
        static signed char rssi;
        int current = 0;
        int previous = 0;
        int cnt = 1;
        for(k=0; k<(BUFFER_SIZE/2);) {
            // Sample the RSSI fast
            MY_FASTSPI_GETRSSI(rssi);
            current = rssi + 55;
            if((current == previous)&&(cnt<255)) {
                cnt++;
            }
            else {
                buffer0[k] = previous;
                buffer1[k++] = cnt;
                cnt = 1;
                previous = current;
            }
        }

        CC2420_SPI_DISABLE();	// Disable SPI
        restore_cpu();			// Restore CPU speed
        eint(); 				// Re-enable interrupts

        // Printing the stored values in compressed form
        for(temp=0; temp<(BUFFER_SIZE/2); temp++) {
            printf("%d: %d\n",buffer0[temp] - 100, buffer1[temp]);
            clock_delay(30000);
        }

        printf("#END\n");

        // Waiting for timer
        etimer_set(&et, PERIOD_TIME);
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    }

    PROCESS_WAIT_EVENT();

    PROCESS_END();
}