A library implementing IEEE 802.15.4 PHY functionality for the MCR20A transceiver. The PHY sublayer provides two services: the PHY data service and the PHY management service interfacing to the PHY sublayer management entity (PLME) service access point (SAP) (known as PLME-SAP). The PHY data service enables the transmission and reception of PHY protocol data units (PSDUs) over the media (radio).

Fork of fsl_phy_mcr20a by Freescale

The Freescale PHY Layer deals with the physical burst which is to be sent and/or received. It performs modulation and demodulation, transmitter and receiver switching, fragmentation, scrambling, interleaving, and error correction coding. The communication to the upper protocol layers is carried out through the Layer 1 Interface.

The PHY Layer is capable of executing the following sequences:

  • I (Idle)
  • R (Receive Sequence conditionally followed by a TxAck)
  • T (Transmit Sequence)
  • C (Standalone CCA)
  • CCCA (Continuous CCA)
  • TR (Transmit/Receive Sequence - transmit unconditionally followed by either an R or RxAck)

In addition to these sequences the PHY Layer also integrates a packet processor which determines whether the packet is MAC-compliant, and if it is, whether it is addressed to the end device. Another feature of the packet processor is Source Address Matching which can be viewed as an extension of packet filtering; however its function is very specific to its intended application (data-polling and indirect queue management by a PAN Coordinator).

Documentation

MCR20A PHY Reference Manual

Committer:
andreikovacs
Date:
Tue Aug 18 12:41:42 2015 +0000
Revision:
0:764779eedf2d
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andreikovacs 0:764779eedf2d 1 /*!
andreikovacs 0:764779eedf2d 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
andreikovacs 0:764779eedf2d 3 * All rights reserved.
andreikovacs 0:764779eedf2d 4 *
andreikovacs 0:764779eedf2d 5 * \file MPM.c
andreikovacs 0:764779eedf2d 6 * This is the source file for the Multiple PAN Manager.
andreikovacs 0:764779eedf2d 7 *
andreikovacs 0:764779eedf2d 8 * Redistribution and use in source and binary forms, with or without modification,
andreikovacs 0:764779eedf2d 9 * are permitted provided that the following conditions are met:
andreikovacs 0:764779eedf2d 10 *
andreikovacs 0:764779eedf2d 11 * o Redistributions of source code must retain the above copyright notice, this list
andreikovacs 0:764779eedf2d 12 * of conditions and the following disclaimer.
andreikovacs 0:764779eedf2d 13 *
andreikovacs 0:764779eedf2d 14 * o Redistributions in binary form must reproduce the above copyright notice, this
andreikovacs 0:764779eedf2d 15 * list of conditions and the following disclaimer in the documentation and/or
andreikovacs 0:764779eedf2d 16 * other materials provided with the distribution.
andreikovacs 0:764779eedf2d 17 *
andreikovacs 0:764779eedf2d 18 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
andreikovacs 0:764779eedf2d 19 * contributors may be used to endorse or promote products derived from this
andreikovacs 0:764779eedf2d 20 * software without specific prior written permission.
andreikovacs 0:764779eedf2d 21 *
andreikovacs 0:764779eedf2d 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
andreikovacs 0:764779eedf2d 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
andreikovacs 0:764779eedf2d 24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
andreikovacs 0:764779eedf2d 25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
andreikovacs 0:764779eedf2d 26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
andreikovacs 0:764779eedf2d 27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
andreikovacs 0:764779eedf2d 28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
andreikovacs 0:764779eedf2d 29 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
andreikovacs 0:764779eedf2d 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
andreikovacs 0:764779eedf2d 31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
andreikovacs 0:764779eedf2d 32 */
andreikovacs 0:764779eedf2d 33
andreikovacs 0:764779eedf2d 34 /************************************************************************************
andreikovacs 0:764779eedf2d 35 *************************************************************************************
andreikovacs 0:764779eedf2d 36 * Include
andreikovacs 0:764779eedf2d 37 *************************************************************************************
andreikovacs 0:764779eedf2d 38 ************************************************************************************/
andreikovacs 0:764779eedf2d 39
andreikovacs 0:764779eedf2d 40 #include "EmbeddedTypes.h"
andreikovacs 0:764779eedf2d 41 #include "MpmInterface.h"
andreikovacs 0:764779eedf2d 42 #include "Phy.h"
andreikovacs 0:764779eedf2d 43
andreikovacs 0:764779eedf2d 44 #if 0
andreikovacs 0:764779eedf2d 45 #include "FunctionLib.h"
andreikovacs 0:764779eedf2d 46 #include "MemManager.h"
andreikovacs 0:764779eedf2d 47 #include "Panic.h"
andreikovacs 0:764779eedf2d 48 #endif
andreikovacs 0:764779eedf2d 49
andreikovacs 0:764779eedf2d 50 #if gMpmIncluded_d
andreikovacs 0:764779eedf2d 51
andreikovacs 0:764779eedf2d 52 /************************************************************************************
andreikovacs 0:764779eedf2d 53 *************************************************************************************
andreikovacs 0:764779eedf2d 54 * Public macros
andreikovacs 0:764779eedf2d 55 *************************************************************************************
andreikovacs 0:764779eedf2d 56 ************************************************************************************/
andreikovacs 0:764779eedf2d 57
andreikovacs 0:764779eedf2d 58 /************************************************************************************
andreikovacs 0:764779eedf2d 59 *************************************************************************************
andreikovacs 0:764779eedf2d 60 * Public type definitions
andreikovacs 0:764779eedf2d 61 *************************************************************************************
andreikovacs 0:764779eedf2d 62 ************************************************************************************/
andreikovacs 0:764779eedf2d 63
andreikovacs 0:764779eedf2d 64 /************************************************************************************
andreikovacs 0:764779eedf2d 65 *************************************************************************************
andreikovacs 0:764779eedf2d 66 * Private memory declarations
andreikovacs 0:764779eedf2d 67 *************************************************************************************
andreikovacs 0:764779eedf2d 68 ************************************************************************************/
andreikovacs 0:764779eedf2d 69 uint8_t mRegisteredPANs;
andreikovacs 0:764779eedf2d 70 bool_t mMpmExclusiveAccess;
andreikovacs 0:764779eedf2d 71 panInfo_t mPanInfo[gMpmMaxPANs_c];
andreikovacs 0:764779eedf2d 72 panInfo_t *pActivePANs[gMpmPhyPanRegSets_c];
andreikovacs 0:764779eedf2d 73
andreikovacs 0:764779eedf2d 74 /************************************************************************************
andreikovacs 0:764779eedf2d 75 *************************************************************************************
andreikovacs 0:764779eedf2d 76 * Private functions prototypes
andreikovacs 0:764779eedf2d 77 *************************************************************************************
andreikovacs 0:764779eedf2d 78 ************************************************************************************/
andreikovacs 0:764779eedf2d 79 static void MPM_SetPanSettingsInPhy( uint8_t panIndex );
andreikovacs 0:764779eedf2d 80 static uint8_t MPM_AllocateResource( bool_t force, uint8_t panIdx );
andreikovacs 0:764779eedf2d 81
andreikovacs 0:764779eedf2d 82 /************************************************************************************
andreikovacs 0:764779eedf2d 83 *************************************************************************************
andreikovacs 0:764779eedf2d 84 * Public functions
andreikovacs 0:764779eedf2d 85 *************************************************************************************
andreikovacs 0:764779eedf2d 86 ************************************************************************************/
andreikovacs 0:764779eedf2d 87
andreikovacs 0:764779eedf2d 88 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 89 * \brief This function determines the instance of the MAC associated with a PHY regSet
andreikovacs 0:764779eedf2d 90 *
andreikovacs 0:764779eedf2d 91 * \param[in] regSet The PHY registry set
andreikovacs 0:764779eedf2d 92 *
andreikovacs 0:764779eedf2d 93 * \return The instance of the MAC associated with a PHY registry set.
andreikovacs 0:764779eedf2d 94 *
andreikovacs 0:764779eedf2d 95 ********************************************************************************** */
andreikovacs 0:764779eedf2d 96 uint32_t MPM_GetMacInstanceFromRegSet(uint32_t regSet)
andreikovacs 0:764779eedf2d 97 {
andreikovacs 0:764779eedf2d 98 if( pActivePANs[regSet] )
andreikovacs 0:764779eedf2d 99 return pActivePANs[regSet]->macInstance;
andreikovacs 0:764779eedf2d 100
andreikovacs 0:764779eedf2d 101 return 0;
andreikovacs 0:764779eedf2d 102 }
andreikovacs 0:764779eedf2d 103
andreikovacs 0:764779eedf2d 104 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 105 * \brief This function determines the PHY regSet for the specified panIndex
andreikovacs 0:764779eedf2d 106 *
andreikovacs 0:764779eedf2d 107 * \param[in] panIdx The index in mPanInfo[] table
andreikovacs 0:764779eedf2d 108 *
andreikovacs 0:764779eedf2d 109 * \return The PHY registry set.
andreikovacs 0:764779eedf2d 110 *
andreikovacs 0:764779eedf2d 111 ********************************************************************************** */
andreikovacs 0:764779eedf2d 112 uint32_t MPM_GetRegSet( uint8_t panIdx )
andreikovacs 0:764779eedf2d 113 {
andreikovacs 0:764779eedf2d 114 return mPanInfo[panIdx].phyRegSet;
andreikovacs 0:764779eedf2d 115 }
andreikovacs 0:764779eedf2d 116
andreikovacs 0:764779eedf2d 117 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 118 * \brief This function determines the PHY regSet for the specified panIndex
andreikovacs 0:764779eedf2d 119 *
andreikovacs 0:764779eedf2d 120 * \param[in] pibId The id of the PHY PIB
andreikovacs 0:764779eedf2d 121 * \param[in] pValue The value of the PHY PIB
andreikovacs 0:764779eedf2d 122 * \param[in] panIdx The index in mPanInfo[] table
andreikovacs 0:764779eedf2d 123 *
andreikovacs 0:764779eedf2d 124 * \return The status of the operation.
andreikovacs 0:764779eedf2d 125 *
andreikovacs 0:764779eedf2d 126 ********************************************************************************** */
andreikovacs 0:764779eedf2d 127 phyStatus_t MPM_SetPIB(phyPibId_t pibId, void* pValue, uint8_t panIdx)
andreikovacs 0:764779eedf2d 128 {
andreikovacs 0:764779eedf2d 129 switch(pibId)
andreikovacs 0:764779eedf2d 130 {
andreikovacs 0:764779eedf2d 131 #if gMpmUseDifferentTxPwrLevel_c
andreikovacs 0:764779eedf2d 132 case gPhyPibTransmitPower_c:
andreikovacs 0:764779eedf2d 133 if( (*(uint8_t*)pValue < 3) || (*(uint8_t*)pValue > 31) )
andreikovacs 0:764779eedf2d 134 {
andreikovacs 0:764779eedf2d 135 return gPhyInvalidParameter_c;
andreikovacs 0:764779eedf2d 136 }
andreikovacs 0:764779eedf2d 137 mPanInfo[panIdx].pwrLevel = *(uint8_t*)pValue;
andreikovacs 0:764779eedf2d 138 break;
andreikovacs 0:764779eedf2d 139 #endif
andreikovacs 0:764779eedf2d 140 #if (gMpmMaxPANs_c > gMpmPhyPanRegSets_c)
andreikovacs 0:764779eedf2d 141 case gPhyPibCurrentChannel_c:
andreikovacs 0:764779eedf2d 142 if( (*(uint8_t*)pValue < 11) || (*(uint8_t*)pValue > 26) )
andreikovacs 0:764779eedf2d 143 {
andreikovacs 0:764779eedf2d 144 return gPhyInvalidParameter_c;
andreikovacs 0:764779eedf2d 145 }
andreikovacs 0:764779eedf2d 146 mPanInfo[panIdx].channel = *(uint8_t*)pValue;
andreikovacs 0:764779eedf2d 147 break;
andreikovacs 0:764779eedf2d 148 case gPhyPibLongAddress_c:
andreikovacs 0:764779eedf2d 149 mPanInfo[panIdx].longAddr = *(uint64_t*)pValue;
andreikovacs 0:764779eedf2d 150 break;
andreikovacs 0:764779eedf2d 151 case gPhyPibShortAddress_c:
andreikovacs 0:764779eedf2d 152 mPanInfo[panIdx].shortAddr = *(uint16_t*)pValue;
andreikovacs 0:764779eedf2d 153 break;
andreikovacs 0:764779eedf2d 154 case gPhyPibPanId_c:
andreikovacs 0:764779eedf2d 155 mPanInfo[panIdx].panId = *(uint16_t*)pValue;
andreikovacs 0:764779eedf2d 156 break;
andreikovacs 0:764779eedf2d 157 case gPhyPibPanCoordinator_c:
andreikovacs 0:764779eedf2d 158 if( *(bool_t*)pValue )
andreikovacs 0:764779eedf2d 159 mPanInfo[panIdx].flags |= gMpmFlagPanCoord_c;
andreikovacs 0:764779eedf2d 160 else
andreikovacs 0:764779eedf2d 161 mPanInfo[panIdx].flags &= ~gMpmFlagPanCoord_c;
andreikovacs 0:764779eedf2d 162 break;
andreikovacs 0:764779eedf2d 163 #endif
andreikovacs 0:764779eedf2d 164 case gPhyPibRxOnWhenIdle:
andreikovacs 0:764779eedf2d 165 if( *(bool_t*)pValue )
andreikovacs 0:764779eedf2d 166 mPanInfo[panIdx].flags |= gMpmFlagRxOnWhenIdle_c;
andreikovacs 0:764779eedf2d 167 else
andreikovacs 0:764779eedf2d 168 mPanInfo[panIdx].flags &= ~gMpmFlagRxOnWhenIdle_c;
andreikovacs 0:764779eedf2d 169 break;
andreikovacs 0:764779eedf2d 170 case gPhyPibPromiscuousMode_c:
andreikovacs 0:764779eedf2d 171 if( *(bool_t*)pValue )
andreikovacs 0:764779eedf2d 172 mPanInfo[panIdx].flags |= gMpmFlagPromiscuous_c;
andreikovacs 0:764779eedf2d 173 else
andreikovacs 0:764779eedf2d 174 mPanInfo[panIdx].flags &= ~gMpmFlagPromiscuous_c;
andreikovacs 0:764779eedf2d 175 break;
andreikovacs 0:764779eedf2d 176 default:
andreikovacs 0:764779eedf2d 177 return gPhyUnsupportedAttribute_c;
andreikovacs 0:764779eedf2d 178 }
andreikovacs 0:764779eedf2d 179
andreikovacs 0:764779eedf2d 180 return gPhySuccess_c;
andreikovacs 0:764779eedf2d 181 }
andreikovacs 0:764779eedf2d 182
andreikovacs 0:764779eedf2d 183 phyStatus_t MPM_GetPIB(phyPibId_t pibId, void *pValue, uint8_t panIdx)
andreikovacs 0:764779eedf2d 184 {
andreikovacs 0:764779eedf2d 185 switch(pibId)
andreikovacs 0:764779eedf2d 186 {
andreikovacs 0:764779eedf2d 187 #if gMpmUseDifferentTxPwrLevel_c
andreikovacs 0:764779eedf2d 188 case gPhyPibTransmitPower_c:
andreikovacs 0:764779eedf2d 189 *(uint8_t*)pValue = mPanInfo[panIdx].pwrLevel;
andreikovacs 0:764779eedf2d 190 break;
andreikovacs 0:764779eedf2d 191 #endif
andreikovacs 0:764779eedf2d 192 #if (gMpmMaxPANs_c > gMpmPhyPanRegSets_c)
andreikovacs 0:764779eedf2d 193 case gPhyPibCurrentChannel_c:
andreikovacs 0:764779eedf2d 194 *(uint8_t*)pValue = mPanInfo[panIdx].channel;
andreikovacs 0:764779eedf2d 195 break;
andreikovacs 0:764779eedf2d 196 case gPhyPibLongAddress_c:
andreikovacs 0:764779eedf2d 197 *(uint64_t*)pValue = mPanInfo[panIdx].longAddr;
andreikovacs 0:764779eedf2d 198 break;
andreikovacs 0:764779eedf2d 199 case gPhyPibShortAddress_c:
andreikovacs 0:764779eedf2d 200 *(uint16_t*)pValue = mPanInfo[panIdx].shortAddr;
andreikovacs 0:764779eedf2d 201 break;
andreikovacs 0:764779eedf2d 202 case gPhyPibPanId_c:
andreikovacs 0:764779eedf2d 203 *(uint16_t*)pValue = mPanInfo[panIdx].panId;
andreikovacs 0:764779eedf2d 204 break;
andreikovacs 0:764779eedf2d 205 case gPhyPibPanCoordinator_c:
andreikovacs 0:764779eedf2d 206 *(uint8_t*)pValue = !!(mPanInfo[panIdx].flags & gMpmFlagPanCoord_c);
andreikovacs 0:764779eedf2d 207 break;
andreikovacs 0:764779eedf2d 208 #endif
andreikovacs 0:764779eedf2d 209 case gPhyPibRxOnWhenIdle:
andreikovacs 0:764779eedf2d 210 *(uint8_t*)pValue = !!(mPanInfo[panIdx].flags & gMpmFlagRxOnWhenIdle_c);
andreikovacs 0:764779eedf2d 211 break;
andreikovacs 0:764779eedf2d 212 case gPhyPibPromiscuousMode_c:
andreikovacs 0:764779eedf2d 213 *(uint8_t*)pValue = !!(mPanInfo[panIdx].flags & gMpmFlagPromiscuous_c);
andreikovacs 0:764779eedf2d 214 break;
andreikovacs 0:764779eedf2d 215 default:
andreikovacs 0:764779eedf2d 216 return gPhyUnsupportedAttribute_c;
andreikovacs 0:764779eedf2d 217 }
andreikovacs 0:764779eedf2d 218
andreikovacs 0:764779eedf2d 219 return gPhySuccess_c;
andreikovacs 0:764779eedf2d 220 }
andreikovacs 0:764779eedf2d 221
andreikovacs 0:764779eedf2d 222
andreikovacs 0:764779eedf2d 223 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 224 * \brief This function initializes the MPM module.
andreikovacs 0:764779eedf2d 225 *
andreikovacs 0:764779eedf2d 226 * \param[in] None.
andreikovacs 0:764779eedf2d 227 *
andreikovacs 0:764779eedf2d 228 * \return None
andreikovacs 0:764779eedf2d 229 *
andreikovacs 0:764779eedf2d 230 ********************************************************************************** */
andreikovacs 0:764779eedf2d 231 void MPM_Init( void )
andreikovacs 0:764779eedf2d 232 {
andreikovacs 0:764779eedf2d 233 uint32_t i;
andreikovacs 0:764779eedf2d 234
andreikovacs 0:764779eedf2d 235 mRegisteredPANs = 0;
andreikovacs 0:764779eedf2d 236 mMpmExclusiveAccess = FALSE;
andreikovacs 0:764779eedf2d 237 FLib_MemSet( mPanInfo, 0x00, sizeof(mPanInfo) );
andreikovacs 0:764779eedf2d 238 FLib_MemSet( pActivePANs, 0x00, sizeof(pActivePANs) );
andreikovacs 0:764779eedf2d 239
andreikovacs 0:764779eedf2d 240 for(i=0; i<gMpmMaxPANs_c; i++)
andreikovacs 0:764779eedf2d 241 mPanInfo[i].phyRegSet = gMpmInvalidRegSet_c;
andreikovacs 0:764779eedf2d 242
andreikovacs 0:764779eedf2d 243 PhyPpSetDualPanDwell( ((mDefaultDualPanDwellPrescaller_c << mDualPanDwellPrescallerShift_c) & mDualPanDwellPrescallerMask_c) |
andreikovacs 0:764779eedf2d 244 ((mDefaultDualPanDwellTime_c << mDualPanDwellTimeShift_c ) & mDualPanDwellTimeMask_c) );
andreikovacs 0:764779eedf2d 245 }
andreikovacs 0:764779eedf2d 246
andreikovacs 0:764779eedf2d 247 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 248 * \brief This function prepare the Radio for a TX/CCA/ED operation
andreikovacs 0:764779eedf2d 249 *
andreikovacs 0:764779eedf2d 250 * \param[in] macInstance The instance of the MAC
andreikovacs 0:764779eedf2d 251 *
andreikovacs 0:764779eedf2d 252 * \return The status of the Operation
andreikovacs 0:764779eedf2d 253 *
andreikovacs 0:764779eedf2d 254 ********************************************************************************** */
andreikovacs 0:764779eedf2d 255 phyStatus_t MPM_PrepareForTx( instanceId_t macInstance )
andreikovacs 0:764779eedf2d 256 {
andreikovacs 0:764779eedf2d 257 uint8_t panIdx = MPM_GetPanIndex(macInstance);
andreikovacs 0:764779eedf2d 258
andreikovacs 0:764779eedf2d 259 if( TRUE == mMpmExclusiveAccess && mPanInfo[panIdx].locked <= 0 )
andreikovacs 0:764779eedf2d 260 return gPhyChannelBusy_c;
andreikovacs 0:764779eedf2d 261
andreikovacs 0:764779eedf2d 262 /* Allocate HW Resources if necessary */
andreikovacs 0:764779eedf2d 263 if( mPanInfo[panIdx].phyRegSet == gMpmInvalidRegSet_c )
andreikovacs 0:764779eedf2d 264 {
andreikovacs 0:764779eedf2d 265 if( gMpmInvalidRegSet_c == MPM_AllocateResource( TRUE, panIdx ) )
andreikovacs 0:764779eedf2d 266 return gPhyChannelBusy_c;
andreikovacs 0:764779eedf2d 267
andreikovacs 0:764779eedf2d 268 MPM_SetPanSettingsInPhy( panIdx );
andreikovacs 0:764779eedf2d 269 }
andreikovacs 0:764779eedf2d 270
andreikovacs 0:764779eedf2d 271 /* Disable DualPan Auto Mode, and select the Active PAN */
andreikovacs 0:764779eedf2d 272 PhyPpSetDualPanAuto( FALSE );
andreikovacs 0:764779eedf2d 273 PhyPpSetDualPanActiveNwk( mPanInfo[panIdx].phyRegSet );
andreikovacs 0:764779eedf2d 274 return gPhySuccess_c;
andreikovacs 0:764779eedf2d 275 }
andreikovacs 0:764779eedf2d 276
andreikovacs 0:764779eedf2d 277 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 278 * \brief This function checks if a PAN has the RxOnWhenIdle PIB set.
andreikovacs 0:764779eedf2d 279 * If an Rx needs to be started, it makes the propper settings in PHY.
andreikovacs 0:764779eedf2d 280 *
andreikovacs 0:764779eedf2d 281 * \param[in] None.
andreikovacs 0:764779eedf2d 282 *
andreikovacs 0:764779eedf2d 283 * \return phyStatus
andreikovacs 0:764779eedf2d 284 *
andreikovacs 0:764779eedf2d 285 ********************************************************************************** */
andreikovacs 0:764779eedf2d 286 phyStatus_t MPM_PrepareForRx( instanceId_t macInstance )
andreikovacs 0:764779eedf2d 287 {
andreikovacs 0:764779eedf2d 288 uint32_t i, count = 0;
andreikovacs 0:764779eedf2d 289 uint32_t activePan;
andreikovacs 0:764779eedf2d 290
andreikovacs 0:764779eedf2d 291 if( gInvalidInstanceId_c != macInstance ) //Rx
andreikovacs 0:764779eedf2d 292 {
andreikovacs 0:764779eedf2d 293 i = MPM_GetPanIndex(macInstance);
andreikovacs 0:764779eedf2d 294
andreikovacs 0:764779eedf2d 295 if( !mMpmExclusiveAccess || mPanInfo[i].locked )
andreikovacs 0:764779eedf2d 296 {
andreikovacs 0:764779eedf2d 297 /* Allocate HW Resources if necessary */
andreikovacs 0:764779eedf2d 298 if( mPanInfo[i].phyRegSet == gMpmInvalidRegSet_c )
andreikovacs 0:764779eedf2d 299 {
andreikovacs 0:764779eedf2d 300 if( gMpmInvalidRegSet_c == MPM_AllocateResource( TRUE, i ) )
andreikovacs 0:764779eedf2d 301 return gPhyChannelBusy_c;
andreikovacs 0:764779eedf2d 302
andreikovacs 0:764779eedf2d 303 MPM_SetPanSettingsInPhy( i );
andreikovacs 0:764779eedf2d 304 }
andreikovacs 0:764779eedf2d 305
andreikovacs 0:764779eedf2d 306 count++;
andreikovacs 0:764779eedf2d 307 activePan = mPanInfo[i].phyRegSet;
andreikovacs 0:764779eedf2d 308 }
andreikovacs 0:764779eedf2d 309 }
andreikovacs 0:764779eedf2d 310 else //RxOnWhenIdle
andreikovacs 0:764779eedf2d 311 {
andreikovacs 0:764779eedf2d 312 for( i=0; i<gMpmPhyPanRegSets_c; i++)
andreikovacs 0:764779eedf2d 313 {
andreikovacs 0:764779eedf2d 314 if( (NULL != pActivePANs[i]) &&
andreikovacs 0:764779eedf2d 315 (pActivePANs[i]->flags & gMpmFlagRxOnWhenIdle_c) &&
andreikovacs 0:764779eedf2d 316 ( !mMpmExclusiveAccess || pActivePANs[i]->locked ) )
andreikovacs 0:764779eedf2d 317 {
andreikovacs 0:764779eedf2d 318 activePan = i;
andreikovacs 0:764779eedf2d 319 count++;
andreikovacs 0:764779eedf2d 320 }
andreikovacs 0:764779eedf2d 321 }
andreikovacs 0:764779eedf2d 322 }
andreikovacs 0:764779eedf2d 323
andreikovacs 0:764779eedf2d 324 if( !count )
andreikovacs 0:764779eedf2d 325 return gPhyChannelBusy_c;
andreikovacs 0:764779eedf2d 326
andreikovacs 0:764779eedf2d 327 /* Set the Active PAN and DualPan Auto mode if needed*/
andreikovacs 0:764779eedf2d 328 PhyPpSetDualPanActiveNwk( activePan );
andreikovacs 0:764779eedf2d 329 PhyPpSetDualPanAuto( count > 1 );
andreikovacs 0:764779eedf2d 330 return gPhySuccess_c;
andreikovacs 0:764779eedf2d 331 }
andreikovacs 0:764779eedf2d 332
andreikovacs 0:764779eedf2d 333 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 334 * \brief This function returns the PAN index for a MAC instance
andreikovacs 0:764779eedf2d 335 *
andreikovacs 0:764779eedf2d 336 * \param[in] macInstance The instance of the MAC
andreikovacs 0:764779eedf2d 337 *
andreikovacs 0:764779eedf2d 338 * \return The PAN index or -1 if it was not found
andreikovacs 0:764779eedf2d 339 *
andreikovacs 0:764779eedf2d 340 ********************************************************************************** */
andreikovacs 0:764779eedf2d 341 int32_t MPM_GetPanIndex( instanceId_t macInstance )
andreikovacs 0:764779eedf2d 342 {
andreikovacs 0:764779eedf2d 343 uint32_t i;
andreikovacs 0:764779eedf2d 344
andreikovacs 0:764779eedf2d 345 /* Get PAN Index for the macInstance */
andreikovacs 0:764779eedf2d 346 for( i=0; i<mRegisteredPANs; i++ )
andreikovacs 0:764779eedf2d 347 {
andreikovacs 0:764779eedf2d 348 if( mPanInfo[i].macInstance == macInstance )
andreikovacs 0:764779eedf2d 349 return i;
andreikovacs 0:764779eedf2d 350 }
andreikovacs 0:764779eedf2d 351
andreikovacs 0:764779eedf2d 352 /* The instance of the MAC is not registered!
andreikovacs 0:764779eedf2d 353 * Register the current MAC instance if there is enough space.
andreikovacs 0:764779eedf2d 354 */
andreikovacs 0:764779eedf2d 355 if( mRegisteredPANs < gMpmMaxPANs_c )
andreikovacs 0:764779eedf2d 356 {
andreikovacs 0:764779eedf2d 357 mPanInfo[mRegisteredPANs].macInstance = macInstance;
andreikovacs 0:764779eedf2d 358
andreikovacs 0:764779eedf2d 359 /* Try to allocate HW resource */
andreikovacs 0:764779eedf2d 360 mPanInfo[mRegisteredPANs].phyRegSet = MPM_AllocateResource( FALSE, i );
andreikovacs 0:764779eedf2d 361 mRegisteredPANs++;
andreikovacs 0:764779eedf2d 362 }
andreikovacs 0:764779eedf2d 363 else
andreikovacs 0:764779eedf2d 364 {
andreikovacs 0:764779eedf2d 365 i = -1;
andreikovacs 0:764779eedf2d 366 }
andreikovacs 0:764779eedf2d 367
andreikovacs 0:764779eedf2d 368 return i;
andreikovacs 0:764779eedf2d 369 }
andreikovacs 0:764779eedf2d 370
andreikovacs 0:764779eedf2d 371
andreikovacs 0:764779eedf2d 372 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 373 * \brief This function configures the MPM module
andreikovacs 0:764779eedf2d 374 *
andreikovacs 0:764779eedf2d 375 * \param[in] pCfg pointer to a configuration structure
andreikovacs 0:764779eedf2d 376 *
andreikovacs 0:764779eedf2d 377 * \remarks
andreikovacs 0:764779eedf2d 378 * The Dual PAN dwell time prescaller values: 0-3
andreikovacs 0:764779eedf2d 379 * The Dual PAN dwell time values 0-63.
andreikovacs 0:764779eedf2d 380 * The (dwellTime+1) represents multiples of the prescaller time base.
andreikovacs 0:764779eedf2d 381 *
andreikovacs 0:764779eedf2d 382 ********************************************************************************** */
andreikovacs 0:764779eedf2d 383 void MPM_SetConfig( mpmConfig_t *pCfg )
andreikovacs 0:764779eedf2d 384 {
andreikovacs 0:764779eedf2d 385 PhyPpSetDualPanAuto ( FALSE );
andreikovacs 0:764779eedf2d 386 PhyPpSetDualPanDwell( pCfg->dwellTime );
andreikovacs 0:764779eedf2d 387 MPM_AllocateResource( TRUE, MPM_GetPanIndex(pCfg->activeMAC) );
andreikovacs 0:764779eedf2d 388 PhyPpSetDualPanAuto ( pCfg->autoMode );
andreikovacs 0:764779eedf2d 389 if( PhyIsIdleRx(0) )
andreikovacs 0:764779eedf2d 390 {
andreikovacs 0:764779eedf2d 391 PhyPlmeForceTrxOffRequest();
andreikovacs 0:764779eedf2d 392 Radio_Phy_TimeRxTimeoutIndication(0);
andreikovacs 0:764779eedf2d 393 }
andreikovacs 0:764779eedf2d 394 }
andreikovacs 0:764779eedf2d 395
andreikovacs 0:764779eedf2d 396 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 397 * \brief This function returns the MPM configuration
andreikovacs 0:764779eedf2d 398 *
andreikovacs 0:764779eedf2d 399 * \param[in] pCfg pointer to a configuration structure
andreikovacs 0:764779eedf2d 400 *
andreikovacs 0:764779eedf2d 401 * \return None.
andreikovacs 0:764779eedf2d 402 *
andreikovacs 0:764779eedf2d 403 ********************************************************************************** */
andreikovacs 0:764779eedf2d 404 void MPM_GetConfig( mpmConfig_t *pCfg )
andreikovacs 0:764779eedf2d 405 {
andreikovacs 0:764779eedf2d 406 pCfg->dwellTime = PhyPpGetDualPanDwell();
andreikovacs 0:764779eedf2d 407 pCfg->activeMAC = MPM_GetMacInstanceFromRegSet( PhyPpGetDualPanActiveNwk() );
andreikovacs 0:764779eedf2d 408 pCfg->autoMode = PhyPpGetDualPanAuto();
andreikovacs 0:764779eedf2d 409 }
andreikovacs 0:764779eedf2d 410 #endif /* #if gMpmIncluded_d */
andreikovacs 0:764779eedf2d 411
andreikovacs 0:764779eedf2d 412 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 413 * \brief This function Acquires a PAN for exclusive access.
andreikovacs 0:764779eedf2d 414 *
andreikovacs 0:764779eedf2d 415 * \param[in] macInstance The instance of the MAC
andreikovacs 0:764779eedf2d 416 *
andreikovacs 0:764779eedf2d 417 * \return The status of the operation
andreikovacs 0:764779eedf2d 418 *
andreikovacs 0:764779eedf2d 419 ********************************************************************************** */
andreikovacs 0:764779eedf2d 420 phyStatus_t MPM_AcquirePAN( instanceId_t macInstance )
andreikovacs 0:764779eedf2d 421 {
andreikovacs 0:764779eedf2d 422 #if gMpmIncluded_d
andreikovacs 0:764779eedf2d 423 int32_t panIndex = MPM_GetPanIndex(macInstance);
andreikovacs 0:764779eedf2d 424
andreikovacs 0:764779eedf2d 425 /* Check if another PAN is acquired */
andreikovacs 0:764779eedf2d 426 if( TRUE == mMpmExclusiveAccess &&
andreikovacs 0:764779eedf2d 427 mPanInfo[panIndex].locked <= 0 )
andreikovacs 0:764779eedf2d 428 {
andreikovacs 0:764779eedf2d 429 return gPhyBusy_c;
andreikovacs 0:764779eedf2d 430 }
andreikovacs 0:764779eedf2d 431
andreikovacs 0:764779eedf2d 432 if( mPanInfo[panIndex].locked == 0 )
andreikovacs 0:764779eedf2d 433 {
andreikovacs 0:764779eedf2d 434 mMpmExclusiveAccess = TRUE;
andreikovacs 0:764779eedf2d 435 if( PhyIsIdleRx(0) )
andreikovacs 0:764779eedf2d 436 {
andreikovacs 0:764779eedf2d 437 PhyPlmeForceTrxOffRequest();
andreikovacs 0:764779eedf2d 438 Radio_Phy_TimeRxTimeoutIndication(0);
andreikovacs 0:764779eedf2d 439 }
andreikovacs 0:764779eedf2d 440 }
andreikovacs 0:764779eedf2d 441
andreikovacs 0:764779eedf2d 442 mPanInfo[panIndex].locked++;
andreikovacs 0:764779eedf2d 443 #endif
andreikovacs 0:764779eedf2d 444 return gPhySuccess_c;
andreikovacs 0:764779eedf2d 445 }
andreikovacs 0:764779eedf2d 446
andreikovacs 0:764779eedf2d 447 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 448 * \brief This function Releases a PAN that was Acquired
andreikovacs 0:764779eedf2d 449 *
andreikovacs 0:764779eedf2d 450 * \param[in] macInstance The instance of the MAC
andreikovacs 0:764779eedf2d 451 *
andreikovacs 0:764779eedf2d 452 * \return The status of the operation
andreikovacs 0:764779eedf2d 453 *
andreikovacs 0:764779eedf2d 454 ********************************************************************************** */
andreikovacs 0:764779eedf2d 455 phyStatus_t MPM_ReleasePAN( instanceId_t macInstance )
andreikovacs 0:764779eedf2d 456 {
andreikovacs 0:764779eedf2d 457 #if gMpmIncluded_d
andreikovacs 0:764779eedf2d 458 uint8_t panIndex = MPM_GetPanIndex(macInstance);
andreikovacs 0:764779eedf2d 459
andreikovacs 0:764779eedf2d 460 mPanInfo[panIndex].locked--;
andreikovacs 0:764779eedf2d 461 if( mPanInfo[panIndex].locked == 0 )
andreikovacs 0:764779eedf2d 462 {
andreikovacs 0:764779eedf2d 463 mMpmExclusiveAccess = FALSE;
andreikovacs 0:764779eedf2d 464 if( PhyIsIdleRx(0) )
andreikovacs 0:764779eedf2d 465 {
andreikovacs 0:764779eedf2d 466 PhyPlmeForceTrxOffRequest();
andreikovacs 0:764779eedf2d 467 Radio_Phy_TimeRxTimeoutIndication(0);
andreikovacs 0:764779eedf2d 468 }
andreikovacs 0:764779eedf2d 469 }
andreikovacs 0:764779eedf2d 470 #endif
andreikovacs 0:764779eedf2d 471 return gPhySuccess_c;
andreikovacs 0:764779eedf2d 472 }
andreikovacs 0:764779eedf2d 473
andreikovacs 0:764779eedf2d 474 /************************************************************************************
andreikovacs 0:764779eedf2d 475 *************************************************************************************
andreikovacs 0:764779eedf2d 476 * Private functions
andreikovacs 0:764779eedf2d 477 *************************************************************************************
andreikovacs 0:764779eedf2d 478 ************************************************************************************/
andreikovacs 0:764779eedf2d 479 #if gMpmIncluded_d
andreikovacs 0:764779eedf2d 480 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 481 * \brief This function alocates a registry set to a PAN.
andreikovacs 0:764779eedf2d 482 *
andreikovacs 0:764779eedf2d 483 * \param[in] force If this parameter is TRUE, then another PAN can be preempted.
andreikovacs 0:764779eedf2d 484 * \param[in] panIdx The index into the MPM database
andreikovacs 0:764779eedf2d 485 *
andreikovacs 0:764779eedf2d 486 * \return The register set allocated for the specified PAN.
andreikovacs 0:764779eedf2d 487 *
andreikovacs 0:764779eedf2d 488 ********************************************************************************** */
andreikovacs 0:764779eedf2d 489 static uint8_t MPM_AllocateResource( bool_t force, uint8_t panIdx )
andreikovacs 0:764779eedf2d 490 {
andreikovacs 0:764779eedf2d 491 uint32_t i, regSet = gMpmInvalidRegSet_c;
andreikovacs 0:764779eedf2d 492
andreikovacs 0:764779eedf2d 493 if( mPanInfo[panIdx].phyRegSet != gMpmInvalidRegSet_c )
andreikovacs 0:764779eedf2d 494 return mPanInfo[panIdx].phyRegSet;
andreikovacs 0:764779eedf2d 495
andreikovacs 0:764779eedf2d 496 for( i=0; i<gMpmPhyPanRegSets_c; i++ )
andreikovacs 0:764779eedf2d 497 {
andreikovacs 0:764779eedf2d 498 if( NULL == pActivePANs[i] )
andreikovacs 0:764779eedf2d 499 {
andreikovacs 0:764779eedf2d 500 regSet = i;
andreikovacs 0:764779eedf2d 501 break;
andreikovacs 0:764779eedf2d 502 }
andreikovacs 0:764779eedf2d 503 else if( (force) &&
andreikovacs 0:764779eedf2d 504 (pActivePANs[i]->flags == 0) &&
andreikovacs 0:764779eedf2d 505 (pActivePANs[i]->locked <= 0) )
andreikovacs 0:764779eedf2d 506 {
andreikovacs 0:764779eedf2d 507 regSet = i;
andreikovacs 0:764779eedf2d 508 }
andreikovacs 0:764779eedf2d 509 }
andreikovacs 0:764779eedf2d 510
andreikovacs 0:764779eedf2d 511 if( regSet != gMpmInvalidRegSet_c )
andreikovacs 0:764779eedf2d 512 {
andreikovacs 0:764779eedf2d 513 if( NULL != pActivePANs[regSet] )
andreikovacs 0:764779eedf2d 514 {
andreikovacs 0:764779eedf2d 515 pActivePANs[regSet]->phyRegSet = gMpmInvalidRegSet_c;
andreikovacs 0:764779eedf2d 516 }
andreikovacs 0:764779eedf2d 517
andreikovacs 0:764779eedf2d 518 pActivePANs[regSet] = &mPanInfo[panIdx];
andreikovacs 0:764779eedf2d 519 pActivePANs[regSet]->phyRegSet = regSet;
andreikovacs 0:764779eedf2d 520 }
andreikovacs 0:764779eedf2d 521
andreikovacs 0:764779eedf2d 522 return regSet;
andreikovacs 0:764779eedf2d 523 }
andreikovacs 0:764779eedf2d 524
andreikovacs 0:764779eedf2d 525 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 526 * \brief This function will store PAN settings in PHY.
andreikovacs 0:764779eedf2d 527 *
andreikovacs 0:764779eedf2d 528 * \param[in] panIdx The index into the MPM database
andreikovacs 0:764779eedf2d 529 *
andreikovacs 0:764779eedf2d 530 * \return None.
andreikovacs 0:764779eedf2d 531 *
andreikovacs 0:764779eedf2d 532 * \remarks Function assumes that the PAN is active!
andreikovacs 0:764779eedf2d 533 *
andreikovacs 0:764779eedf2d 534 ********************************************************************************** */
andreikovacs 0:764779eedf2d 535 static void MPM_SetPanSettingsInPhy( uint8_t panIndex )
andreikovacs 0:764779eedf2d 536 {
andreikovacs 0:764779eedf2d 537 panInfo_t *pPAN = &mPanInfo[panIndex];
andreikovacs 0:764779eedf2d 538
andreikovacs 0:764779eedf2d 539 #if gMpmUseDifferentTxPwrLevel_c
andreikovacs 0:764779eedf2d 540 PhyPlmeSetPIBRequest(gPhyPibTransmitPower_c, pPAN->pwrLevel, pPAN->phyRegSet, 0 );
andreikovacs 0:764779eedf2d 541 #endif
andreikovacs 0:764779eedf2d 542
andreikovacs 0:764779eedf2d 543 #if (gMpmMaxPANs_c > gMpmPhyPanRegSets_c)
andreikovacs 0:764779eedf2d 544 PhyPlmeSetPIBRequest(gPhyPibPromiscuousMode_c, !!(pPAN->flags & gMpmFlagPromiscuous_c), pPAN->phyRegSet, 0 );
andreikovacs 0:764779eedf2d 545 PhyPlmeSetPIBRequest(gPhyPibRxOnWhenIdle, !!(pPAN->flags & gMpmFlagRxOnWhenIdle_c), pPAN->phyRegSet, 0 );
andreikovacs 0:764779eedf2d 546 PhyPlmeSetPIBRequest(gPhyPibPanCoordinator_c, !!(pPAN->flags & gMpmFlagPanCoord_c), pPAN->phyRegSet, 0 );
andreikovacs 0:764779eedf2d 547 PhyPlmeSetPIBRequest(gPhyPibPanId_c, pPAN->panId, pPAN->phyRegSet, 0 );
andreikovacs 0:764779eedf2d 548 PhyPlmeSetPIBRequest(gPhyPibShortAddress_c, pPAN->shortAddr, pPAN->phyRegSet, 0 );
andreikovacs 0:764779eedf2d 549 PhyPlmeSetPIBRequest(gPhyPibLongAddress_c, pPAN->longAddr, pPAN->phyRegSet, 0 );
andreikovacs 0:764779eedf2d 550 PhyPlmeSetPIBRequest(gPhyPibCurrentChannel_c, pPAN->channel, pPAN->phyRegSet, 0 );
andreikovacs 0:764779eedf2d 551 #else
andreikovacs 0:764779eedf2d 552 (void)pPAN;
andreikovacs 0:764779eedf2d 553 #endif
andreikovacs 0:764779eedf2d 554 }
andreikovacs 0:764779eedf2d 555 #endif /* gMpmIncluded_d */