/**
 * @file tal_irq_handler.c
 *
 * @brief This file handles the interrupts generated by the transceiver.
 *
 * $Id: tal_irq_handler.c 24720 2011-01-05 15:33:06Z sschneid $
 *
 * @author    Atmel Corporation: http://www.atmel.com
 * @author    Support email: avr@atmel.com
 */
/*
 * Copyright (c) 2009, Atmel Corporation All rights reserved.
 *
 * Licensed under Atmel's Limited License Agreement --> EULA.txt
 */

/* === INCLUDES ============================================================ */

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "pal.h"
#include "return_val.h"
#include "tal.h"
#include "ieee_const.h"
#include "stack_config.h"
#include "bmm.h"
#include "qmm.h"
#include "tal_irq_handler.h"
#include "tal_rx.h"
#include "atmega128rfa1.h"
#include "tal_internal.h"
#include "tal_constants.h"
#include "tal_tx.h"
#include "mac_build_config.h"

/* === TYPES =============================================================== */


/* === MACROS ============================================================== */


/* === GLOBALS ============================================================= */


/* === PROTOTYPES ========================================================== */


/* === IMPLEMENTATION ====================================================== */

/**
 * @brief Transceiver interrupt handler
 *
 * This function handles the transceiver generated interrupts for RX end.
 */
void trx_rx_end_handler_cb(void)
{
    ENTER_CRITICAL_REGION();

    /* Handle rx interrupt. */
    handle_received_frame_irq();    // see tal_rx.c

    LEAVE_CRITICAL_REGION();
}/* trx_rx_end_handler_cb() */


/**
 * @brief Transceiver interrupt handler
 *
 * This function handles the transceiver generated interrupts for TX end.
 */
void trx_tx_end_handler_cb(void)
{
    ENTER_CRITICAL_REGION();

    /* Get the result and push it to the queue. */
    handle_tx_end_irq();            // see tal_tx.c

    LEAVE_CRITICAL_REGION();
}/* trx_tx_end_handler_cb() */


#if (defined BEACON_SUPPORT) || (defined ENABLE_TSTAMP)
/**
 * @brief Timestamp interrupt handler
 *
 * This function handles the interrupts handling the timestamp.
 * The timestamping is only required for beaconing networks
 * or if timestamping is explicitly enabled.
 */
void trx_irq_timestamp_handler_cb(void)
{
    /* The timestamping is only required for beaconing networks
     * or if timestamping is explicitly enabled.
     */
    pal_trx_read_timestamp(&tal_rx_timestamp);
}
#endif /* (defined BEACON_SUPPORT) || (defined ENABLE_TSTAMP) */

/**
 * @brief Transceiver interrupt handler for awake end IRQ
 *
 * This function handles the transceiver awake end interrupt.
 */
void trx_awake_handler_cb(void)
{
    /* Set the wake-up flag. */
    tal_awake_end_flag = true;
}
/* EOF */

