NXP / fsl_phy_mcr20a

Fork of fsl_phy_mcr20a by Freescale

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ASP.c Source File

ASP.c

Go to the documentation of this file.
00001 /*!
00002 * Copyright (c) 2015, Freescale Semiconductor, Inc.
00003 * All rights reserved.
00004 *
00005 * \file ASP.c
00006 * This is the source file for the ASP module.
00007 *
00008 * Redistribution and use in source and binary forms, with or without modification,
00009 * are permitted provided that the following conditions are met:
00010 *
00011 * o Redistributions of source code must retain the above copyright notice, this list
00012 *   of conditions and the following disclaimer.
00013 *
00014 * o Redistributions in binary form must reproduce the above copyright notice, this
00015 *   list of conditions and the following disclaimer in the documentation and/or
00016 *   other materials provided with the distribution.
00017 *
00018 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
00019 *   contributors may be used to endorse or promote products derived from this
00020 *   software without specific prior written permission.
00021 *
00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00024 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00026 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00027 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00029 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00030 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00031 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032 */
00033 
00034 /************************************************************************************
00035 *************************************************************************************
00036 * Include
00037 *************************************************************************************
00038 ************************************************************************************/
00039 
00040 #include "EmbeddedTypes.h "
00041 //#include "fsl_os_abstraction.h"
00042 
00043 #include "Phy.h "
00044 #include "PhyInterface.h "
00045 #include "MpmInterface.h "
00046 #include "AspInterface.h"
00047 
00048 #if 0
00049 #include "MemManager.h "
00050 #include "FunctionLib.h "
00051 #include "Panic.h"
00052 #endif 
00053 
00054 #include "MCR20Drv.h "
00055 #include "MCR20Reg.h"
00056 
00057 #if gFsciIncluded_c
00058 #include "FsciInterface.h"
00059 #include "FsciCommands.h"
00060 #include "FsciCommunication.h"
00061 #endif
00062 
00063 #define gSmacSupported (1)
00064 
00065 #ifdef gSmacSupported
00066 #include "SMAC_Interface.h"
00067 #endif
00068 #if gAspCapability_d
00069 
00070 /************************************************************************************
00071 *************************************************************************************
00072 * Public macros
00073 *************************************************************************************
00074 ************************************************************************************/
00075 #define mFAD_THR_ResetValue         0x82
00076 #define mANT_AGC_CTRL_ResetValue    0x40
00077 
00078 /************************************************************************************
00079 *************************************************************************************
00080 * Public type definitions
00081 *************************************************************************************
00082 ************************************************************************************/
00083 //MCR20 DTS modes
00084 enum {
00085   gDtsNormal_c,
00086   gDtsTxOne_c,
00087   gDtsTxZero_c,
00088   gDtsTx2Mhz_c,
00089   gDtsTx200Khz_c,
00090   gDtsTx1MbpsPRBS9_c,
00091   gDtsTxExternalSrc_c,
00092   gDtsTxRandomSeq_c
00093 };
00094 
00095 /************************************************************************************
00096 *************************************************************************************
00097 * Private functions prototype
00098 *************************************************************************************
00099 ************************************************************************************/
00100 phyStatus_t AspSetDtsMode( uint8_t mode );
00101 phyStatus_t AspEnableBER( void );
00102 void AspDisableBER( void );
00103 
00104 #if gFsciIncluded_c
00105 static void fsciAspReqHandler(void *pData, void* param, uint32_t interfaceId);
00106 static void AspSapMonitor(void *pData, void* param, uint32_t interfaceId);
00107 #endif
00108 
00109 /************************************************************************************
00110 *************************************************************************************
00111 * Private memory declarations
00112 *************************************************************************************
00113 ************************************************************************************/
00114 //2405   2410    2415    2420    2425    2430    2435    2440    2445    2450    2455    2460    2465    2470    2475    2480
00115 static const uint16_t asp_pll_frac[16] = {0x2400, 0x4C00, 0x7400, 0x9C00, 0xC400, 0xEC00, 0x1400, 0x3C00, 0x6400, 0x8C00, 0xB400, 0xDC00, 0x0400, 0x2C00, 0x5400, 0x7C00};
00116 
00117 #if gFsciIncluded_c
00118 static uint8_t mAspFsciBinding[gPhyInstancesCnt_c];
00119 #endif
00120 
00121 /************************************************************************************
00122 *************************************************************************************
00123 * Public functions
00124 *************************************************************************************
00125 ************************************************************************************/
00126 
00127 /*! *********************************************************************************
00128 * \brief  Initialize the ASP module
00129 *
00130 * \param[in]  phyInstance The instance of the PHY
00131 * \param[in]  interfaceId The Serial Manager interface used
00132 *
00133 ********************************************************************************** */
00134 #undef mFuncId_c
00135 #define mFuncId_c 0
00136 void ASP_Init( instanceId_t phyInstance, uint8_t interfaceId )
00137 {
00138 #if gFsciIncluded_c
00139     if( phyInstance < gPhyInstancesCnt_c )
00140     {
00141         mAspFsciBinding[phyInstance] = interfaceId;
00142         FSCI_RegisterOpGroup( gFSCI_AppAspOpcodeGroup_c, gFsciMonitorMode_c, fsciAspReqHandler, NULL, gAspInterfaceId);
00143         FSCI_RegisterOpGroup( gFSCI_AspSapId_c,          gFsciMonitorMode_c, AspSapMonitor,     NULL, gAspInterfaceId);
00144     }
00145 #endif
00146 }
00147 
00148 /*! *********************************************************************************
00149 * \brief  ASP SAP handler.
00150 *
00151 * \param[in]  pMsg        Pointer to the request message
00152 * \param[in]  instanceId  The instance of the PHY
00153 *
00154 * \return  AspStatus_t
00155 *
00156 ********************************************************************************** */
00157 #undef mFuncId_c
00158 #define mFuncId_c 1
00159 AspStatus_t APP_ASP_SapHandler(AppToAspMessage_t *pMsg, instanceId_t instanceId)
00160 {
00161     AspStatus_t status = gAspSuccess_c;
00162 #if gFsciIncluded_c
00163     FSCI_Monitor( gFSCI_AspSapId_c,
00164                   pMsg,
00165                   NULL,
00166                   gAspInterfaceId );
00167 #endif
00168     switch( pMsg->msgType )
00169     {
00170     case aspMsgTypeGetTimeReq_c:
00171         Asp_GetTimeReq((uint32_t*)&pMsg->msgData.aspGetTimeReq.time);
00172         break;
00173     case aspMsgTypeXcvrWriteReq_c:
00174         status = Asp_XcvrWriteReq( pMsg->msgData.aspXcvrData.mode,
00175                                    pMsg->msgData.aspXcvrData.addr,
00176                                    pMsg->msgData.aspXcvrData.len,
00177                                    pMsg->msgData.aspXcvrData.data);
00178         break;
00179     case aspMsgTypeXcvrReadReq_c:
00180         status = Asp_XcvrReadReq( pMsg->msgData.aspXcvrData.mode,
00181                                   pMsg->msgData.aspXcvrData.addr,
00182                                   pMsg->msgData.aspXcvrData.len,
00183                                   pMsg->msgData.aspXcvrData.data);
00184         break;
00185     case aspMsgTypeSetFADState_c:
00186         status = Asp_SetFADState(pMsg->msgData.aspFADState);
00187         break;
00188     case aspMsgTypeSetFADThreshold_c:
00189         status = Asp_SetFADThreshold(pMsg->msgData.aspFADThreshold);
00190         break;
00191     case aspMsgTypeSetANTXState_c:
00192         status = Asp_SetANTXState(pMsg->msgData.aspANTXState);
00193         break;
00194     case aspMsgTypeGetANTXState_c:
00195         *((uint8_t*)&status) = Asp_GetANTXState();
00196         break;
00197     case aspMsgTypeSetPowerLevel_c:
00198         status = Asp_SetPowerLevel(pMsg->msgData.aspSetPowerLevelReq.powerLevel);
00199         break;
00200     case aspMsgTypeGetPowerLevel_c:
00201         *((uint8_t*)&status) = Asp_GetPowerLevel(); //remove compiler warning
00202         break;
00203     case aspMsgTypeTelecSetFreq_c:
00204         status = ASP_TelecSetFreq(pMsg->msgData.aspTelecsetFreq.channel);
00205         break;
00206     case aspMsgTypeTelecSendRawData_c:
00207         status = ASP_TelecSendRawData((uint8_t*)&pMsg->msgData.aspTelecSendRawData);
00208         break;
00209     case aspMsgTypeTelecTest_c:
00210         status = ASP_TelecTest(pMsg->msgData.aspTelecTest.mode);
00211         break;
00212     case aspMsgTypeSetLQIMode_c:
00213         status = Asp_SetLQIMode(pMsg->msgData.aspLQIMode);
00214         break;
00215     case aspMsgTypeGetRSSILevel_c:
00216         *((uint8_t*)&status) = Asp_GetRSSILevel(); //remove compiler warning
00217         break;
00218 #if gMpmIncluded_d
00219     case aspMsgTypeSetMpmConfig_c:
00220         MPM_SetConfig(&pMsg->msgData.MpmConfig);
00221         break;
00222     case aspMsgTypeGetMpmConfig_c:
00223         MPM_GetConfig(&pMsg->msgData.MpmConfig);
00224         break;
00225 #endif
00226     default:
00227         status = gAspInvalidRequest_c;// OR gAspInvalidParameter_c
00228         break;
00229     }
00230 #if gFsciIncluded_c
00231     FSCI_Monitor( gFSCI_AspSapId_c,
00232                   pMsg,
00233                   (void*)&status,
00234                   gAspInterfaceId );
00235 #endif
00236     return status;
00237 }
00238 
00239 /*! *********************************************************************************
00240 * \brief  Returns the current PHY time
00241 *
00242 * \param[in]  time  location where the PHY time will be stored
00243 *
00244 ********************************************************************************** */
00245 #undef mFuncId_c
00246 #define mFuncId_c 2
00247 void Asp_GetTimeReq(uint32_t *time)
00248 {
00249     PhyTimeReadClock( time );
00250 }
00251 
00252 /*! *********************************************************************************
00253 * \brief  Write XCVR registers
00254 *
00255 * \param[in]  mode   Direct/Indirect access
00256 * \param[in]  addr   XCVR address
00257 * \param[in]  len    number of bytes to write
00258 * \param[in]  pData  data o be written
00259 *
00260 * \return  AspStatus_t
00261 *
00262 ********************************************************************************** */
00263 #undef mFuncId_c
00264 #define mFuncId_c 3
00265 AspStatus_t Asp_XcvrWriteReq (uint8_t mode, uint16_t addr, uint8_t len, uint8_t* pData)
00266 {
00267     if (mode)
00268         MCR20Drv_IndirectAccessSPIMultiByteWrite((uint8_t)addr, pData, len);
00269     else
00270         MCR20Drv_DirectAccessSPIMultiByteWrite((uint8_t)addr, pData, len);
00271 
00272     return gAspSuccess_c;
00273 }
00274 
00275 /*! *********************************************************************************
00276 * \brief  Read XCVR registers
00277 *
00278 * \param[in]  mode   Direct/Indirect access
00279 * \param[in]  addr   XCVR address
00280 * \param[in]  len    number of bytes to read
00281 * \param[in]  pData  location where data will be stored
00282 *
00283 * \return  AspStatus_t
00284 *
00285 ********************************************************************************** */
00286 #undef mFuncId_c
00287 #define mFuncId_c 4
00288 AspStatus_t Asp_XcvrReadReq  (uint8_t mode, uint16_t addr, uint8_t len, uint8_t* pData)
00289 {
00290     if (mode)
00291         MCR20Drv_IndirectAccessSPIMultiByteRead((uint8_t)addr, pData, len);
00292     else
00293         MCR20Drv_DirectAccessSPIMultiByteRead((uint8_t)addr, pData, len);
00294 
00295     return gAspSuccess_c;
00296 }
00297 
00298 /*! *********************************************************************************
00299 * \brief  Set Tx output power level
00300 *
00301 * \param[in]  powerLevel   The new power level: 0x03-0x1F (see documentation for details)
00302 *
00303 * \return  AspStatus_t
00304 *
00305 ********************************************************************************** */
00306 #undef mFuncId_c
00307 #define mFuncId_c 5
00308 AspStatus_t Asp_SetPowerLevel( uint8_t powerLevel )
00309 {
00310     if(powerLevel > gAspPowerLevel_16dBm)
00311         return gAspInvalidParameter_c;
00312 
00313     {
00314         uint8_t res;
00315 
00316         res = PhyPlmeSetPwrLevelRequest(powerLevel);
00317 
00318         if( res == gPhySuccess_c )
00319         {
00320             return gAspSuccess_c;
00321         }
00322         else
00323         {
00324             return gAspDenied_c;
00325         }
00326     }
00327 }
00328 
00329 /*! *********************************************************************************
00330 * \brief  Read the current Tx power level
00331 *
00332 * \return  power level
00333 *
00334 ********************************************************************************** */
00335 #undef mFuncId_c
00336 #define mFuncId_c 6
00337 uint8_t Asp_GetPowerLevel()
00338 {
00339     return MCR20Drv_DirectAccessSPIRead(PA_PWR);
00340 }
00341 
00342 /*! *********************************************************************************
00343 * \brief  Set the state of Active Promiscuous functionality
00344 *
00345 * \param[in]  state  new state 
00346 *
00347 * \return  AspStatus_t
00348 *
00349 ********************************************************************************** */
00350 #undef mFuncId_c
00351 #define mFuncId_c 7
00352 AspStatus_t Asp_SetActivePromState(bool_t state)
00353 {
00354     PhySetActivePromiscuous(state);
00355     return gAspSuccess_c;
00356 }
00357 
00358 /*! *********************************************************************************
00359 * \brief  Set the state of Fast Antenna Diversity functionality
00360 *
00361 * \param[in]  state  new state 
00362 *
00363 * \return  AspStatus_t
00364 *
00365 ********************************************************************************** */
00366 #undef mFuncId_c
00367 #define mFuncId_c 8
00368 AspStatus_t Asp_SetFADState(bool_t state)
00369 {
00370     if( gPhySuccess_c != PhyPlmeSetFADStateRequest(state) )
00371     {
00372         return gAspDenied_c;
00373     }
00374     return gAspSuccess_c;
00375 }
00376 
00377 /*! *********************************************************************************
00378 * \brief  Set the Fast Antenna Diversity threshold
00379 *
00380 * \param[in]  threshold 
00381 *
00382 * \return  AspStatus_t
00383 *
00384 ********************************************************************************** */
00385 #undef mFuncId_c
00386 #define mFuncId_c 9
00387 AspStatus_t Asp_SetFADThreshold(uint8_t threshold)
00388 {
00389     if( gPhySuccess_c != PhyPlmeSetFADThresholdRequest(threshold) )
00390     {
00391         return gAspDenied_c;
00392     }
00393     return gAspSuccess_c;
00394 }
00395 
00396 /*! *********************************************************************************
00397 * \brief  Set the ANTX functionality
00398 *
00399 * \param[in]  state 
00400 *
00401 * \return  AspStatus_t
00402 *
00403 ********************************************************************************** */
00404 #undef mFuncId_c
00405 #define mFuncId_c 10
00406 AspStatus_t Asp_SetANTXState(bool_t state)
00407 {
00408     if( gPhySuccess_c != PhyPlmeSetANTXStateRequest(state) )
00409     {
00410         return gAspDenied_c;
00411     }
00412     return gAspSuccess_c;
00413 }
00414 
00415 /*! *********************************************************************************
00416 * \brief  Get the ANTX functionality
00417 *
00418 * \return  current state
00419 *
00420 ********************************************************************************** */
00421 #undef mFuncId_c
00422 #define mFuncId_c 11
00423 uint8_t Asp_GetANTXState(void)
00424 {
00425   return PhyPlmeGetANTXStateRequest();
00426 }
00427 
00428 /*! *********************************************************************************
00429 * \brief  Set the ANTX pad state
00430 *
00431 * \param[in]  antAB_on 
00432 * \param[in]  rxtxSwitch_on 
00433 *
00434 * \return  status
00435 *
00436 ********************************************************************************** */
00437 #undef mFuncId_c
00438 #define mFuncId_c 12
00439 uint8_t Asp_SetANTPadStateRequest(bool_t antAB_on, bool_t rxtxSwitch_on)
00440 {
00441     return PhyPlmeSetANTPadStateRequest(antAB_on, rxtxSwitch_on);
00442 }
00443 
00444 /*! *********************************************************************************
00445 * \brief  Set the ANTX pad strength
00446 *
00447 * \param[in]  hiStrength 
00448 *
00449 * \return  status
00450 *
00451 ********************************************************************************** */
00452 #undef mFuncId_c
00453 #define mFuncId_c 13
00454 uint8_t Asp_SetANTPadStrengthRequest(bool_t hiStrength)
00455 {
00456     return PhyPlmeSetANTPadStrengthRequest(hiStrength);
00457 }
00458 
00459 /*! *********************************************************************************
00460 * \brief  Set the ANTX inverted pads
00461 *
00462 * \param[in]  invAntA  invert Ant_A pad
00463 * \param[in]  invAntB  invert Ant_B pad
00464 * \param[in]  invTx    invert Tx pad
00465 * \param[in]  invRx    invert Rx pad
00466 *
00467 * \return  status
00468 *
00469 ********************************************************************************** */
00470 #undef mFuncId_c
00471 #define mFuncId_c 14
00472 uint8_t Asp_SetANTPadInvertedRequest(bool_t invAntA, bool_t invAntB, bool_t invTx, bool_t invRx)
00473 {
00474     return PhyPlmeSetANTPadInvertedRequest(invAntA, invAntB, invTx, invRx);
00475 }
00476 
00477 /*! *********************************************************************************
00478 * \brief  Set the LQI mode
00479 *
00480 * \param[in]  mode 
00481 *
00482 * \return  AspStatus_t
00483 *
00484 ********************************************************************************** */
00485 #undef mFuncId_c
00486 #define mFuncId_c 15
00487 AspStatus_t Asp_SetLQIMode(bool_t mode)
00488 {
00489     if( gPhySuccess_c != PhyPlmeSetLQIModeRequest(mode) )
00490     {
00491         return gAspDenied_c;
00492     }
00493     return gAspSuccess_c;
00494 }
00495 
00496 /*! *********************************************************************************
00497 * \brief  Get the last RSSI level
00498 *
00499 * \return  RSSI
00500 *
00501 ********************************************************************************** */
00502 #undef mFuncId_c
00503 #define mFuncId_c 16
00504 uint8_t Asp_GetRSSILevel(void)
00505 {
00506   return PhyPlmeGetRSSILevelRequest();
00507 }
00508 
00509 /*! *********************************************************************************
00510 * \brief  Set current channel
00511 *
00512 * \param[in]  channel  channel number (11-26)
00513 *
00514 * \return  AspStatus_t
00515 *
00516 ********************************************************************************** */
00517 #undef mFuncId_c
00518 #define mFuncId_c 17
00519 AspStatus_t ASP_TelecSetFreq(uint8_t channel)
00520 {
00521     PhyPlmeForceTrxOffRequest();
00522     if( gPhySuccess_c != PhyPlmeSetCurrentChannelRequest(channel,0) )
00523     {
00524         return gAspInvalidParameter_c;
00525     }
00526 
00527     return gAspSuccess_c;
00528 }
00529 
00530 /*! *********************************************************************************
00531 * \brief  Send a raw data frame OTA
00532 *
00533 * \param[in]  dataPtr  raw data
00534 *
00535 * \return  AspStatus_t
00536 *
00537 ********************************************************************************** */
00538 #undef mFuncId_c
00539 #define mFuncId_c 18
00540 AspStatus_t ASP_TelecSendRawData(uint8_t* dataPtr)
00541 {
00542     uint8_t phyReg;
00543 
00544     dataPtr[0] += 2; /* Add FCS length to PSDU Length*/
00545 
00546     // Validate the length
00547     if(dataPtr[0] > gMaxPHYPacketSize_c)
00548         return gAspTooLong_c;
00549 
00550     //Force Idle
00551     PhyPlmeForceTrxOffRequest();
00552     AspSetDtsMode(gDtsNormal_c);
00553     AspDisableBER();
00554     // Load the TX PB: load the PSDU Lenght byte but not the FCS bytes
00555     MCR20Drv_PB_SPIBurstWrite(dataPtr, dataPtr[0] + 1 - 2);
00556     // Program a Tx sequence
00557     phyReg = MCR20Drv_DirectAccessSPIRead(PHY_CTRL1);
00558     phyReg |=  gTX_c;
00559     MCR20Drv_DirectAccessSPIWrite( (uint8_t) PHY_CTRL1, phyReg);
00560     return gAspSuccess_c;
00561 }
00562 
00563 /*! *********************************************************************************
00564 * \brief  Set Telec test mode
00565 *
00566 * \param[in]  mode  Telec test mode
00567 *
00568 * \return  AspStatus_t
00569 *
00570 ********************************************************************************** */
00571 #undef mFuncId_c
00572 #define mFuncId_c 19
00573 AspStatus_t ASP_TelecTest(uint8_t mode)
00574 {
00575     uint8_t phyReg;
00576     static uint8_t aTxContModPattern[2];
00577     uint8_t channel;
00578     static bool_t fracSet = FALSE;
00579 
00580     // Get current channel number
00581     channel = PhyPlmeGetCurrentChannelRequest(0);
00582 
00583     if( fracSet )
00584     {
00585         ASP_TelecSetFreq(channel);
00586         fracSet = FALSE;
00587     }
00588 
00589     switch( mode )
00590     {
00591     case gTestForceIdle_c:  //ForceIdle();
00592 #ifdef gSmacSupported
00593         MLMEPhySoftReset();
00594 #else
00595         PhyPlmeForceTrxOffRequest();
00596 #endif
00597         AspSetDtsMode(gDtsNormal_c);
00598         AspDisableBER();
00599         break;
00600 
00601     case gTestPulseTxPrbs9_c:   // Continuously transmit a PRBS9 pattern.
00602         // PLME_PRBS9_Load (); // Load the TX RAM
00603         AspSetDtsMode(gDtsTxRandomSeq_c);
00604         //Enable continuous TX mode
00605         AspEnableBER();
00606         // Start Tx packet mode with no interrupt on end
00607         phyReg = MCR20Drv_DirectAccessSPIRead(PHY_CTRL1);
00608         phyReg |=  gTX_c;
00609         MCR20Drv_DirectAccessSPIWrite( (uint8_t) PHY_CTRL1, phyReg);
00610         break;
00611 
00612     case gTestContinuousRx_c: // Sets the device into continuous RX mode
00613         AspSetDtsMode(gDtsNormal_c);
00614         //Enable continuous RX mode
00615         AspEnableBER();
00616         // Set length of data in DUAL_PAN_DWELL register
00617         MCR20Drv_IndirectAccessSPIWrite(DUAL_PAN_DWELL, 127);
00618         // Start Rx packet mode with no interrupt on end
00619         phyReg = MCR20Drv_DirectAccessSPIRead(PHY_CTRL1);
00620         phyReg |=  gRX_c;
00621         MCR20Drv_DirectAccessSPIWrite( (uint8_t) PHY_CTRL1, phyReg);
00622         break;
00623 
00624     case gTestContinuousTxMod_c: // Sets the device to continuously transmit a 10101010 pattern
00625         AspSetDtsMode(gDtsNormal_c);
00626         //Enable continuous TX mode
00627         AspEnableBER();
00628         //Prepare TX operation
00629         aTxContModPattern[0] = 1;
00630         aTxContModPattern[1] = 0xAA;
00631         // Load the TX PB
00632         MCR20Drv_PB_SPIBurstWrite(aTxContModPattern, aTxContModPattern[0] + 1);
00633         // Program a Tx sequence
00634         phyReg = MCR20Drv_DirectAccessSPIRead(PHY_CTRL1);
00635         phyReg |=  gTX_c;
00636         MCR20Drv_DirectAccessSPIWrite( (uint8_t) PHY_CTRL1, phyReg);
00637         break;
00638 
00639     case gTestContinuousTxNoMod_c: // Sets the device to continuously transmit an unmodulated CW
00640         //Enable unmodulated TX
00641         AspSetDtsMode(gDtsTxOne_c);
00642         //Enable continuous TX mode
00643         AspEnableBER();
00644         MCR20Drv_DirectAccessSPIMultiByteWrite(PLL_FRAC0_LSB, (uint8_t *) &asp_pll_frac[channel - 11], 2);
00645         fracSet = TRUE;
00646         // Program a Tx sequence
00647         phyReg = MCR20Drv_DirectAccessSPIRead(PHY_CTRL1);
00648         phyReg |=  gTX_c;
00649         MCR20Drv_DirectAccessSPIWrite( (uint8_t) PHY_CTRL1, phyReg);
00650         break;
00651 
00652     case gTestContinuousTx2Mhz_c:
00653         AspSetDtsMode(gDtsTx2Mhz_c);
00654         //Enable continuous TX mode
00655         AspEnableBER();
00656         // Program a Tx sequence
00657         phyReg = MCR20Drv_DirectAccessSPIRead(PHY_CTRL1);
00658         phyReg |=  gTX_c;
00659         MCR20Drv_DirectAccessSPIWrite( (uint8_t) PHY_CTRL1, phyReg);
00660         break;
00661 
00662     case gTestContinuousTx200Khz_c:
00663         AspSetDtsMode(gDtsTx200Khz_c);
00664         //Enable continuous TX mode
00665         AspEnableBER();
00666         // Program a Tx sequence
00667         phyReg = MCR20Drv_DirectAccessSPIRead(PHY_CTRL1);
00668         phyReg |=  gTX_c;
00669         MCR20Drv_DirectAccessSPIWrite( (uint8_t) PHY_CTRL1, phyReg);
00670         break;
00671 
00672     case gTestContinuousTx1MbpsPRBS9_c:
00673         AspSetDtsMode(gDtsTx1MbpsPRBS9_c);
00674         //Enable continuous TX mode
00675         AspEnableBER();
00676         // Program a Tx sequence
00677         phyReg = MCR20Drv_DirectAccessSPIRead(PHY_CTRL1);
00678         phyReg |=  gTX_c;
00679         MCR20Drv_DirectAccessSPIWrite( (uint8_t) PHY_CTRL1, phyReg);
00680         break;
00681 
00682     case gTestContinuousTxExternalSrc_c:
00683         AspSetDtsMode(gDtsTxExternalSrc_c);
00684         //Enable continuous TX mode
00685         AspEnableBER();
00686         // Program a Tx sequence
00687         phyReg = MCR20Drv_DirectAccessSPIRead(PHY_CTRL1);
00688         phyReg |=  gTX_c;
00689         MCR20Drv_DirectAccessSPIWrite( (uint8_t) PHY_CTRL1, phyReg);
00690         break;
00691 
00692     case gTestContinuousTxNoModZero_c:
00693         //Enable unmodulated TX
00694         AspSetDtsMode(gDtsTxZero_c);
00695         //Enable continuous TX mode
00696         AspEnableBER();
00697         // Program a Tx sequence
00698         phyReg = MCR20Drv_DirectAccessSPIRead(PHY_CTRL1);
00699         phyReg |=  gTX_c;
00700         MCR20Drv_DirectAccessSPIWrite( (uint8_t) PHY_CTRL1, phyReg);
00701         break;
00702 
00703     case gTestContinuousTxNoModOne_c:
00704         //Enable unmodulated TX
00705         AspSetDtsMode(gDtsTxOne_c);
00706         //Enable continuous TX mode
00707         AspEnableBER();
00708         // Program a Tx sequence
00709         phyReg = MCR20Drv_DirectAccessSPIRead(PHY_CTRL1);
00710         phyReg |=  gTX_c;
00711         MCR20Drv_DirectAccessSPIWrite( (uint8_t) PHY_CTRL1, phyReg);
00712         break;
00713     }
00714 
00715     return gAspSuccess_c;
00716 }
00717 
00718 /*! *********************************************************************************
00719 * \brief  Return the instance of the PHY associated with the FSCI interface
00720 *
00721 * \param[in]  interfaceId  FSCI interface
00722 *
00723 * \return  insance
00724 *
00725 ********************************************************************************** */
00726 #if gFsciIncluded_c
00727 #undef mFuncId_c
00728 #define mFuncId_c 20
00729 static uint32_t getPhyInstance( uint32_t interfaceId )
00730 {
00731     uint32_t i;
00732 
00733     for( i=0; i<gPhyInstancesCnt_c; i++ )
00734         if( mAspFsciBinding[i] == interfaceId )
00735             return i;
00736 
00737     return 0;
00738 }
00739 
00740 /*! *********************************************************************************
00741 * \brief  Handle ASP requests received from FSCI
00742 *
00743 * \param[in]  pData        monitored message
00744 * \param[in]  param        
00745 * \param[in]  interfaceId  FSCI interface 
00746 *
00747 ********************************************************************************** */
00748 #undef mFuncId_c
00749 #define mFuncId_c 21
00750 static void fsciAspReqHandler(void *pData, void* param, uint32_t interfaceId)
00751 {
00752     clientPacket_t *pClientPacket = ((clientPacket_t*)pData);
00753     uint8_t *pMsg = pClientPacket->structured.payload;
00754 
00755     pMsg -= sizeof(AppAspMsgType_t);
00756     ((AppToAspMessage_t*)pMsg)->msgType = (AppAspMsgType_t)pClientPacket->structured.header.opCode;
00757 
00758     APP_ASP_SapHandler( (AppToAspMessage_t*)pMsg, getPhyInstance( interfaceId ) );
00759     MEM_BufferFree(pData);
00760 }
00761 
00762 /*! *********************************************************************************
00763 * \brief  Monitor the ASP Requests and Responses
00764 *
00765 * \param[in]  pData        monitored message
00766 * \param[in]  param        
00767 * \param[in]  interfaceId  FSCI interface 
00768 *
00769 * \return  AspStatus_t
00770 *
00771 ********************************************************************************** */
00772 #undef mFuncId_c
00773 #define mFuncId_c 22
00774 static void AspSapMonitor(void *pData, void* param, uint32_t interfaceId)
00775 {
00776     clientPacket_t *pFsciPacket = MEM_BufferAlloc( sizeof(clientPacket_t) );
00777     AppToAspMessage_t *pReq = (AppToAspMessage_t*)pData;
00778     uint8_t *p;
00779 
00780     if( NULL == pFsciPacket )
00781     {
00782         FSCI_Error( gFsciOutOfMessages_c, interfaceId );
00783         return;
00784     }
00785 
00786     p = pFsciPacket->structured.payload;
00787 
00788     if( NULL == param ) // Requests
00789     {
00790         pFsciPacket->structured.header.opGroup = gFSCI_AppAspOpcodeGroup_c;
00791         pFsciPacket->structured.header.opCode = pReq->msgType;
00792 
00793         switch( pReq->msgType )
00794         {
00795         case aspMsgTypeGetTimeReq_c:
00796             break;
00797         case aspMsgTypeXcvrWriteReq_c:
00798         case aspMsgTypeXcvrReadReq_c:
00799             *p++ = pReq->msgData.aspXcvrData.mode;
00800             *((uint16_t*)p) = pReq->msgData.aspXcvrData.addr;
00801             p += sizeof(uint16_t);
00802             *p++ = pReq->msgData.aspXcvrData.len;
00803             if( pReq->msgType == aspMsgTypeXcvrWriteReq_c )
00804             {
00805                 FLib_MemCpy( p, pReq->msgData.aspXcvrData.data,
00806                              pReq->msgData.aspXcvrData.len );
00807                 p += pReq->msgData.aspXcvrData.len;
00808             }
00809             break;
00810         case aspMsgTypeSetFADState_c:
00811             FLib_MemCpy( p, &pReq->msgData.aspFADState, sizeof(pReq->msgData.aspFADState) );
00812             p += sizeof(pReq->msgData.aspFADState);
00813             break;
00814         case aspMsgTypeSetFADThreshold_c:
00815             FLib_MemCpy( p, &pReq->msgData.aspFADThreshold, sizeof(pReq->msgData.aspFADThreshold) );
00816             p += sizeof(pReq->msgData.aspFADThreshold);
00817             break;
00818         case aspMsgTypeSetANTXState_c:
00819             FLib_MemCpy( p, &pReq->msgData.aspANTXState, sizeof(pReq->msgData.aspANTXState) );
00820             p += sizeof(pReq->msgData.aspANTXState);
00821             break;
00822         case aspMsgTypeGetANTXState_c:
00823             /* Nothing to do here */
00824             break;
00825 
00826         case aspMsgTypeSetPowerLevel_c:
00827             FLib_MemCpy( p, &pReq->msgData.aspSetPowerLevelReq, sizeof(pReq->msgData.aspSetPowerLevelReq) );
00828             p += sizeof(pReq->msgData.aspSetPowerLevelReq);
00829             break;
00830         case aspMsgTypeGetPowerLevel_c:
00831             /* Nothing to do here */
00832             break;
00833         case aspMsgTypeTelecSetFreq_c:
00834             FLib_MemCpy( p, &pReq->msgData.aspTelecsetFreq, sizeof(pReq->msgData.aspTelecsetFreq) );
00835             p += sizeof(pReq->msgData.aspTelecsetFreq);
00836             break;
00837         case aspMsgTypeTelecSendRawData_c:
00838             FLib_MemCpy( p, &pReq->msgData.aspTelecSendRawData, sizeof(pReq->msgData.aspTelecSendRawData) );
00839             p += sizeof(pReq->msgData.aspTelecSendRawData);
00840             break;
00841         case aspMsgTypeTelecTest_c:
00842             FLib_MemCpy( p, &pReq->msgData.aspTelecTest, sizeof(pReq->msgData.aspTelecTest) );
00843             p += sizeof(pReq->msgData.aspTelecTest);
00844             break;
00845         case aspMsgTypeSetLQIMode_c:
00846             FLib_MemCpy(p, &pReq->msgData.aspLQIMode, sizeof(pReq->msgData.aspLQIMode) );
00847             p += sizeof(pReq->msgData.aspLQIMode);
00848             break;
00849         case aspMsgTypeGetRSSILevel_c:
00850             /* Nothing to do here */
00851             break;
00852         }
00853     }
00854     else // Confirms / Indications
00855     {
00856         pFsciPacket->structured.header.opGroup = gFSCI_AspAppOpcodeGroup_c;
00857         pFsciPacket->structured.header.opCode = pReq->msgType;
00858 
00859         *p++ = *((uint8_t*)param);/* copy status */
00860 
00861         switch( pReq->msgType )
00862         {
00863         case aspMsgTypeGetTimeReq_c:
00864             FLib_MemCpy( p, &pReq->msgData.aspGetTimeReq.time , sizeof(aspEventReq_t) );
00865             p += sizeof(aspEventReq_t);
00866             break;
00867         case aspMsgTypeGetMpmConfig_c:
00868             FLib_MemCpy( p, &pReq->msgData.MpmConfig , sizeof(mpmConfig_t) );
00869             p += sizeof(mpmConfig_t);
00870             break;
00871         case aspMsgTypeXcvrReadReq_c:
00872             *p++ = pReq->msgData.aspXcvrData.len; /* copy length */
00873             FLib_MemCpy( p, pReq->msgData.aspXcvrData.data, pReq->msgData.aspXcvrData.len );
00874             p += pReq->msgData.aspXcvrData.len;
00875             break;
00876         }
00877 
00878     }
00879 
00880     /* Send data over the serial interface */
00881     pFsciPacket->structured.header.len = (fsciLen_t)(p - pFsciPacket->structured.payload);
00882 
00883     if ( pFsciPacket->structured.header.len )
00884         FSCI_transmitFormatedPacket( pFsciPacket, interfaceId );
00885     else
00886         MEM_BufferFree( pFsciPacket );
00887 }
00888 
00889 #endif /* gFsciIncluded_c */
00890 
00891 
00892  /*! *********************************************************************************
00893 * \brief  Set the Tx data source selector
00894 *
00895 * \param[in]  mode 
00896 *
00897 * \return  AspStatus_t
00898 *
00899 ********************************************************************************** */
00900 phyStatus_t AspSetDtsMode(uint8_t mode)
00901 {
00902   uint8_t phyReg;
00903 
00904   phyReg = MCR20Drv_IndirectAccessSPIRead(TX_MODE_CTRL);
00905   phyReg &= ~cTX_MODE_CTRL_DTS_MASK;   // Clear DTS_MODE
00906   phyReg |= mode; // Set new DTS_MODE
00907   MCR20Drv_IndirectAccessSPIWrite(TX_MODE_CTRL, phyReg);
00908 
00909   return gPhySuccess_c;
00910 }
00911 
00912 /*! *********************************************************************************
00913 * \brief  Enable XCVR test mode
00914 *
00915 * \return  AspStatus_t
00916 *
00917 ********************************************************************************** */
00918 phyStatus_t AspEnableBER()
00919 {
00920   uint8_t phyReg;
00921 
00922   phyReg = MCR20Drv_IndirectAccessSPIRead(DTM_CTRL1);
00923   phyReg |= cDTM_CTRL1_DTM_EN;
00924   MCR20Drv_IndirectAccessSPIWrite(DTM_CTRL1, phyReg);
00925 
00926   phyReg = MCR20Drv_IndirectAccessSPIRead(TESTMODE_CTRL);
00927   phyReg |= cTEST_MODE_CTRL_CONTINUOUS_EN | cTEST_MODE_CTRL_IDEAL_PFC_EN;
00928   MCR20Drv_IndirectAccessSPIWrite(TESTMODE_CTRL, phyReg);
00929 
00930   return gPhySuccess_c;
00931 }
00932 
00933 /*! *********************************************************************************
00934 * \brief  Disable XCVR test mode
00935 *
00936 ********************************************************************************** */
00937 void AspDisableBER()
00938 {
00939   uint8_t phyReg;
00940 
00941   phyReg = MCR20Drv_IndirectAccessSPIRead(DTM_CTRL1);
00942   phyReg &= ~cDTM_CTRL1_DTM_EN;
00943   MCR20Drv_IndirectAccessSPIWrite(DTM_CTRL1, phyReg);
00944 
00945   phyReg = MCR20Drv_IndirectAccessSPIRead(TESTMODE_CTRL);
00946   phyReg &= ~(cTEST_MODE_CTRL_CONTINUOUS_EN | cTEST_MODE_CTRL_IDEAL_PFC_EN);
00947   MCR20Drv_IndirectAccessSPIWrite(TESTMODE_CTRL, phyReg);
00948 }
00949 
00950 
00951 #endif /* gAspCapability_d */