/**************************************************************************************************
Filename: mac_tx.c
Revised: $Date: 2007-10-15 14:56:36 -0700 (Mon, 15 Oct 2007) $
Revision: $Revision: 15687 $
Description: Describe the purpose and contents of the file.
Copyright 2006-2007 Texas Instruments Incorporated. All rights reserved.
IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose.
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED �AS IS?WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
**************************************************************************************************/
/* ------------------------------------------------------------------------------------------------
* Includes
* ------------------------------------------------------------------------------------------------
*/
/* hal */
#include "hal_types.h"
#include "hal_defs.h"
#include "hal_mcu.h"
#include "hal_mac_cfg.h"
/* high-level */
#include "mac_spec.h"
#include "mac_pib.h"
/* exported low-level */
#include "mac_low_level.h"
/* low-level specific */
#include "mac_tx.h"
#include "mac_backoff_timer.h"
#include "mac_rx.h"
#include "mac_rx_onoff.h"
#include "mac_radio.h"
#include "mac_sleep.h"
/* target specific */
#include "mac_radio_defs.h"
/* debug */
#include "mac_assert.h"
/* ------------------------------------------------------------------------------------------------
* Defines
* ------------------------------------------------------------------------------------------------
*/
#define MFR_LEN MAC_FCS_FIELD_LEN
#define PREPENDED_BYTE_LEN 1
/* ------------------------------------------------------------------------------------------------
* Global Constants
* ------------------------------------------------------------------------------------------------
*/
/*
* This is the time, in backoffs, required to set up a slotted transmit.
* It is exported to high level so that code can schedule enough time
* for slotted transmits.
*
* A default is provided if a value is not specified. If the default
* is not appropriate, a #define should be added within hal_mac_cfg.h.
*/
#ifndef HAL_MAC_TX_SLOTTED_DELAY
#define HAL_MAC_TX_SLOTTED_DELAY 3
#endif
uint8 const macTxSlottedDelay = HAL_MAC_TX_SLOTTED_DELAY;
/* ------------------------------------------------------------------------------------------------
* Global Variables
* ------------------------------------------------------------------------------------------------
*/
uint8 macTxActive;
uint8 macTxType;
uint8 macTxBe;
uint8 macTxCsmaBackoffDelay;
/* ------------------------------------------------------------------------------------------------
* Local Variables
* ------------------------------------------------------------------------------------------------
*/
static uint8 nb;
static uint8 txSeqn;
static uint8 txAckReq;
static uint8 txRetransmitFlag;
/* ------------------------------------------------------------------------------------------------
* Local Prototypes
* ------------------------------------------------------------------------------------------------
*/
static void txCsmaPrep(void);
static void txGo(void);
static void txCsmaGo(void);
static void txComplete(uint8 status);
/**************************************************************************************************
* @fn macTxInit
*
* @brief Initialize variables for tx module.
*
* @param none
*
* @return none
**************************************************************************************************
*/
void macTxInit(void)
{
macTxActive = MAC_TX_ACTIVE_NO_ACTIVITY;
txRetransmitFlag = 0;
}
/**************************************************************************************************
* @fn macTxHaltCleanup
*
* @brief -
*
* @param none
*
* @return none
**************************************************************************************************
*/
void macTxHaltCleanup(void)
{
MAC_RADIO_TX_RESET();
macTxInit();
}
/**************************************************************************************************
* @fn macTxFrame
*
* @brief Transmit the frame pointed to by pMacDataTx with the specified type.
* NOTE! It is not legal to call this function from interrupt context.
*
* @param txType - type of transmit
*
* @return none
**************************************************************************************************
*/
void macTxFrame(uint8 txType)
{
MAC_ASSERT(!macTxActive); /* transmit on top of transmit */
/* mark transmit as active */
macTxActive = MAC_TX_ACTIVE_INITIALIZE;
/*
* The MAC will not enter sleep mode if there is an active transmit. However, if macSleep() is
* ever called from interrupt context, it possible to enter sleep state after a transmit is
* intiated but before macTxActive is set. To recover from this, the transmit must be aborted
* and proper notificiation given to high-level.
*/
if (macSleepState != MAC_SLEEP_STATE_AWAKE)
{
/* notify high-level that transmit had to be aborted */
txComplete(MAC_TX_ABORTED);
/* exit from transmit logic */
return;
}
/* save transmit type */
macTxType = txType;