コード例 #1
0
/*
 * \brief Parses received frame and create the frame_info_t structure
 *
 * This function parses the received frame and creates the frame_info_t
 * structure to be sent to the MAC as a parameter of tal_rx_frame_cb().
 *
 * \param buf Pointer to the buffer containing the received frame
 */
void process_incoming_frame(buffer_t *buf_ptr)
{
#ifndef TRX_REG_RAW_VALUE
    uint8_t frame_len;
    uint8_t *frame_ptr;
    uint8_t ed_level;
    uint8_t lqi;
#endif

    frame_info_t *receive_frame = (frame_info_t *)BMM_BUFFER_POINTER(buf_ptr);

    /* The frame is present towards the end of the buffer. */

#ifndef TRX_REG_RAW_VALUE
    /*
     * Store the last frame length for IFS handling.
     * Substract LQI and length fields.
     */
    frame_len = last_frame_length = receive_frame->mpdu[0];
#else
    last_frame_length = receive_frame->mpdu[0];
#endif

#ifdef PROMISCUOUS_MODE
    if (tal_pib.PromiscuousMode)
    {
#ifndef TRX_REG_RAW_VALUE
        frame_ptr = &(receive_frame->mpdu[frame_len + LQI_LEN]);

        /*
         * The LQI is stored after the FCS.
         * The ED value is stored after the LQI.
         */
        lqi = *frame_ptr++;
        ed_level = *frame_ptr;

        /*
         * The LQI normalization is done using the ED level measured during
         * the frame reception.
         */
#ifdef RSSI_TO_LQI_MAPPING
        lqi = normalize_lqi(ed_level);
#else
        lqi = normalize_lqi(lqi, ed_level);
#endif

        /* Store normalized LQI value again. */
        frame_ptr--;
        *frame_ptr = lqi;
#endif  /* #ifndef TRX_REG_RAW_VALUE */

        receive_frame->buffer_header = buf_ptr;

        /* The callback function implemented by MAC is invoked. */
        tal_rx_frame_cb(receive_frame);

        return;
    }
#endif   /* #ifdef PROMISCUOUS_MODE */

#ifdef BEACON_SUPPORT
    /*
     * Are we waiting for a beacon for slotted CSMA?
     * Check if received frame is a beacon.
     */
    if ((receive_frame->mpdu[PL_POS_FCF_1] & FCF_FRAMETYPE_MASK) == FCF_FRAMETYPE_BEACON)
    {
        /* Debug pin to switch on: define ENABLE_DEBUG_PINS, pal_config.h */
        PIN_BEACON_START();

        if (tal_csma_state == BACKOFF_WAITING_FOR_BEACON)
        {
            /* Debug pin to switch on: define ENABLE_DEBUG_PINS, pal_config.h */
            PIN_WAITING_FOR_BEACON_END();
            tal_pib.BeaconTxTime = TAL_CONVERT_US_TO_SYMBOLS(receive_frame->time_stamp);
            tal_csma_state = CSMA_HANDLE_BEACON;
        }

        /* Debug pin to switch on: define ENABLE_DEBUG_PINS, pal_config.h */
        PIN_BEACON_END();
    }
#endif  /* BEACON_SUPPORT */

#ifndef TRX_REG_RAW_VALUE
    /*
     * The LQI is stored after the FCS.
     * The ED value is stored after the LQI.
     */
    frame_ptr = &(receive_frame->mpdu[frame_len + LQI_LEN]);
    lqi = *frame_ptr++;
    ed_level = *frame_ptr;

    /*
     * The LQI normalization is done using the ED level measured during
     * the frame reception.
     */
#ifdef RSSI_TO_LQI_MAPPING
    lqi = normalize_lqi(ed_level);
#else
    lqi = normalize_lqi(lqi, ed_level);
#endif

    /* Store normalized LQI value again. */
    frame_ptr--;
    *frame_ptr = lqi;
#endif  /* #ifndef TRX_REG_RAW_VALUE */

    receive_frame->buffer_header = buf_ptr;

#ifdef ENABLE_RTB
    /* The callback function implemented by RTB is invoked. */
    rtb_rx_frame_cb(receive_frame);
#else
    /* The callback function implemented by MAC is invoked. */
    tal_rx_frame_cb(receive_frame);
#endif
} /* process_incoming_frame() */
コード例 #2
0
void tal_tx_beacon(frame_info_t *tx_frame)
{
	tal_trx_status_t trx_status;

	/* Set pointer to actual mpdu to be downloaded to the transceiver. */
	uint8_t *tal_beacon_to_tx = tx_frame->mpdu;

	/*
	 * Avoid that the beacon is transmitted while transmitting
	 * a frame using slotted CSMA.
	 */
	if ((tal_csma_state == FRAME_SENDING_WITH_ACK) ||
			(tal_csma_state == FRAME_SENDING_NO_ACK) ||
			(tal_csma_state == WAITING_FOR_ACK)) {
		Assert(
				"trying to transmit beacon while ongoing transmission" ==
				0);
		return;
	}

	/* Send the pre-created beacon frame to the transceiver. */
	/* debug pin to switch on: define ENABLE_DEBUG_PINS, pal_config.h */
	PIN_BEACON_START();

	/* \TODO wait for talbeaconTxTime */
	do {
		trx_status = set_trx_state(CMD_FORCE_PLL_ON);
#if (_DEBUG_ > 1)
		if (trx_status != PLL_ON) {
			Assert("PLL_ON failed for beacon transmission" == 0);
		}

#endif
	} while (trx_status != PLL_ON);

	pal_trx_irq_dis();

	/* Toggle the SLP_TR pin triggering transmission. */
	PAL_SLP_TR_HIGH();
	PAL_WAIT_65_NS();
	PAL_SLP_TR_LOW();

	/*
	 * Send the frame to the transceiver.
	 * Note: The PhyHeader is the first byte of the frame to
	 * be sent to the transceiver and this contains the frame
	 * length.
	 * The actual length of the frame to be downloaded
	 * (parameter two of pal_trx_frame_write)
	 * is
	 * 1 octet frame length octet
	 * + n octets frame (i.e. value of frame_tx[0])
	 * - 2 octets FCS
	 */
	pal_trx_frame_write(tal_beacon_to_tx, tal_beacon_to_tx[0] - 1);

#ifndef NON_BLOCKING_SPI
	pal_trx_irq_en();
#endif

	tal_state = TAL_TX_BEACON;
}