Пример #1
0
void device_ptx_mode_esb(void)
{
  while(true)
  {
    // Wait til the packet is sent
    do {
      radio_irq ();
    } while((radio_get_status ()) == RF_BUSY);

    // Blink LED2 if ACK is recieved, LED3 if not
    if (((radio_get_status ()) == RF_TX_DS))
    {
      LED2_BLINK();
    }
    else
    {
      LED3_BLINK();
    }

    // Sleep 100ms
    start_timer(100);
    wait_for_timer();

    // Set up the payload according to the input button 1
    pload_esb[0] = 0;

    if(B1_PRESSED())
    {
      pload_esb[0] = 1;
    }

    //Send the packet
    radio_send_packet(pload_esb, RF_PAYLOAD_LENGTH);           
  }
}
Пример #2
0
/* Repeater mode, for use with a standalone dev board */
void repeater_mode() {
  CLKCON = (1<<7) | (0<<6) | (0<<3) | (0<<0); //26MHz crystal oscillator for cpu and timer
  while (CLKCON & CLKCON_OSC);  //wait for clock stability
  
  P1DIR=0x03;   //LEDs on P1.1 and P1.0

#define LEDR P1_1
#define LEDG P1_0
  clock_delayms(100);

  radio_init();
  
  clock_delayms(100);

//    clear();
  while (1) {
    LEDR = 1; LEDG = 0;
  //  print_message(" ",2,0);
  //  print_message(" ",3,0);
  //  print_message("* Listening...        ",0,0);
    radio_listen();
    while (!radio_receive_poll(buf)) {
      clock_delayms(100);
      LEDG ^= 1;
  //    SSN = LOW;
  //    setCursor(0, 15*5);
  //    printf("%d %d %d", rf_packet_ix, rf_packet_n, rf_packet[0]); 
  //    SSN = HIGH;
    }
    buf[21]='\0';
 //   print_message("                                       ",1,0);
 //   print_message(buf, 1, 0);

    LEDR = 0; LEDG = 0;

    RFST = RFST_SIDLE;
    clock_delayms(3000);

    LEDR = 0; LEDG = 1;
 //   print_message("* Sending...",2,0);

    radio_send_packet(buf, strlen(buf) + 1);
    while (radio_still_sending()) {          
      clock_delayms(100);
 //     SSN = LOW;
 //     setCursor(2, 15*5);
 //     printf("%d %d %d", rf_packet_ix, rf_packet_n, rf_packet[0]); 
 //     SSN = HIGH;
    }
 //   print_message("* SENT!", 3, 0);
    RFST = RFST_SIDLE;
    clock_delayms(100);

  }
}
Пример #3
0
/* For debugging, a simple test of the radio. */
void run_test_radio() {
  uint8_t wait_col = 55;
  uint8_t num_rcvd;

  clear();
  display_print_message("SENDING MSG", 0, 0);

  radio_send_packet("CORN MUFFIN", 11);
  while (radio_still_sending()) {          
    clock_delayms(100);
    display_print_message(".", 0, wait_col);
    wait_col += 5;
  }

  display_print_message("SENT! WAITING..", 1, 0);
  
  num_rcvd = radio_recv_packet_block(buf);
  buf[21]='\0';
  display_print_message(buf, 2, 0);
    
  setDisplayStart(0);
  SSN = LOW;
  setCursor(3, 0);
  printf("%d bytes RSSI=%d LQI=%02X", num_rcvd, radio_last_rssi, radio_last_lqi);
  SSN = HIGH;

  RFST = RFST_SIDLE;
  clock_delayms(100);
  
  display_print_message("SENDING ANOTHER", 4, 0);

  radio_send_packet("POOP", 5);
  while (radio_still_sending()) {          
    clock_delayms(100);
    SSN = LOW;
    setCursor(5, 0);
    printf("%d %d %d", rf_packet_ix, rf_packet_n, rf_packet[0]); 
    SSN = HIGH;
  }

  display_print_message("SENT!", 5, 0);
}
Пример #4
0
// ------------------------------------------------------------------------------------------------
// Transmission test with interrupt handling
int radio_transmit_test_int(spi_parms_t *spi_parms, arguments_t *arguments)
// ------------------------------------------------------------------------------------------------
{
    init_radio_int(spi_parms, arguments);
    PI_CC_SPIStrobe(spi_parms, PI_CCxxx0_SFTX); // Flush Tx FIFO

    verbprintf(0, "Sending %d test packets of size %d\n", arguments->repetition, arguments->packet_length);

    while(packets_sent < arguments->repetition)
    {
        radio_wait_free(); // make sure no radio operation is in progress
        radio_send_packet(spi_parms, arguments, arguments->test_phrase, strlen(arguments->test_phrase));
        radio_wait_a_bit(arguments->packet_length / 4);
    }
}
Пример #5
0
/************************************************
 * Description: PHY layer's main FSM service.
 *
 * Arguments:
 * 	None.
 * Return:
 * 	None.
 *
 * Date: 2010-05-20
 ***********************************************/
void phy_FSM()
{
	switch (phy_state)
	{
		case PHY_STATE_IDLE:
			hal_idle();	// Hal Layer might want to do something in idle state
			break;
		case PHY_STATE_COMMAND_START:
			switch(a_phy_service.cmd)
			{
				case LRWPAN_SVC_PHY_INIT_HAL:	//not split phase
					a_phy_service.status = hal_init();
					phy_state = PHY_STATE_IDLE;
					break;
				case LRWPAN_SVC_PHY_TX_DATA:
					phy_pib.flags.bits.txFinished = 0;
					a_phy_service.status = radio_send_packet();
					if (a_phy_service.status == LRWPAN_STATUS_SUCCESS)
					{
						//TX started, wait for it to end.
						phy_state = PHY_STATE_TX_WAIT;
					}
					else
					{
						// Something failed, will give up on this,
						// MAC can take action if it wants
						phy_state = PHY_STATE_IDLE;
					}
					break;
				default: break;
			}//end switch cmd
			break;
		case PHY_STATE_TX_WAIT:  //wait for TX out of radio to complete or timeout
			if (phy_pib.flags.bits.txFinished)
				phy_state = PHY_STATE_IDLE;
			break;
		default:
			break;
	}//end switch phy_state
}
Пример #6
0
static void send_message() {

//  while(1) {

  SSN = LOW;
  setDisplayStart(0);
  setCursor(6, 0);
  printf("Transmitting!");

  radio_send_packet(compose_buffer_);
  setCursor(7, 0);
  putchar('8');
  SSN = HIGH;
  
  while (radio_still_sending()) {
    clock_delayms(400);
    SSN = LOW;
    putchar('=');
    SSN = HIGH;
  }
  radio_listen(); // go back into receive mode

  clock_delayms(500);
  SSN = LOW;
  putchar('D');
  SSN = HIGH;
  clock_delayms(500);

//  }

  /* Reset the compose view. */
  state_ = COMPOSE_STATE_WRITING;
  compose_new_message();


  /* Switch back to the inbox view. */
  switch_state(STATE_VIEW);
}
Пример #7
0
// ------------------------------------------------------------------------------------------------
// Simple echo test
void radio_test_echo(spi_parms_t *spi_parms, radio_parms_t *radio_parms, arguments_t *arguments, uint8_t active)
// ------------------------------------------------------------------------------------------------
{
    uint8_t  nb_bytes, rtx_bytes[RADIO_BUFSIZE];
    uint8_t  rtx_toggle, rtx_count;
    uint32_t timeout_value, timeout;
    struct timeval tdelay, tstart, tstop;

    init_radio_int(spi_parms, arguments);
    radio_flush_fifos(spi_parms);

    timeout_value = (uint32_t) (arguments->packet_length * 10 * radio_get_byte_time(radio_parms));
    timeout = 0;

    if (active)
    {
        nb_bytes = strlen(arguments->test_phrase);
        strcpy(rtx_bytes, arguments->test_phrase);
        rtx_toggle = 1;
    }
    else
    {
        rtx_toggle = 0;
    }

    while (packets_sent < arguments->repetition)
    {
        rtx_count = 0;

        do // Rx-Tx transaction in whichever order
        {
            if (arguments->tnc_keyup_delay)
            {
                usleep(arguments->tnc_keyup_delay);
            }

            if (rtx_toggle) // Tx
            {
                verbprintf(0, "Sending #%d\n", packets_sent);

                radio_wait_free(); // make sure no radio operation is in progress
                radio_send_packet(spi_parms, arguments, rtx_bytes, nb_bytes);
                radio_wait_a_bit(4);
                timeout = timeout_value; // arm Rx timeout
                rtx_count++;
                rtx_toggle = 0; // next is Rx
            }

            if (rtx_count >= 2)
            {
                break;
            }

            if (arguments->tnc_keydown_delay)
            {
                usleep(arguments->tnc_keydown_delay);
            }

            if (!rtx_toggle) // Rx
            {
                verbprintf(0, "Receiving #%d\n", packets_received);

                radio_init_rx(spi_parms, arguments); // Init for new packet to receive
                radio_turn_rx(spi_parms);            // Put back into Rx

                if (timeout > 0)
                {
                    gettimeofday(&tstart, NULL);
                }

                do
                {
                    radio_wait_free(); // make sure no radio operation is in progress
                    nb_bytes = radio_receive_packet(spi_parms, arguments, rtx_bytes);
                    radio_wait_a_bit(4);

                    if (timeout > 0)
                    {
                        gettimeofday(&tstop, NULL);
                        timeval_subtract(&tdelay, &tstop, &tstart);

                        if (ts_us(&tdelay) > timeout)
                        {
                            verbprintf(0, "Time out reached. Faking receiving data\n");
                            nb_bytes = strlen(arguments->test_phrase);
                            strcpy(rtx_bytes, arguments->test_phrase);
                            break;
                        }
                    }

                } while (nb_bytes == 0);

                rtx_count++;
                rtx_toggle = 1; // next is Tx
            }

        } while(rtx_count < 2);
    }
}
Пример #8
0
// ------------------------------------------------------------------------------------------------
// Run the KISS virtual TNC
void kiss_run(serial_t *serial_parms, spi_parms_t *spi_parms, arguments_t *arguments)
// ------------------------------------------------------------------------------------------------
{
    static const size_t   bufsize = RADIO_BUFSIZE;
    uint32_t timeout_value;
    uint8_t  rx_buffer[bufsize], tx_buffer[bufsize];
    uint8_t  rtx_toggle; // 1:Tx, 0:Rx
    uint8_t  rx_trigger; 
    uint8_t  tx_trigger; 
    uint8_t  force_mode;
    int      rx_count, tx_count, byte_count, ret;
    uint64_t timestamp;
    struct timeval tp;  

    set_serial_parameters(serial_parms, arguments);
    init_radio_int(spi_parms, arguments);
    memset(rx_buffer, 0, bufsize);
    memset(tx_buffer, 0, bufsize);
    radio_flush_fifos(spi_parms);
    
    verbprintf(1, "Starting...\n");

    force_mode = 1;
    rtx_toggle = 0;
    rx_trigger = 0;
    tx_trigger = 0;
    rx_count = 0;
    tx_count = 0;
    radio_init_rx(spi_parms, arguments); // init for new packet to receive Rx
    radio_turn_rx(spi_parms);            // Turn Rx on

    while(1)
    {    
        byte_count = radio_receive_packet(spi_parms, arguments, &rx_buffer[rx_count]); // check if anything was received on radio link

        if (byte_count > 0)
        {
            rx_count += byte_count;  // Accumulate Rx
            
            gettimeofday(&tp, NULL);
            timestamp = tp.tv_sec * 1000000ULL + tp.tv_usec;
            timeout_value = arguments->tnc_radio_window;
            force_mode = (timeout_value == 0);

            if (rtx_toggle) // Tx to Rx transition
            {
                tx_trigger = 1; // Push Tx
            }
            else
            {
                tx_trigger = 0;
            }

            radio_init_rx(spi_parms, arguments); // Init for new packet to receive
            rtx_toggle = 0;
        }

        byte_count = read_serial(serial_parms, &tx_buffer[tx_count], bufsize - tx_count);

        if (byte_count > 0)
        {
            tx_count += byte_count;  // Accumulate Tx

            gettimeofday(&tp, NULL);
            timestamp = tp.tv_sec * 1000000ULL + tp.tv_usec;
            timeout_value = arguments->tnc_serial_window;
            force_mode = (timeout_value == 0);

            if (!rtx_toggle) // Rx to Tx transition
            {
                rx_trigger = 1;
            }
            else
            {
                rx_trigger = 0;
            }

            rtx_toggle = 1;
        }

        if ((rx_count > 0) && ((rx_trigger) || (force_mode))) // Send bytes received on air to serial
        {
            radio_wait_free();            // Make sure no radio operation is in progress
            radio_turn_idle(spi_parms);   // Inhibit radio operations
            verbprintf(2, "Received %d bytes\n", rx_count);
            ret = write_serial(serial_parms, rx_buffer, rx_count);
            verbprintf(2, "Sent %d bytes on serial\n", ret);
            radio_init_rx(spi_parms, arguments); // Init for new packet to receive Rx
            radio_turn_rx(spi_parms);            // Put back into Rx
            rx_count = 0;
            rx_trigger = 0;
        }

        if ((tx_count > 0) && ((tx_trigger) || (force_mode))) // Send bytes received on serial to air 
        {
            if (!kiss_command(tx_buffer))
            {
                radio_wait_free();            // Make sure no radio operation is in progress
                radio_turn_idle(spi_parms);   // Inhibit radio operations (should be superfluous since both Tx and Rx turn to IDLE after a packet has been processed)
                radio_flush_fifos(spi_parms); // Flush result of any Rx activity

                verbprintf(2, "%d bytes to send\n", tx_count);

                if (tnc_tx_keyup_delay)
                {
                    usleep(tnc_tx_keyup_delay);
                }

                radio_send_packet(spi_parms, arguments, tx_buffer, tx_count);

                radio_init_rx(spi_parms, arguments); // init for new packet to receive Rx
                radio_turn_rx(spi_parms);            // put back into Rx
            }

            tx_count = 0;
            tx_trigger = 0;            
        }

        if (!force_mode)
        {
            gettimeofday(&tp, NULL);

            if ((tp.tv_sec * 1000000ULL + tp.tv_usec) > timestamp + timeout_value)
            {
                force_mode = 1;
            }                        
        }

        radio_wait_a_bit(4);
    }
}