/**@brief   Function for handling timeslots in a context with elevated priority.
 */
void QDEC_IRQHandler(void)
{
    // This is called here instead of in the uesb_event_handler for two reasons:
    // 1) Updating the uESB params shouldn't have to lag behind transmissions
    // 2) m_tx_callback should not be run at RADIO_IRQHandler priority
    syma_update((uint8_t*)&m_uesb_config.rf_channel,
		(uint8_t*)&m_uesb_config.rx_address_p0[0],
		(uint8_t*)&m_uesb_config.rf_addr_length,
		(uint8_t*)&m_tx_payload.data[0],
		(uint8_t*)&m_tx_payload.length);

    m_uesb_config.payload_length = m_tx_payload.length;

    if (UESB_SUCCESS != uesb_init((uesb_config_t*)&m_uesb_config))
    {
	app_error_handler(PROPRIETARY_RF_DEBUG,
			  __LINE__,
			  (const uint8_t*)__FILE__);
    }

    if(UESB_SUCCESS != uesb_write_tx_payload((uesb_payload_t*) &m_tx_payload))
    {
	app_error_handler(PROPRIETARY_RF_DEBUG,
			  __LINE__,
			  (const uint8_t*)__FILE__);
    }
}
예제 #2
0
파일: main.c 프로젝트: JulianYG/WNR
int send_data(uint8_t *data, int length)
{
	for (int i = 0; i < length; ++i) {
		tx_payload.data[i % 8] = data[i];
		if (i > 0 && i % 8 == 0)
			uesb_write_tx_payload(&tx_payload);
	}
}
/**@brief IRQHandler used for execution context management. 
  *        Any available handler can be used as we're not using the associated hardware.
  *        This handler is used to initiate UESB RX/TX
  */
void TIMESLOT_BEGIN_IRQHandler(void)
{
    uesb_payload_t payload;
    uint32_t       payload_len;
    uint32_t       err_code;
    
    uesb_init(&m_uesb_config);
    
    // Packet transmission is syncrhonized to the beginning of timeslots
    // Check FIFO for packets and transmit if not empty
    if (m_transmit_fifo.free_items < sizeof(m_transmit_fifo.buf) && m_ut_state != UT_STATE_TX)
    {
        // There are packets in the FIFO: Start transmitting
        payload_len = sizeof(payload);
        
        // Copy packet from FIFO. Packet isn't removed until transmissions succeeds or max retries has been exceeded
        if (m_tx_attempts < MAX_TX_ATTEMPTS)
        {        
            fifo_peek_pkt(&m_transmit_fifo, (uint8_t *) &payload, &payload_len);
            APP_ERROR_CHECK_BOOL(payload_len == sizeof(payload));
        }
        else
        {
            fifo_get_pkt(&m_transmit_fifo, (uint8_t *) &payload, &payload_len);
            APP_ERROR_CHECK_BOOL(payload_len == sizeof(payload));
            
            m_tx_attempts = 0;
        }
        
        if (m_ut_state == UT_STATE_RX)
        {
            uesb_stop_rx();
        }
        
        err_code = uesb_write_tx_payload(&payload);
        APP_ERROR_CHECK(err_code);
        
        m_ut_state = UT_STATE_TX;
    }
    else
    {
        // No packets in the FIFO: start reception
        err_code = uesb_start_rx();
        m_ut_state = UT_STATE_RX;

    }
}