this a test code modified to cr20A

Dependencies:   fsl_phy_mcr20a fsl_smac mbed-rtos mbed

Fork of mcr20_connectivity_test by Freescale

Committer:
andreikovacs
Date:
Thu Jul 16 07:29:15 2015 +0000
Revision:
0:4eb2240dbd22
Child:
1:1eb1eccc81c2
Initial commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andreikovacs 0:4eb2240dbd22 1 /*!
andreikovacs 0:4eb2240dbd22 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
andreikovacs 0:4eb2240dbd22 3 * All rights reserved.
andreikovacs 0:4eb2240dbd22 4 *
andreikovacs 0:4eb2240dbd22 5 * \file Connectivity_TestApp.c
andreikovacs 0:4eb2240dbd22 6 *
andreikovacs 0:4eb2240dbd22 7 * Redistribution and use in source and binary forms, with or without modification,
andreikovacs 0:4eb2240dbd22 8 * are permitted provided that the following conditions are met:
andreikovacs 0:4eb2240dbd22 9 *
andreikovacs 0:4eb2240dbd22 10 * o Redistributions of source code must retain the above copyright notice, this list
andreikovacs 0:4eb2240dbd22 11 * of conditions and the following disclaimer.
andreikovacs 0:4eb2240dbd22 12 *
andreikovacs 0:4eb2240dbd22 13 * o Redistributions in binary form must reproduce the above copyright notice, this
andreikovacs 0:4eb2240dbd22 14 * list of conditions and the following disclaimer in the documentation and/or
andreikovacs 0:4eb2240dbd22 15 * other materials provided with the distribution.
andreikovacs 0:4eb2240dbd22 16 *
andreikovacs 0:4eb2240dbd22 17 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
andreikovacs 0:4eb2240dbd22 18 * contributors may be used to endorse or promote products derived from this
andreikovacs 0:4eb2240dbd22 19 * software without specific prior written permission.
andreikovacs 0:4eb2240dbd22 20 *
andreikovacs 0:4eb2240dbd22 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
andreikovacs 0:4eb2240dbd22 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
andreikovacs 0:4eb2240dbd22 23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
andreikovacs 0:4eb2240dbd22 24 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
andreikovacs 0:4eb2240dbd22 25 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
andreikovacs 0:4eb2240dbd22 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
andreikovacs 0:4eb2240dbd22 27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
andreikovacs 0:4eb2240dbd22 28 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
andreikovacs 0:4eb2240dbd22 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
andreikovacs 0:4eb2240dbd22 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
andreikovacs 0:4eb2240dbd22 31 */
andreikovacs 0:4eb2240dbd22 32
andreikovacs 0:4eb2240dbd22 33 /************************************************************************************
andreikovacs 0:4eb2240dbd22 34 *************************************************************************************
andreikovacs 0:4eb2240dbd22 35 * Include
andreikovacs 0:4eb2240dbd22 36 *************************************************************************************
andreikovacs 0:4eb2240dbd22 37 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 38
andreikovacs 0:4eb2240dbd22 39 #include "Application_Interface.h"
andreikovacs 0:4eb2240dbd22 40 #include "Connectivity_Test_Platform.h"
andreikovacs 0:4eb2240dbd22 41 /************************************************************************************
andreikovacs 0:4eb2240dbd22 42 *************************************************************************************
andreikovacs 0:4eb2240dbd22 43 * Private type definitions
andreikovacs 0:4eb2240dbd22 44 *************************************************************************************
andreikovacs 0:4eb2240dbd22 45 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 46
andreikovacs 0:4eb2240dbd22 47 /************************************************************************************
andreikovacs 0:4eb2240dbd22 48 *************************************************************************************
andreikovacs 0:4eb2240dbd22 49 * Macros
andreikovacs 0:4eb2240dbd22 50 *************************************************************************************
andreikovacs 0:4eb2240dbd22 51 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 52 #define gPrbs9BufferLength_c ( 65 )
andreikovacs 0:4eb2240dbd22 53 #define gContTxModSelectPN9_c ( 2 )
andreikovacs 0:4eb2240dbd22 54 #define gContTxModSelectOnes_c ( 1 )
andreikovacs 0:4eb2240dbd22 55 #define gContTxModSelectZeros_c ( 0 )
andreikovacs 0:4eb2240dbd22 56 #define SelfNotificationEvent() mainTask->signal_set(gCTSelf_EVENT_c);
andreikovacs 0:4eb2240dbd22 57
andreikovacs 0:4eb2240dbd22 58 #define gUART_RX_EVENT_c (1<<0)
andreikovacs 0:4eb2240dbd22 59 #define gMcps_Cnf_EVENT_c (1<<1)
andreikovacs 0:4eb2240dbd22 60 #define gMcps_Ind_EVENT_c (1<<2)
andreikovacs 0:4eb2240dbd22 61 #define gMlme_EdCnf_EVENT_c (1<<3)
andreikovacs 0:4eb2240dbd22 62 #define gMlme_CcaCnf_EVENT_c (1<<4)
andreikovacs 0:4eb2240dbd22 63 #define gMlme_TimeoutInd_EVENT_c (1<<5)
andreikovacs 0:4eb2240dbd22 64 #define gRangeTest_EVENT_c (1<<6)
andreikovacs 0:4eb2240dbd22 65 #define gCTSelf_EVENT_c (1<<7)
andreikovacs 0:4eb2240dbd22 66 #define gTimePassed_EVENT_c (1<<8)
andreikovacs 0:4eb2240dbd22 67
andreikovacs 0:4eb2240dbd22 68 #define gEventsAll_c (gUART_RX_EVENT_c | gMcps_Ind_EVENT_c | gMcps_Cnf_EVENT_c | \
andreikovacs 0:4eb2240dbd22 69 gMlme_TimeoutInd_EVENT_c | gMlme_EdCnf_EVENT_c | gMlme_CcaCnf_EVENT_c | \
andreikovacs 0:4eb2240dbd22 70 gRangeTest_EVENT_c | gCTSelf_EVENT_c | gTimePassed_EVENT_c)
andreikovacs 0:4eb2240dbd22 71
andreikovacs 0:4eb2240dbd22 72 #define Delay_ms(a)
andreikovacs 0:4eb2240dbd22 73 #define FlaggedDelay_ms(a) TMR_StartSingleShotTimer(AppDelayTmr, a, DelayTimeElapsed, NULL)
andreikovacs 0:4eb2240dbd22 74
andreikovacs 0:4eb2240dbd22 75 #ifdef gPHY_802_15_4g_d
andreikovacs 0:4eb2240dbd22 76 #define GetTimestampUS() PhyTime_GetTimestampUs()
andreikovacs 0:4eb2240dbd22 77 #define GetTransmissionTime(payload, bitrate) ((((gPhyFSKPreambleLength_c + \
andreikovacs 0:4eb2240dbd22 78 gPhyMRFSKPHRLength_c + gPhyMRFSKSFDLength_c + \
andreikovacs 0:4eb2240dbd22 79 sizeof(smacHeader_t) + payload + gPhyFCSSize_c )*8000 )/ bitrate))
andreikovacs 0:4eb2240dbd22 80 #else
andreikovacs 0:4eb2240dbd22 81 #define GetTimestampUS() (16*PhyTime_GetTimestamp())
andreikovacs 0:4eb2240dbd22 82 #define GetTransmissionTime(payload, bitrate) (((6 + sizeof(smacHeader_t) + payload + 2)*32))
andreikovacs 0:4eb2240dbd22 83 //bitrate is fixed for 2.4 GHz
andreikovacs 0:4eb2240dbd22 84 #define crtBitrate (0)
andreikovacs 0:4eb2240dbd22 85 #endif
andreikovacs 0:4eb2240dbd22 86 /************************************************************************************
andreikovacs 0:4eb2240dbd22 87 *************************************************************************************
andreikovacs 0:4eb2240dbd22 88 * Public memory declarations
andreikovacs 0:4eb2240dbd22 89 *************************************************************************************
andreikovacs 0:4eb2240dbd22 90 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 91
andreikovacs 0:4eb2240dbd22 92 uint32_t gTaskEventFlags;
andreikovacs 0:4eb2240dbd22 93
andreikovacs 0:4eb2240dbd22 94 /*smac related variables*/
andreikovacs 0:4eb2240dbd22 95 bool_t bTxDone;
andreikovacs 0:4eb2240dbd22 96 bool_t bRxDone;
andreikovacs 0:4eb2240dbd22 97 bool_t bScanDone;
andreikovacs 0:4eb2240dbd22 98 bool_t gCCaGotResult;
andreikovacs 0:4eb2240dbd22 99 bool_t gIsChannelIdle;
andreikovacs 0:4eb2240dbd22 100 bool_t bEdDone;
andreikovacs 0:4eb2240dbd22 101 bool_t failedPRBS9;
andreikovacs 0:4eb2240dbd22 102 uint8_t u8LastRxRssiValue;
andreikovacs 0:4eb2240dbd22 103 bool_t evTestParameters;
andreikovacs 0:4eb2240dbd22 104 uint8_t au8ScanResults[129];
andreikovacs 0:4eb2240dbd22 105
andreikovacs 0:4eb2240dbd22 106 /*serial manager related variables*/
andreikovacs 0:4eb2240dbd22 107 uint8_t gu8UartData;
andreikovacs 0:4eb2240dbd22 108 bool_t evDataFromUART;
andreikovacs 0:4eb2240dbd22 109 uint8_t mAppSer;
andreikovacs 0:4eb2240dbd22 110
andreikovacs 0:4eb2240dbd22 111 /*connectivity test state machine variables*/
andreikovacs 0:4eb2240dbd22 112 operationModes_t testOpMode;
andreikovacs 0:4eb2240dbd22 113 operationModes_t prevOpMode;
andreikovacs 0:4eb2240dbd22 114
andreikovacs 0:4eb2240dbd22 115 channels_t testChannel;
andreikovacs 0:4eb2240dbd22 116 uint8_t testPower;
andreikovacs 0:4eb2240dbd22 117 uint8_t testPayloadLen;
andreikovacs 0:4eb2240dbd22 118 uint8_t contTxModBitValue;
andreikovacs 0:4eb2240dbd22 119 uint8_t ccaThresh;
andreikovacs 0:4eb2240dbd22 120 bool_t shortCutsEnabled;
andreikovacs 0:4eb2240dbd22 121 ConnectivityStates_t connState;
andreikovacs 0:4eb2240dbd22 122 ContinuousTxRxTestStates_t cTxRxState;
andreikovacs 0:4eb2240dbd22 123 PerTxStates_t perTxState;
andreikovacs 0:4eb2240dbd22 124 PerRxStates_t perRxState;
andreikovacs 0:4eb2240dbd22 125 RangeTxStates_t rangeTxState;
andreikovacs 0:4eb2240dbd22 126 RangeRxStates_t rangeRxState;
andreikovacs 0:4eb2240dbd22 127 EditRegsStates_t eRState;
andreikovacs 0:4eb2240dbd22 128 oRStates_t oRState;
andreikovacs 0:4eb2240dbd22 129 rRStates_t rRState;
andreikovacs 0:4eb2240dbd22 130 dRStates_t dRState;
andreikovacs 0:4eb2240dbd22 131 CSenseTCtrlStates_t cstcState;
andreikovacs 0:4eb2240dbd22 132 uint8_t ChannelToScan;
andreikovacs 0:4eb2240dbd22 133 smacTestMode_t contTestRunning;
andreikovacs 0:4eb2240dbd22 134
andreikovacs 0:4eb2240dbd22 135 /*asp related variables*/
andreikovacs 0:4eb2240dbd22 136 AppToAspMessage_t aspTestRequestMsg;
andreikovacs 0:4eb2240dbd22 137
andreikovacs 0:4eb2240dbd22 138 extern uint8_t u8Prbs9Buffer[gPrbs9BufferLength_c];
andreikovacs 0:4eb2240dbd22 139
andreikovacs 0:4eb2240dbd22 140 Serial uart(USBTX,USBRX);
andreikovacs 0:4eb2240dbd22 141 Thread *mainTask;
andreikovacs 0:4eb2240dbd22 142
andreikovacs 0:4eb2240dbd22 143 /************************************************************************************
andreikovacs 0:4eb2240dbd22 144 *************************************************************************************
andreikovacs 0:4eb2240dbd22 145 * Private memory declarations
andreikovacs 0:4eb2240dbd22 146 *************************************************************************************
andreikovacs 0:4eb2240dbd22 147 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 148 static uint8_t gau8RxDataBuffer[gMaxSmacSDULength_c + sizeof(txPacket_t)];
andreikovacs 0:4eb2240dbd22 149 static uint8_t gau8TxDataBuffer[gMaxSmacSDULength_c + sizeof(rxPacket_t)];
andreikovacs 0:4eb2240dbd22 150
andreikovacs 0:4eb2240dbd22 151 static txPacket_t * gAppTxPacket;
andreikovacs 0:4eb2240dbd22 152 static rxPacket_t * gAppRxPacket;
andreikovacs 0:4eb2240dbd22 153
andreikovacs 0:4eb2240dbd22 154 static uint8_t timePassed;
andreikovacs 0:4eb2240dbd22 155 Timeout RangeTestTmr;
andreikovacs 0:4eb2240dbd22 156 Timer AppDelayTmr;
andreikovacs 0:4eb2240dbd22 157 /************************************************************************************
andreikovacs 0:4eb2240dbd22 158 *************************************************************************************
andreikovacs 0:4eb2240dbd22 159 * Private prototypes
andreikovacs 0:4eb2240dbd22 160 *************************************************************************************
andreikovacs 0:4eb2240dbd22 161 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 162 #if CT_Feature_Calibration
andreikovacs 0:4eb2240dbd22 163 extern void StoreTrimValueToFlash (uint32_t trimValue, CalibrationOptionSelect_t option);
andreikovacs 0:4eb2240dbd22 164 #endif
andreikovacs 0:4eb2240dbd22 165
andreikovacs 0:4eb2240dbd22 166 /*platform independent functions*/
andreikovacs 0:4eb2240dbd22 167 static void SerialUIStateMachine(void);
andreikovacs 0:4eb2240dbd22 168 static bool_t SerialContinuousTxRxTest(void);
andreikovacs 0:4eb2240dbd22 169 static bool_t PacketErrorRateTx(void);
andreikovacs 0:4eb2240dbd22 170 static bool_t PacketErrorRateRx(void);
andreikovacs 0:4eb2240dbd22 171 static void SetRadioRxOnNoTimeOut(void);
andreikovacs 0:4eb2240dbd22 172 static void HandleEvents(int32_t evSignals);
andreikovacs 0:4eb2240dbd22 173 static void PrintTestParameters(bool_t bEraseLine);
andreikovacs 0:4eb2240dbd22 174
andreikovacs 0:4eb2240dbd22 175 static void PrintPerRxFinalLine(uint16_t u16Received, uint16_t u16Total);
andreikovacs 0:4eb2240dbd22 176 extern uint32_t HexString2Dec(uint8_t * au8String);
andreikovacs 0:4eb2240dbd22 177 static bool_t stringComp(uint8_t * au8leftString, uint8_t * au8RightString, uint8_t bytesToCompare);
andreikovacs 0:4eb2240dbd22 178 /********************************/
andreikovacs 0:4eb2240dbd22 179
andreikovacs 0:4eb2240dbd22 180 static void RangeTest_Timer_CallBack ();
andreikovacs 0:4eb2240dbd22 181 static bool_t RangeTx(void);
andreikovacs 0:4eb2240dbd22 182 static bool_t RangeRx(void);
andreikovacs 0:4eb2240dbd22 183
andreikovacs 0:4eb2240dbd22 184 static bool_t EditRegisters(void);
andreikovacs 0:4eb2240dbd22 185 #if CT_Feature_Direct_Registers || CT_Feature_Indirect_Registers
andreikovacs 0:4eb2240dbd22 186 bool_t OverrideRegisters(void);
andreikovacs 0:4eb2240dbd22 187 bool_t ReadRegisters(void);
andreikovacs 0:4eb2240dbd22 188 bool_t DumpRegisters(void);
andreikovacs 0:4eb2240dbd22 189 bool_t bIsRegisterDirect = TRUE;
andreikovacs 0:4eb2240dbd22 190 #endif
andreikovacs 0:4eb2240dbd22 191
andreikovacs 0:4eb2240dbd22 192 static bool_t CSenseAndTCtrl(void);
andreikovacs 0:4eb2240dbd22 193 static void TransmissionControlHandler(void);
andreikovacs 0:4eb2240dbd22 194 static void CarrierSenseHandler(void);
andreikovacs 0:4eb2240dbd22 195 static smacErrors_t TestMode ( smacTestMode_t mode);
andreikovacs 0:4eb2240dbd22 196 static void PacketHandler_Prbs9(void);
andreikovacs 0:4eb2240dbd22 197 static void DelayTimeElapsed();
andreikovacs 0:4eb2240dbd22 198 static void IncrementChannelOnEdEvent();
andreikovacs 0:4eb2240dbd22 199 extern void ReadRFRegs(registerAddressSize_t, registerAddressSize_t);
andreikovacs 0:4eb2240dbd22 200 extern void PrintTestParameters(bool_t bEraseLine);
andreikovacs 0:4eb2240dbd22 201
andreikovacs 0:4eb2240dbd22 202 /*************************************/
andreikovacs 0:4eb2240dbd22 203 /************************************************************************************
andreikovacs 0:4eb2240dbd22 204 *************************************************************************************
andreikovacs 0:4eb2240dbd22 205 * Public functions
andreikovacs 0:4eb2240dbd22 206 *************************************************************************************
andreikovacs 0:4eb2240dbd22 207 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 208 void InitProject(void);
andreikovacs 0:4eb2240dbd22 209 void InitSmac(void);
andreikovacs 0:4eb2240dbd22 210 void main_task(void const *argument);
andreikovacs 0:4eb2240dbd22 211 extern void ResetMCU(void);
andreikovacs 0:4eb2240dbd22 212 void UartRxCallBack(void * param);
andreikovacs 0:4eb2240dbd22 213 void PrintMenu(char * const pu8Menu[], uint8_t port);
andreikovacs 0:4eb2240dbd22 214
andreikovacs 0:4eb2240dbd22 215 /************************************************************************************
andreikovacs 0:4eb2240dbd22 216 *
andreikovacs 0:4eb2240dbd22 217 * InitProject
andreikovacs 0:4eb2240dbd22 218 *
andreikovacs 0:4eb2240dbd22 219 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 220 void InitProject(void)
andreikovacs 0:4eb2240dbd22 221 {
andreikovacs 0:4eb2240dbd22 222 /*Global Data init*/
andreikovacs 0:4eb2240dbd22 223 testPayloadLen = gMaxSmacSDULength_c;
andreikovacs 0:4eb2240dbd22 224
andreikovacs 0:4eb2240dbd22 225 testOpMode = gDefaultOperationMode_c;
andreikovacs 0:4eb2240dbd22 226 testChannel = gDefaultChannelNumber_c;
andreikovacs 0:4eb2240dbd22 227 testPower = gDefaultOutputPower_c;
andreikovacs 0:4eb2240dbd22 228 testPayloadLen = gDefaultPayload_c;
andreikovacs 0:4eb2240dbd22 229 contTestRunning = gTestModeForceIdle_c;
andreikovacs 0:4eb2240dbd22 230 shortCutsEnabled = FALSE;
andreikovacs 0:4eb2240dbd22 231 connState = gConnInitState_c;
andreikovacs 0:4eb2240dbd22 232 cTxRxState = gCTxRxStateInit_c;
andreikovacs 0:4eb2240dbd22 233 perTxState = gPerTxStateInit_c;
andreikovacs 0:4eb2240dbd22 234 perRxState = gPerRxStateInit_c;
andreikovacs 0:4eb2240dbd22 235 rangeTxState = gRangeTxStateInit_c;
andreikovacs 0:4eb2240dbd22 236 rangeRxState = gRangeRxStateInit_c;
andreikovacs 0:4eb2240dbd22 237 prevOpMode = gDefaultOperationMode_c;
andreikovacs 0:4eb2240dbd22 238 oRState = gORStateInit_c;
andreikovacs 0:4eb2240dbd22 239 rRState = gRRStateInit_c;
andreikovacs 0:4eb2240dbd22 240 dRState = gDRStateInit_c;
andreikovacs 0:4eb2240dbd22 241 ccaThresh = gDefaultCCAThreshold_c;
andreikovacs 0:4eb2240dbd22 242 bEdDone = FALSE;
andreikovacs 0:4eb2240dbd22 243 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 244
andreikovacs 0:4eb2240dbd22 245 InitProject_custom();
andreikovacs 0:4eb2240dbd22 246 }
andreikovacs 0:4eb2240dbd22 247
andreikovacs 0:4eb2240dbd22 248 /************************************************************************************
andreikovacs 0:4eb2240dbd22 249 *************************************************************************************
andreikovacs 0:4eb2240dbd22 250 * SAP functions
andreikovacs 0:4eb2240dbd22 251 *************************************************************************************
andreikovacs 0:4eb2240dbd22 252 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 253
andreikovacs 0:4eb2240dbd22 254 //(Management) Sap handler for managing timeout indication and ED confirm
andreikovacs 0:4eb2240dbd22 255 smacErrors_t smacToAppMlmeSap(smacToAppMlmeMessage_t* pMsg, instanceId_t instance)
andreikovacs 0:4eb2240dbd22 256 {
andreikovacs 0:4eb2240dbd22 257 switch(pMsg->msgType)
andreikovacs 0:4eb2240dbd22 258 {
andreikovacs 0:4eb2240dbd22 259 case gMlmeEdCnf_c:
andreikovacs 0:4eb2240dbd22 260 au8ScanResults[pMsg->msgData.edCnf.scannedChannel] = pMsg->msgData.edCnf.energyLeveldB;
andreikovacs 0:4eb2240dbd22 261 gTaskEventFlags |= gMlme_EdCnf_EVENT_c;
andreikovacs 0:4eb2240dbd22 262 break;
andreikovacs 0:4eb2240dbd22 263 case gMlmeCcaCnf_c:
andreikovacs 0:4eb2240dbd22 264 gTaskEventFlags |= gMlme_CcaCnf_EVENT_c;
andreikovacs 0:4eb2240dbd22 265 if(pMsg->msgData.ccaCnf.status == gErrorNoError_c)
andreikovacs 0:4eb2240dbd22 266 gIsChannelIdle = TRUE;
andreikovacs 0:4eb2240dbd22 267 else
andreikovacs 0:4eb2240dbd22 268 gIsChannelIdle = FALSE;
andreikovacs 0:4eb2240dbd22 269 break;
andreikovacs 0:4eb2240dbd22 270 case gMlmeTimeoutInd_c:
andreikovacs 0:4eb2240dbd22 271 gTaskEventFlags |= gMlme_TimeoutInd_EVENT_c;
andreikovacs 0:4eb2240dbd22 272 break;
andreikovacs 0:4eb2240dbd22 273 default:
andreikovacs 0:4eb2240dbd22 274 break;
andreikovacs 0:4eb2240dbd22 275 }
andreikovacs 0:4eb2240dbd22 276 MEM_BufferFree(pMsg);
andreikovacs 0:4eb2240dbd22 277 return gErrorNoError_c;
andreikovacs 0:4eb2240dbd22 278 }
andreikovacs 0:4eb2240dbd22 279 //(Data) Sap handler for managing data confirm and data indication
andreikovacs 0:4eb2240dbd22 280 smacErrors_t smacToAppMcpsSap(smacToAppDataMessage_t* pMsg, instanceId_t instance)
andreikovacs 0:4eb2240dbd22 281 {
andreikovacs 0:4eb2240dbd22 282 switch(pMsg->msgType)
andreikovacs 0:4eb2240dbd22 283 {
andreikovacs 0:4eb2240dbd22 284 case gMcpsDataInd_c:
andreikovacs 0:4eb2240dbd22 285 if(pMsg->msgData.dataInd.pRxPacket->rxStatus == rxSuccessStatus_c)
andreikovacs 0:4eb2240dbd22 286 {
andreikovacs 0:4eb2240dbd22 287 u8LastRxRssiValue = pMsg->msgData.dataInd.u8LastRxRssi;
andreikovacs 0:4eb2240dbd22 288 gTaskEventFlags |= gMcps_Ind_EVENT_c;
andreikovacs 0:4eb2240dbd22 289 }
andreikovacs 0:4eb2240dbd22 290 break;
andreikovacs 0:4eb2240dbd22 291 case gMcpsDataCnf_c:
andreikovacs 0:4eb2240dbd22 292 if(pMsg->msgData.dataCnf.status == gErrorNoError_c)
andreikovacs 0:4eb2240dbd22 293 {
andreikovacs 0:4eb2240dbd22 294 gTaskEventFlags |= gMcps_Cnf_EVENT_c;
andreikovacs 0:4eb2240dbd22 295
andreikovacs 0:4eb2240dbd22 296 }
andreikovacs 0:4eb2240dbd22 297 break;
andreikovacs 0:4eb2240dbd22 298 default:
andreikovacs 0:4eb2240dbd22 299 break;
andreikovacs 0:4eb2240dbd22 300 }
andreikovacs 0:4eb2240dbd22 301
andreikovacs 0:4eb2240dbd22 302 MEM_BufferFree(pMsg);
andreikovacs 0:4eb2240dbd22 303 return gErrorNoError_c;
andreikovacs 0:4eb2240dbd22 304 }
andreikovacs 0:4eb2240dbd22 305
andreikovacs 0:4eb2240dbd22 306 static void HandleEvents(int32_t evSignals)
andreikovacs 0:4eb2240dbd22 307 {
andreikovacs 0:4eb2240dbd22 308 if(evSignals & gUART_RX_EVENT_c)
andreikovacs 0:4eb2240dbd22 309 {
andreikovacs 0:4eb2240dbd22 310 if(shortCutsEnabled)
andreikovacs 0:4eb2240dbd22 311 {
andreikovacs 0:4eb2240dbd22 312 ShortCutsParser(gu8UartData);
andreikovacs 0:4eb2240dbd22 313 }
andreikovacs 0:4eb2240dbd22 314 else
andreikovacs 0:4eb2240dbd22 315 {
andreikovacs 0:4eb2240dbd22 316 evDataFromUART = TRUE;
andreikovacs 0:4eb2240dbd22 317 }
andreikovacs 0:4eb2240dbd22 318 }
andreikovacs 0:4eb2240dbd22 319 if(evSignals & gMcps_Cnf_EVENT_c)
andreikovacs 0:4eb2240dbd22 320 {
andreikovacs 0:4eb2240dbd22 321 bTxDone = TRUE;
andreikovacs 0:4eb2240dbd22 322 }
andreikovacs 0:4eb2240dbd22 323 if(evSignals & gMcps_Ind_EVENT_c)
andreikovacs 0:4eb2240dbd22 324 {
andreikovacs 0:4eb2240dbd22 325 bRxDone = TRUE;
andreikovacs 0:4eb2240dbd22 326 }
andreikovacs 0:4eb2240dbd22 327 if(evSignals & gMlme_TimeoutInd_EVENT_c)
andreikovacs 0:4eb2240dbd22 328 {
andreikovacs 0:4eb2240dbd22 329 }
andreikovacs 0:4eb2240dbd22 330 if(evSignals & gRangeTest_EVENT_c)
andreikovacs 0:4eb2240dbd22 331 {
andreikovacs 0:4eb2240dbd22 332 bRxDone=TRUE;
andreikovacs 0:4eb2240dbd22 333 }
andreikovacs 0:4eb2240dbd22 334 if(evSignals & gMlme_EdCnf_EVENT_c)
andreikovacs 0:4eb2240dbd22 335 {
andreikovacs 0:4eb2240dbd22 336 if (cTxRxState == gCTxRxStateRunnigScanTest_c)
andreikovacs 0:4eb2240dbd22 337 {
andreikovacs 0:4eb2240dbd22 338 IncrementChannelOnEdEvent();
andreikovacs 0:4eb2240dbd22 339 }
andreikovacs 0:4eb2240dbd22 340 if (cTxRxState == gCTxRxStateRunnigEdTest_c)
andreikovacs 0:4eb2240dbd22 341 {
andreikovacs 0:4eb2240dbd22 342 cTxRxState = gCTxRxStateRunningEdTestGotResult_c;
andreikovacs 0:4eb2240dbd22 343 }
andreikovacs 0:4eb2240dbd22 344 if (connState == gConnCSenseAndTCtrl_c)
andreikovacs 0:4eb2240dbd22 345 {
andreikovacs 0:4eb2240dbd22 346 bScanDone = TRUE;
andreikovacs 0:4eb2240dbd22 347 }
andreikovacs 0:4eb2240dbd22 348 bEdDone = TRUE;
andreikovacs 0:4eb2240dbd22 349 }
andreikovacs 0:4eb2240dbd22 350 if(evSignals & gMlme_CcaCnf_EVENT_c)
andreikovacs 0:4eb2240dbd22 351 {
andreikovacs 0:4eb2240dbd22 352 gCCaGotResult = TRUE;
andreikovacs 0:4eb2240dbd22 353 uart.printf("Channel %d is", (uint32_t)testChannel);
andreikovacs 0:4eb2240dbd22 354 if(gIsChannelIdle)
andreikovacs 0:4eb2240dbd22 355 uart.printf("Idle\r\n");
andreikovacs 0:4eb2240dbd22 356 else
andreikovacs 0:4eb2240dbd22 357 uart.printf("Busy\r\n");
andreikovacs 0:4eb2240dbd22 358 }
andreikovacs 0:4eb2240dbd22 359 if(evSignals & gCTSelf_EVENT_c)
andreikovacs 0:4eb2240dbd22 360 {
andreikovacs 0:4eb2240dbd22 361 }
andreikovacs 0:4eb2240dbd22 362 }
andreikovacs 0:4eb2240dbd22 363
andreikovacs 0:4eb2240dbd22 364
andreikovacs 0:4eb2240dbd22 365 /*************************************************************************/
andreikovacs 0:4eb2240dbd22 366 /*Main Task: Application entry point*/
andreikovacs 0:4eb2240dbd22 367 /*************************************************************************/
andreikovacs 0:4eb2240dbd22 368 void main_task(void const *argument)
andreikovacs 0:4eb2240dbd22 369 {
andreikovacs 0:4eb2240dbd22 370 static bool_t bIsInitialized = FALSE;
andreikovacs 0:4eb2240dbd22 371 static bool_t bUserInteraction = FALSE;
andreikovacs 0:4eb2240dbd22 372 //Initialize Memory Manager, Timer Manager and LEDs.
andreikovacs 0:4eb2240dbd22 373 if( !bIsInitialized )
andreikovacs 0:4eb2240dbd22 374 {
andreikovacs 0:4eb2240dbd22 375
andreikovacs 0:4eb2240dbd22 376 MEM_Init();
andreikovacs 0:4eb2240dbd22 377 //initialize PHY
andreikovacs 0:4eb2240dbd22 378 Phy_Init();
andreikovacs 0:4eb2240dbd22 379
andreikovacs 0:4eb2240dbd22 380 InitApp();
andreikovacs 0:4eb2240dbd22 381
andreikovacs 0:4eb2240dbd22 382 /*Prints the Welcome screens in the terminal*/
andreikovacs 0:4eb2240dbd22 383 PrintMenu(cu8FreescaleLogo, mAppSer);
andreikovacs 0:4eb2240dbd22 384
andreikovacs 0:4eb2240dbd22 385 connState = gConnIdleState_c;
andreikovacs 0:4eb2240dbd22 386 bIsInitialized = TRUE;
andreikovacs 0:4eb2240dbd22 387 }
andreikovacs 0:4eb2240dbd22 388 if(!bUserInteraction)
andreikovacs 0:4eb2240dbd22 389 {
andreikovacs 0:4eb2240dbd22 390 while(1)
andreikovacs 0:4eb2240dbd22 391 {
andreikovacs 0:4eb2240dbd22 392 //(void)OSA_EventWait(&gTaskEvent, gEventsAll_c, FALSE, OSA_WAIT_FOREVER ,&gTaskEventFlags);
andreikovacs 0:4eb2240dbd22 393 Thread::signal_wait(gEventsAll_c);
andreikovacs 0:4eb2240dbd22 394 if(gTaskEventFlags & gUART_RX_EVENT_c)
andreikovacs 0:4eb2240dbd22 395 {
andreikovacs 0:4eb2240dbd22 396 if(gu8UartData == '\r')
andreikovacs 0:4eb2240dbd22 397 {
andreikovacs 0:4eb2240dbd22 398 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 399 bUserInteraction = TRUE;
andreikovacs 0:4eb2240dbd22 400 break;
andreikovacs 0:4eb2240dbd22 401 }
andreikovacs 0:4eb2240dbd22 402 else
andreikovacs 0:4eb2240dbd22 403 {
andreikovacs 0:4eb2240dbd22 404 PrintMenu(cu8FreescaleLogo, mAppSer);
andreikovacs 0:4eb2240dbd22 405 }
andreikovacs 0:4eb2240dbd22 406 }
andreikovacs 0:4eb2240dbd22 407 }
andreikovacs 0:4eb2240dbd22 408 }
andreikovacs 0:4eb2240dbd22 409 if(bUserInteraction)
andreikovacs 0:4eb2240dbd22 410 {
andreikovacs 0:4eb2240dbd22 411 while(1)
andreikovacs 0:4eb2240dbd22 412 {
andreikovacs 0:4eb2240dbd22 413 //(void)OSA_EventWait(&gTaskEvent, gEventsAll_c, FALSE, OSA_WAIT_FOREVER ,&gTaskEventFlags);
andreikovacs 0:4eb2240dbd22 414 Thread::signal_wait(gEventsAll_c);
andreikovacs 0:4eb2240dbd22 415 HandleEvents(gTaskEventFlags);
andreikovacs 0:4eb2240dbd22 416 SerialUIStateMachine();
andreikovacs 0:4eb2240dbd22 417 }
andreikovacs 0:4eb2240dbd22 418 }
andreikovacs 0:4eb2240dbd22 419 }
andreikovacs 0:4eb2240dbd22 420
andreikovacs 0:4eb2240dbd22 421 /*************************************************************************/
andreikovacs 0:4eb2240dbd22 422 /*InitApp: Initializes application mdoules and data*/
andreikovacs 0:4eb2240dbd22 423 /*************************************************************************/
andreikovacs 0:4eb2240dbd22 424 void InitApp()
andreikovacs 0:4eb2240dbd22 425 {
andreikovacs 0:4eb2240dbd22 426
andreikovacs 0:4eb2240dbd22 427 gAppTxPacket = (txPacket_t*)gau8TxDataBuffer; //Map TX packet to buffer
andreikovacs 0:4eb2240dbd22 428 gAppRxPacket = (rxPacket_t*)gau8RxDataBuffer; //Map Rx packet to buffer
andreikovacs 0:4eb2240dbd22 429 gAppRxPacket->u8MaxDataLength = gMaxSmacSDULength_c;
andreikovacs 0:4eb2240dbd22 430
andreikovacs 0:4eb2240dbd22 431 uart.baud(115200);
andreikovacs 0:4eb2240dbd22 432
andreikovacs 0:4eb2240dbd22 433 //Initialise SMAC
andreikovacs 0:4eb2240dbd22 434 InitSmac();
andreikovacs 0:4eb2240dbd22 435 //Tell SMAC who to call when it needs to pass a message to the application thread.
andreikovacs 0:4eb2240dbd22 436 Smac_RegisterSapHandlers((SMAC_APP_MCPS_SapHandler_t)smacToAppMcpsSap,(SMAC_APP_MLME_SapHandler_t)smacToAppMlmeSap,0);
andreikovacs 0:4eb2240dbd22 437
andreikovacs 0:4eb2240dbd22 438 InitProject();
andreikovacs 0:4eb2240dbd22 439
andreikovacs 0:4eb2240dbd22 440 InitApp_custom();
andreikovacs 0:4eb2240dbd22 441
andreikovacs 0:4eb2240dbd22 442 ASP_Init(0, mAppSer);
andreikovacs 0:4eb2240dbd22 443
andreikovacs 0:4eb2240dbd22 444 SMACFillHeader(&(gAppTxPacket->smacHeader), gBroadcastAddress_c); //@CMA, Conn Test. Start with broadcast address default
andreikovacs 0:4eb2240dbd22 445 (void)MLMEPAOutputAdjust(testPower);
andreikovacs 0:4eb2240dbd22 446 (void)MLMESetChannelRequest(testChannel); //@CMA, Conn Test. Start Foperation at default channel
andreikovacs 0:4eb2240dbd22 447 }
andreikovacs 0:4eb2240dbd22 448
andreikovacs 0:4eb2240dbd22 449 /************************************************************************************
andreikovacs 0:4eb2240dbd22 450 *
andreikovacs 0:4eb2240dbd22 451 * Connectivity Test State Machine
andreikovacs 0:4eb2240dbd22 452 *
andreikovacs 0:4eb2240dbd22 453 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 454 void SerialUIStateMachine(void)
andreikovacs 0:4eb2240dbd22 455 {
andreikovacs 0:4eb2240dbd22 456 if((gConnSelectTest_c == connState) && evTestParameters)
andreikovacs 0:4eb2240dbd22 457 {
andreikovacs 0:4eb2240dbd22 458 #if CT_Feature_Calibration
andreikovacs 0:4eb2240dbd22 459 (void)MLMESetAdditionalRFOffset(gOffsetIncrement);
andreikovacs 0:4eb2240dbd22 460 #endif
andreikovacs 0:4eb2240dbd22 461 (void)MLMESetChannelRequest(testChannel);
andreikovacs 0:4eb2240dbd22 462 (void)MLMEPAOutputAdjust(testPower);
andreikovacs 0:4eb2240dbd22 463 PrintTestParameters(TRUE);
andreikovacs 0:4eb2240dbd22 464 evTestParameters = FALSE;
andreikovacs 0:4eb2240dbd22 465 }
andreikovacs 0:4eb2240dbd22 466 switch(connState)
andreikovacs 0:4eb2240dbd22 467 {
andreikovacs 0:4eb2240dbd22 468 case gConnIdleState_c:
andreikovacs 0:4eb2240dbd22 469 PrintMenu(cu8MainMenu, mAppSer);
andreikovacs 0:4eb2240dbd22 470 PrintTestParameters(FALSE);
andreikovacs 0:4eb2240dbd22 471 shortCutsEnabled = TRUE;
andreikovacs 0:4eb2240dbd22 472 connState = gConnSelectTest_c;
andreikovacs 0:4eb2240dbd22 473 break;
andreikovacs 0:4eb2240dbd22 474 case gConnSelectTest_c:
andreikovacs 0:4eb2240dbd22 475 if(evDataFromUART){
andreikovacs 0:4eb2240dbd22 476 if('1' == gu8UartData)
andreikovacs 0:4eb2240dbd22 477 {
andreikovacs 0:4eb2240dbd22 478 cTxRxState = gCTxRxStateInit_c;
andreikovacs 0:4eb2240dbd22 479 connState = gConnContinuousTxRxState_c;
andreikovacs 0:4eb2240dbd22 480 }
andreikovacs 0:4eb2240dbd22 481 else if('2' == gu8UartData)
andreikovacs 0:4eb2240dbd22 482 {
andreikovacs 0:4eb2240dbd22 483 perTxState = gPerTxStateInit_c;
andreikovacs 0:4eb2240dbd22 484 perRxState = gPerRxStateInit_c;
andreikovacs 0:4eb2240dbd22 485 connState = gConnPerState_c;
andreikovacs 0:4eb2240dbd22 486 }
andreikovacs 0:4eb2240dbd22 487 else if('3' == gu8UartData)
andreikovacs 0:4eb2240dbd22 488 {
andreikovacs 0:4eb2240dbd22 489 rangeTxState = gRangeTxStateInit_c;
andreikovacs 0:4eb2240dbd22 490 rangeRxState = gRangeRxStateInit_c;
andreikovacs 0:4eb2240dbd22 491 connState = gConnRangeState_c;
andreikovacs 0:4eb2240dbd22 492 }
andreikovacs 0:4eb2240dbd22 493 else if('4' == gu8UartData)
andreikovacs 0:4eb2240dbd22 494 {
andreikovacs 0:4eb2240dbd22 495 cstcState = gCsTcStateInit_c;
andreikovacs 0:4eb2240dbd22 496 connState = gConnCSenseAndTCtrl_c;
andreikovacs 0:4eb2240dbd22 497 }
andreikovacs 0:4eb2240dbd22 498 #if CT_Feature_Direct_Registers || CT_Feature_Indirect_Registers
andreikovacs 0:4eb2240dbd22 499 else if('5' == gu8UartData)
andreikovacs 0:4eb2240dbd22 500 {
andreikovacs 0:4eb2240dbd22 501 eRState = gERStateInit_c;
andreikovacs 0:4eb2240dbd22 502 connState = gConnRegEditState_c;
andreikovacs 0:4eb2240dbd22 503 }
andreikovacs 0:4eb2240dbd22 504 #endif
andreikovacs 0:4eb2240dbd22 505 #if CT_Feature_Bitrate_Select
andreikovacs 0:4eb2240dbd22 506 else if('6' == gu8UartData)
andreikovacs 0:4eb2240dbd22 507 {
andreikovacs 0:4eb2240dbd22 508 bsState = gBSStateInit_c;
andreikovacs 0:4eb2240dbd22 509 connState = gConnBitrateSelectState_c;
andreikovacs 0:4eb2240dbd22 510 }
andreikovacs 0:4eb2240dbd22 511 #endif
andreikovacs 0:4eb2240dbd22 512 #if CT_Feature_Calibration
andreikovacs 0:4eb2240dbd22 513 else if('7' == gu8UartData)
andreikovacs 0:4eb2240dbd22 514 {
andreikovacs 0:4eb2240dbd22 515 connState = gConnEDMeasCalib_c;
andreikovacs 0:4eb2240dbd22 516 edCalState= gEdCalStateInit_c;
andreikovacs 0:4eb2240dbd22 517 }
andreikovacs 0:4eb2240dbd22 518 #endif
andreikovacs 0:4eb2240dbd22 519 else if('!' == gu8UartData)
andreikovacs 0:4eb2240dbd22 520 {
andreikovacs 0:4eb2240dbd22 521 ResetMCU();
andreikovacs 0:4eb2240dbd22 522 }
andreikovacs 0:4eb2240dbd22 523 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 524 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 525 }
andreikovacs 0:4eb2240dbd22 526 break;
andreikovacs 0:4eb2240dbd22 527 case gConnContinuousTxRxState_c:
andreikovacs 0:4eb2240dbd22 528 if(SerialContinuousTxRxTest())
andreikovacs 0:4eb2240dbd22 529 {
andreikovacs 0:4eb2240dbd22 530 connState = gConnIdleState_c;
andreikovacs 0:4eb2240dbd22 531 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 532 }
andreikovacs 0:4eb2240dbd22 533 break;
andreikovacs 0:4eb2240dbd22 534 case gConnPerState_c:
andreikovacs 0:4eb2240dbd22 535 if(mTxOperation_c == testOpMode)
andreikovacs 0:4eb2240dbd22 536 {
andreikovacs 0:4eb2240dbd22 537 if(PacketErrorRateTx())
andreikovacs 0:4eb2240dbd22 538 {
andreikovacs 0:4eb2240dbd22 539 connState = gConnIdleState_c;
andreikovacs 0:4eb2240dbd22 540 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 541 }
andreikovacs 0:4eb2240dbd22 542 }
andreikovacs 0:4eb2240dbd22 543 else
andreikovacs 0:4eb2240dbd22 544 {
andreikovacs 0:4eb2240dbd22 545 if(PacketErrorRateRx())
andreikovacs 0:4eb2240dbd22 546 {
andreikovacs 0:4eb2240dbd22 547 connState = gConnIdleState_c;
andreikovacs 0:4eb2240dbd22 548 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 549 }
andreikovacs 0:4eb2240dbd22 550 }
andreikovacs 0:4eb2240dbd22 551 break;
andreikovacs 0:4eb2240dbd22 552 case gConnRangeState_c:
andreikovacs 0:4eb2240dbd22 553 if(mTxOperation_c == testOpMode)
andreikovacs 0:4eb2240dbd22 554 {
andreikovacs 0:4eb2240dbd22 555 if(RangeTx())
andreikovacs 0:4eb2240dbd22 556 {
andreikovacs 0:4eb2240dbd22 557 connState = gConnIdleState_c;
andreikovacs 0:4eb2240dbd22 558 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 559 }
andreikovacs 0:4eb2240dbd22 560 }
andreikovacs 0:4eb2240dbd22 561 else
andreikovacs 0:4eb2240dbd22 562 {
andreikovacs 0:4eb2240dbd22 563 if(RangeRx())
andreikovacs 0:4eb2240dbd22 564 {
andreikovacs 0:4eb2240dbd22 565 connState = gConnIdleState_c;
andreikovacs 0:4eb2240dbd22 566 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 567 }
andreikovacs 0:4eb2240dbd22 568 }
andreikovacs 0:4eb2240dbd22 569 break;
andreikovacs 0:4eb2240dbd22 570 case gConnRegEditState_c:
andreikovacs 0:4eb2240dbd22 571 if(EditRegisters())
andreikovacs 0:4eb2240dbd22 572 {
andreikovacs 0:4eb2240dbd22 573 connState = gConnIdleState_c;
andreikovacs 0:4eb2240dbd22 574 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 575 }
andreikovacs 0:4eb2240dbd22 576 break;
andreikovacs 0:4eb2240dbd22 577 #if CT_Feature_Bitrate_Select
andreikovacs 0:4eb2240dbd22 578 case gConnBitrateSelectState_c:
andreikovacs 0:4eb2240dbd22 579 if(Bitrate_Select())
andreikovacs 0:4eb2240dbd22 580 {
andreikovacs 0:4eb2240dbd22 581 connState = gConnIdleState_c;
andreikovacs 0:4eb2240dbd22 582 }
andreikovacs 0:4eb2240dbd22 583 break;
andreikovacs 0:4eb2240dbd22 584 #endif
andreikovacs 0:4eb2240dbd22 585 case gConnCSenseAndTCtrl_c:
andreikovacs 0:4eb2240dbd22 586 if(CSenseAndTCtrl())
andreikovacs 0:4eb2240dbd22 587 {
andreikovacs 0:4eb2240dbd22 588 connState = gConnIdleState_c;
andreikovacs 0:4eb2240dbd22 589 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 590 }
andreikovacs 0:4eb2240dbd22 591 break;
andreikovacs 0:4eb2240dbd22 592 #if CT_Feature_Calibration
andreikovacs 0:4eb2240dbd22 593 case gConnEDMeasCalib_c:
andreikovacs 0:4eb2240dbd22 594 if(EDCalibrationMeasurement())
andreikovacs 0:4eb2240dbd22 595 {
andreikovacs 0:4eb2240dbd22 596 connState = gConnIdleState_c;
andreikovacs 0:4eb2240dbd22 597 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 598 }
andreikovacs 0:4eb2240dbd22 599 break;
andreikovacs 0:4eb2240dbd22 600 #endif
andreikovacs 0:4eb2240dbd22 601 default:
andreikovacs 0:4eb2240dbd22 602 break;
andreikovacs 0:4eb2240dbd22 603
andreikovacs 0:4eb2240dbd22 604 }
andreikovacs 0:4eb2240dbd22 605 if(prevOpMode != testOpMode)
andreikovacs 0:4eb2240dbd22 606 {
andreikovacs 0:4eb2240dbd22 607 perTxState = gPerTxStateInit_c;
andreikovacs 0:4eb2240dbd22 608 perRxState = gPerRxStateInit_c;
andreikovacs 0:4eb2240dbd22 609 rangeTxState = gRangeTxStateInit_c;
andreikovacs 0:4eb2240dbd22 610 rangeRxState = gRangeRxStateInit_c;
andreikovacs 0:4eb2240dbd22 611 prevOpMode = testOpMode;
andreikovacs 0:4eb2240dbd22 612 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 613 }
andreikovacs 0:4eb2240dbd22 614 }
andreikovacs 0:4eb2240dbd22 615
andreikovacs 0:4eb2240dbd22 616 /************************************************************************************
andreikovacs 0:4eb2240dbd22 617 *
andreikovacs 0:4eb2240dbd22 618 * Continuous Tests State Machine
andreikovacs 0:4eb2240dbd22 619 *
andreikovacs 0:4eb2240dbd22 620 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 621 bool_t SerialContinuousTxRxTest(void)
andreikovacs 0:4eb2240dbd22 622 {
andreikovacs 0:4eb2240dbd22 623 bool_t bBackFlag = FALSE;
andreikovacs 0:4eb2240dbd22 624 uint8_t u8Index, u8TempEnergyValue, u8TempScanValue;
andreikovacs 0:4eb2240dbd22 625
andreikovacs 0:4eb2240dbd22 626 if(evTestParameters)
andreikovacs 0:4eb2240dbd22 627 {
andreikovacs 0:4eb2240dbd22 628 (void)TestMode(gTestModeForceIdle_c);
andreikovacs 0:4eb2240dbd22 629 #if CT_Feature_Calibration
andreikovacs 0:4eb2240dbd22 630 (void)MLMESetAdditionalRFOffset(gOffsetIncrement);
andreikovacs 0:4eb2240dbd22 631 #endif
andreikovacs 0:4eb2240dbd22 632 (void)MLMESetChannelRequest(testChannel);
andreikovacs 0:4eb2240dbd22 633 (void)MLMEPAOutputAdjust(testPower);
andreikovacs 0:4eb2240dbd22 634
andreikovacs 0:4eb2240dbd22 635 if(gTestModePRBS9_c == contTestRunning)
andreikovacs 0:4eb2240dbd22 636 {
andreikovacs 0:4eb2240dbd22 637 cTxRxState = gCTxRxStateRunningPRBS9Test_c;
andreikovacs 0:4eb2240dbd22 638 }
andreikovacs 0:4eb2240dbd22 639 (void)TestMode(contTestRunning);
andreikovacs 0:4eb2240dbd22 640
andreikovacs 0:4eb2240dbd22 641 if(gCTxRxStateSelectTest_c == cTxRxState)
andreikovacs 0:4eb2240dbd22 642 {
andreikovacs 0:4eb2240dbd22 643 PrintTestParameters(TRUE);
andreikovacs 0:4eb2240dbd22 644 }
andreikovacs 0:4eb2240dbd22 645 else
andreikovacs 0:4eb2240dbd22 646 {
andreikovacs 0:4eb2240dbd22 647 PrintTestParameters(FALSE);
andreikovacs 0:4eb2240dbd22 648 uart.printf("\r\n");
andreikovacs 0:4eb2240dbd22 649 }
andreikovacs 0:4eb2240dbd22 650
andreikovacs 0:4eb2240dbd22 651 if(gCTxRxStateRunnigRxTest_c == cTxRxState)
andreikovacs 0:4eb2240dbd22 652 {
andreikovacs 0:4eb2240dbd22 653 bRxDone = FALSE;
andreikovacs 0:4eb2240dbd22 654 gAppRxPacket->u8MaxDataLength = gMaxSmacSDULength_c;
andreikovacs 0:4eb2240dbd22 655 (void)MLMERXEnableRequest(gAppRxPacket, 0);
andreikovacs 0:4eb2240dbd22 656 }
andreikovacs 0:4eb2240dbd22 657 evTestParameters = FALSE;
andreikovacs 0:4eb2240dbd22 658 }
andreikovacs 0:4eb2240dbd22 659
andreikovacs 0:4eb2240dbd22 660 switch(cTxRxState)
andreikovacs 0:4eb2240dbd22 661 {
andreikovacs 0:4eb2240dbd22 662 case gCTxRxStateIdle_c:
andreikovacs 0:4eb2240dbd22 663 if((evDataFromUART) && ('\r' == gu8UartData))
andreikovacs 0:4eb2240dbd22 664 {
andreikovacs 0:4eb2240dbd22 665 cTxRxState = gCTxRxStateInit_c;
andreikovacs 0:4eb2240dbd22 666 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 667 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 668 }
andreikovacs 0:4eb2240dbd22 669 break;
andreikovacs 0:4eb2240dbd22 670 case gCTxRxStateInit_c:
andreikovacs 0:4eb2240dbd22 671 PrintMenu(cu8ShortCutsBar, mAppSer);
andreikovacs 0:4eb2240dbd22 672 PrintMenu(cu8ContinuousTestMenu, mAppSer);
andreikovacs 0:4eb2240dbd22 673 //Phy in StandBy, smacstate in Idle.
andreikovacs 0:4eb2240dbd22 674 (void)TestMode(gTestModeForceIdle_c);
andreikovacs 0:4eb2240dbd22 675 while(MLMESetChannelRequest(testChannel));
andreikovacs 0:4eb2240dbd22 676 uart.printf(cu8ContinuousTestTags[contTestRunning]);
andreikovacs 0:4eb2240dbd22 677 if(contTestRunning == gTestModeContinuousTxModulated_c)
andreikovacs 0:4eb2240dbd22 678 {
andreikovacs 0:4eb2240dbd22 679 uart.printf(cu8TxModTestTags[contTxModBitValue]);
andreikovacs 0:4eb2240dbd22 680 }
andreikovacs 0:4eb2240dbd22 681 (void)TestMode(contTestRunning);
andreikovacs 0:4eb2240dbd22 682 uart.printf("\r\n\r\n");
andreikovacs 0:4eb2240dbd22 683 PrintTestParameters(FALSE);
andreikovacs 0:4eb2240dbd22 684 shortCutsEnabled = TRUE;
andreikovacs 0:4eb2240dbd22 685 cTxRxState = gCTxRxStateSelectTest_c;
andreikovacs 0:4eb2240dbd22 686 break;
andreikovacs 0:4eb2240dbd22 687 case gCTxRxStateSelectTest_c:
andreikovacs 0:4eb2240dbd22 688 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 689 {
andreikovacs 0:4eb2240dbd22 690 if('1' == gu8UartData)
andreikovacs 0:4eb2240dbd22 691 {
andreikovacs 0:4eb2240dbd22 692 contTestRunning = gTestModeForceIdle_c;
andreikovacs 0:4eb2240dbd22 693 cTxRxState = gCTxRxStateInit_c;
andreikovacs 0:4eb2240dbd22 694 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 695 }
andreikovacs 0:4eb2240dbd22 696 else if('2' == gu8UartData)
andreikovacs 0:4eb2240dbd22 697 {
andreikovacs 0:4eb2240dbd22 698 shortCutsEnabled = FALSE;
andreikovacs 0:4eb2240dbd22 699 (void)TestMode(gTestModeForceIdle_c);
andreikovacs 0:4eb2240dbd22 700 contTestRunning = gTestModePRBS9_c;
andreikovacs 0:4eb2240dbd22 701 MLMESetChannelRequest(testChannel);
andreikovacs 0:4eb2240dbd22 702 uart.printf("\f\r\nPress [p] to stop the Continuous PRBS9 test\r\n");
andreikovacs 0:4eb2240dbd22 703 (void)TestMode(contTestRunning);
andreikovacs 0:4eb2240dbd22 704 cTxRxState = gCTxRxStateRunningPRBS9Test_c;
andreikovacs 0:4eb2240dbd22 705 }
andreikovacs 0:4eb2240dbd22 706 else if('3' == gu8UartData)
andreikovacs 0:4eb2240dbd22 707 {
andreikovacs 0:4eb2240dbd22 708 contTestRunning = gTestModeContinuousTxModulated_c;
andreikovacs 0:4eb2240dbd22 709 cTxRxState = gCTxRxStateRunningTXModSelectOpt;
andreikovacs 0:4eb2240dbd22 710 // uart.printf( "\f\r\n To use this mode shunt pins 3-4 on J18");
andreikovacs 0:4eb2240dbd22 711 uart.printf("\f\r\nPress 2 for PN9, 1 to modulate values of 1 and 0 to modulate values of 0");
andreikovacs 0:4eb2240dbd22 712
andreikovacs 0:4eb2240dbd22 713 }
andreikovacs 0:4eb2240dbd22 714 else if('4' == gu8UartData)
andreikovacs 0:4eb2240dbd22 715 {
andreikovacs 0:4eb2240dbd22 716 if(gTestModeContinuousTxUnmodulated_c != contTestRunning)
andreikovacs 0:4eb2240dbd22 717 {
andreikovacs 0:4eb2240dbd22 718 contTestRunning = gTestModeContinuousTxUnmodulated_c;
andreikovacs 0:4eb2240dbd22 719 cTxRxState = gCTxRxStateInit_c;
andreikovacs 0:4eb2240dbd22 720 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 721 }
andreikovacs 0:4eb2240dbd22 722 }
andreikovacs 0:4eb2240dbd22 723 else if('5' == gu8UartData)
andreikovacs 0:4eb2240dbd22 724 {
andreikovacs 0:4eb2240dbd22 725 shortCutsEnabled = FALSE;
andreikovacs 0:4eb2240dbd22 726 (void)TestMode(gTestModeForceIdle_c);
andreikovacs 0:4eb2240dbd22 727 MLMESetChannelRequest(testChannel);
andreikovacs 0:4eb2240dbd22 728 contTestRunning = gTestModeForceIdle_c;
andreikovacs 0:4eb2240dbd22 729 uart.printf("\f\r\nPress [p] to stop receiving broadcast packets \r\n");
andreikovacs 0:4eb2240dbd22 730 bRxDone = FALSE;
andreikovacs 0:4eb2240dbd22 731 gAppRxPacket->u8MaxDataLength = gMaxSmacSDULength_c;
andreikovacs 0:4eb2240dbd22 732 (void)MLMERXEnableRequest(gAppRxPacket, 0);
andreikovacs 0:4eb2240dbd22 733 cTxRxState = gCTxRxStateRunnigRxTest_c;
andreikovacs 0:4eb2240dbd22 734 }
andreikovacs 0:4eb2240dbd22 735 else if('6' == gu8UartData)
andreikovacs 0:4eb2240dbd22 736 {
andreikovacs 0:4eb2240dbd22 737 (void)TestMode(gTestModeForceIdle_c);
andreikovacs 0:4eb2240dbd22 738 contTestRunning = gTestModeForceIdle_c;
andreikovacs 0:4eb2240dbd22 739 uart.printf("\f\r\nPress [p] to stop the Continuous ED test\r\n");
andreikovacs 0:4eb2240dbd22 740 cTxRxState = gCTxRxStateRunnigEdTest_c;
andreikovacs 0:4eb2240dbd22 741 Thread::wait(200);
andreikovacs 0:4eb2240dbd22 742 }
andreikovacs 0:4eb2240dbd22 743 else if('7' == gu8UartData)
andreikovacs 0:4eb2240dbd22 744 {
andreikovacs 0:4eb2240dbd22 745 (void)TestMode(gTestModeForceIdle_c);
andreikovacs 0:4eb2240dbd22 746 contTestRunning = gTestModeForceIdle_c;
andreikovacs 0:4eb2240dbd22 747 ChannelToScan= gDefaultChannelNumber_c;
andreikovacs 0:4eb2240dbd22 748 uart.printf("\f\r\nPress [p] to stop the Continuous SCAN test\r\n");
andreikovacs 0:4eb2240dbd22 749 bScanDone = FALSE;
andreikovacs 0:4eb2240dbd22 750 cTxRxState = gCTxRxStateRunnigScanTest_c;
andreikovacs 0:4eb2240dbd22 751 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 752 }
andreikovacs 0:4eb2240dbd22 753 else if('8' == gu8UartData)
andreikovacs 0:4eb2240dbd22 754 {
andreikovacs 0:4eb2240dbd22 755 (void)TestMode(gTestModeForceIdle_c);
andreikovacs 0:4eb2240dbd22 756 uart.printf("\f\r\nPress [p] to stop the Continuous CCA test\r\n");
andreikovacs 0:4eb2240dbd22 757 contTestRunning = gTestModeForceIdle_c;
andreikovacs 0:4eb2240dbd22 758 cTxRxState = gCTxRxStateRunnigCcaTest_c;
andreikovacs 0:4eb2240dbd22 759 Thread::wait(100);
andreikovacs 0:4eb2240dbd22 760 MLMECcaRequest();
andreikovacs 0:4eb2240dbd22 761 }
andreikovacs 0:4eb2240dbd22 762 #if CT_Feature_BER_Test
andreikovacs 0:4eb2240dbd22 763 else if ('9' == gu8UartData)
andreikovacs 0:4eb2240dbd22 764 {
andreikovacs 0:4eb2240dbd22 765 uart.printf( "\f\r\nPress [p] to stop the Continuous BER test\r\n");
andreikovacs 0:4eb2240dbd22 766 contTestRunning = gTestModeContinuousRxBER_c;
andreikovacs 0:4eb2240dbd22 767 cTxRxState = gCTxRxStateInit_c;
andreikovacs 0:4eb2240dbd22 768 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 769 }
andreikovacs 0:4eb2240dbd22 770 #endif
andreikovacs 0:4eb2240dbd22 771 else if('p' == gu8UartData)
andreikovacs 0:4eb2240dbd22 772 {
andreikovacs 0:4eb2240dbd22 773 (void)TestMode(gTestModeForceIdle_c);
andreikovacs 0:4eb2240dbd22 774 (void)MLMESetChannelRequest(testChannel);
andreikovacs 0:4eb2240dbd22 775 AppDelayTmr.stop();
andreikovacs 0:4eb2240dbd22 776 timePassed = FALSE;
andreikovacs 0:4eb2240dbd22 777 bBackFlag = TRUE;
andreikovacs 0:4eb2240dbd22 778 }
andreikovacs 0:4eb2240dbd22 779 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 780 }
andreikovacs 0:4eb2240dbd22 781 break;
andreikovacs 0:4eb2240dbd22 782 case gCTxRxStateRunningTXModSelectOpt:
andreikovacs 0:4eb2240dbd22 783 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 784 {
andreikovacs 0:4eb2240dbd22 785 if(gu8UartData == '2')
andreikovacs 0:4eb2240dbd22 786 contTxModBitValue = gContTxModSelectPN9_c;
andreikovacs 0:4eb2240dbd22 787 else
andreikovacs 0:4eb2240dbd22 788 if(gu8UartData == '1')
andreikovacs 0:4eb2240dbd22 789 contTxModBitValue = gContTxModSelectOnes_c;
andreikovacs 0:4eb2240dbd22 790 else
andreikovacs 0:4eb2240dbd22 791 if(gu8UartData == '0')
andreikovacs 0:4eb2240dbd22 792 contTxModBitValue = gContTxModSelectZeros_c;
andreikovacs 0:4eb2240dbd22 793
andreikovacs 0:4eb2240dbd22 794 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 795 cTxRxState = gCTxRxStateInit_c;
andreikovacs 0:4eb2240dbd22 796 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 797 }
andreikovacs 0:4eb2240dbd22 798 break;
andreikovacs 0:4eb2240dbd22 799 case gCTxRxStateRunningPRBS9Test_c:
andreikovacs 0:4eb2240dbd22 800 if(bTxDone || failedPRBS9)
andreikovacs 0:4eb2240dbd22 801 {
andreikovacs 0:4eb2240dbd22 802 failedPRBS9 = FALSE;
andreikovacs 0:4eb2240dbd22 803 bTxDone = FALSE;
andreikovacs 0:4eb2240dbd22 804 PacketHandler_Prbs9();
andreikovacs 0:4eb2240dbd22 805 }
andreikovacs 0:4eb2240dbd22 806 if(evDataFromUART && 'p' == gu8UartData)
andreikovacs 0:4eb2240dbd22 807 {
andreikovacs 0:4eb2240dbd22 808 contTestRunning = gTestModeForceIdle_c;
andreikovacs 0:4eb2240dbd22 809 (void)TestMode(gTestModeForceIdle_c);
andreikovacs 0:4eb2240dbd22 810 (void)MLMESetChannelRequest(testChannel);
andreikovacs 0:4eb2240dbd22 811 AppDelayTmr.stop();
andreikovacs 0:4eb2240dbd22 812 timePassed = FALSE;
andreikovacs 0:4eb2240dbd22 813 uart.printf("\r\n\r\n Press [enter] to go back to the Continuous test menu ");
andreikovacs 0:4eb2240dbd22 814 cTxRxState = gCTxRxStateIdle_c;
andreikovacs 0:4eb2240dbd22 815 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 816 shortCutsEnabled = TRUE;
andreikovacs 0:4eb2240dbd22 817 }
andreikovacs 0:4eb2240dbd22 818 break;
andreikovacs 0:4eb2240dbd22 819 case gCTxRxStateRunnigRxTest_c:
andreikovacs 0:4eb2240dbd22 820 if(bRxDone)
andreikovacs 0:4eb2240dbd22 821 {
andreikovacs 0:4eb2240dbd22 822 if (gAppRxPacket->rxStatus == rxSuccessStatus_c)
andreikovacs 0:4eb2240dbd22 823 {
andreikovacs 0:4eb2240dbd22 824 uart.printf("New Packet: ");
andreikovacs 0:4eb2240dbd22 825 for(u8Index = 0; u8Index < (gAppRxPacket->u8DataLength); u8Index++){
andreikovacs 0:4eb2240dbd22 826 uart.printf( (const char *)(&(gAppRxPacket->smacPdu.smacPdu[u8Index])));
andreikovacs 0:4eb2240dbd22 827 }
andreikovacs 0:4eb2240dbd22 828 uart.printf(" \r\n");
andreikovacs 0:4eb2240dbd22 829 }
andreikovacs 0:4eb2240dbd22 830 bRxDone = FALSE;
andreikovacs 0:4eb2240dbd22 831 gAppRxPacket->u8MaxDataLength = gMaxSmacSDULength_c;
andreikovacs 0:4eb2240dbd22 832 (void)MLMERXEnableRequest(gAppRxPacket, 0);
andreikovacs 0:4eb2240dbd22 833 }
andreikovacs 0:4eb2240dbd22 834 if((evDataFromUART) && ('p' == gu8UartData))
andreikovacs 0:4eb2240dbd22 835 {
andreikovacs 0:4eb2240dbd22 836 (void)MLMERXDisableRequest();
andreikovacs 0:4eb2240dbd22 837 (void)TestMode(gTestModeForceIdle_c);
andreikovacs 0:4eb2240dbd22 838 uart.printf("\r\n\r\n Press [enter] to go back to the Continuous test menu ");
andreikovacs 0:4eb2240dbd22 839 cTxRxState = gCTxRxStateIdle_c;
andreikovacs 0:4eb2240dbd22 840 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 841 }
andreikovacs 0:4eb2240dbd22 842 break;
andreikovacs 0:4eb2240dbd22 843 case gCTxRxStateRunnigEdTest_c:
andreikovacs 0:4eb2240dbd22 844 if(timePassed)
andreikovacs 0:4eb2240dbd22 845 {
andreikovacs 0:4eb2240dbd22 846 timePassed = FALSE;
andreikovacs 0:4eb2240dbd22 847 Thread::wait(100);
andreikovacs 0:4eb2240dbd22 848 MLMEScanRequest(testChannel);
andreikovacs 0:4eb2240dbd22 849 }
andreikovacs 0:4eb2240dbd22 850 if((evDataFromUART) && ('p' == gu8UartData))
andreikovacs 0:4eb2240dbd22 851 {
andreikovacs 0:4eb2240dbd22 852 uart.printf("\r\n\r\n Press [enter] to go back to the Continuous test menu ");
andreikovacs 0:4eb2240dbd22 853 cTxRxState = gCTxRxStateIdle_c;
andreikovacs 0:4eb2240dbd22 854 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 855 timePassed = FALSE;
andreikovacs 0:4eb2240dbd22 856 AppDelayTmr.stop();
andreikovacs 0:4eb2240dbd22 857 }
andreikovacs 0:4eb2240dbd22 858
andreikovacs 0:4eb2240dbd22 859 break;
andreikovacs 0:4eb2240dbd22 860 case gCTxRxStateRunningEdTestGotResult_c:
andreikovacs 0:4eb2240dbd22 861 uart.printf("Energy on the Channel %d : ", (uint32_t)testChannel);
andreikovacs 0:4eb2240dbd22 862 u8TempEnergyValue = au8ScanResults[testChannel];
andreikovacs 0:4eb2240dbd22 863 if(u8TempEnergyValue != 0)
andreikovacs 0:4eb2240dbd22 864 uart.printf( "-");
andreikovacs 0:4eb2240dbd22 865 uart.printf("%d dBm\r\n ",(uint32_t)u8TempEnergyValue);
andreikovacs 0:4eb2240dbd22 866 cTxRxState = gCTxRxStateRunnigEdTest_c;
andreikovacs 0:4eb2240dbd22 867 break;
andreikovacs 0:4eb2240dbd22 868 case gCTxRxStateRunnigCcaTest_c:
andreikovacs 0:4eb2240dbd22 869 if(timePassed && gCCaGotResult)
andreikovacs 0:4eb2240dbd22 870 {
andreikovacs 0:4eb2240dbd22 871 gCCaGotResult = FALSE;
andreikovacs 0:4eb2240dbd22 872 timePassed = FALSE;
andreikovacs 0:4eb2240dbd22 873 MLMECcaRequest();
andreikovacs 0:4eb2240dbd22 874 Thread::wait(100);
andreikovacs 0:4eb2240dbd22 875 }
andreikovacs 0:4eb2240dbd22 876 if((evDataFromUART) && ('p' == gu8UartData))
andreikovacs 0:4eb2240dbd22 877 {
andreikovacs 0:4eb2240dbd22 878 uart.printf("\r\n\r\n Press [enter] to go back to the Continuous test menu ");
andreikovacs 0:4eb2240dbd22 879 cTxRxState = gCTxRxStateIdle_c;
andreikovacs 0:4eb2240dbd22 880 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 881 timePassed = FALSE;
andreikovacs 0:4eb2240dbd22 882 AppDelayTmr.stop();
andreikovacs 0:4eb2240dbd22 883 }
andreikovacs 0:4eb2240dbd22 884 break;
andreikovacs 0:4eb2240dbd22 885 case gCTxRxStateRunnigScanTest_c:
andreikovacs 0:4eb2240dbd22 886 if(bScanDone && timePassed)
andreikovacs 0:4eb2240dbd22 887 {
andreikovacs 0:4eb2240dbd22 888 //Enters here until all channels have been scanned. Then starts to print.
andreikovacs 0:4eb2240dbd22 889 uart.printf("Results : ");
andreikovacs 0:4eb2240dbd22 890 for(u8Index = gMinChannel_c; u8Index <= gMaxChannel_c ; u8Index++)
andreikovacs 0:4eb2240dbd22 891 {
andreikovacs 0:4eb2240dbd22 892 u8TempScanValue= au8ScanResults[u8Index];
andreikovacs 0:4eb2240dbd22 893 if(u8TempScanValue != 0)
andreikovacs 0:4eb2240dbd22 894 uart.printf("-");
andreikovacs 0:4eb2240dbd22 895 uart.printf("%d, ", (uint32_t) u8TempScanValue);
andreikovacs 0:4eb2240dbd22 896 }
andreikovacs 0:4eb2240dbd22 897 uart.printf("\b \r\n");
andreikovacs 0:4eb2240dbd22 898 bScanDone = FALSE;
andreikovacs 0:4eb2240dbd22 899 ChannelToScan = gDefaultChannelNumber_c; // Restart channel count
andreikovacs 0:4eb2240dbd22 900 timePassed = FALSE;
andreikovacs 0:4eb2240dbd22 901 }
andreikovacs 0:4eb2240dbd22 902
andreikovacs 0:4eb2240dbd22 903 if((evDataFromUART) && ('p' == gu8UartData))
andreikovacs 0:4eb2240dbd22 904 {
andreikovacs 0:4eb2240dbd22 905 uart.printf("\r\n\r\n Press [enter] to go back to the Continuous test menu ");
andreikovacs 0:4eb2240dbd22 906 cTxRxState = gCTxRxStateIdle_c;
andreikovacs 0:4eb2240dbd22 907 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 908 }
andreikovacs 0:4eb2240dbd22 909 else
andreikovacs 0:4eb2240dbd22 910 {
andreikovacs 0:4eb2240dbd22 911 if(ChannelToScan == gDefaultChannelNumber_c)
andreikovacs 0:4eb2240dbd22 912 {
andreikovacs 0:4eb2240dbd22 913 smacErrors_t err = MLMEScanRequest((channels_t)ChannelToScan);
andreikovacs 0:4eb2240dbd22 914 if(err == gErrorNoError_c)
andreikovacs 0:4eb2240dbd22 915 ChannelToScan++;
andreikovacs 0:4eb2240dbd22 916 }
andreikovacs 0:4eb2240dbd22 917 //Each of the other channels is scanned after SMAC notifies us that
andreikovacs 0:4eb2240dbd22 918 //it has obtained the energy value on the currently scanned channel
andreikovacs 0:4eb2240dbd22 919 //(channel scanning is performed asynchronously). See IncrementChannelOnEdEvent().
andreikovacs 0:4eb2240dbd22 920 }
andreikovacs 0:4eb2240dbd22 921 break;
andreikovacs 0:4eb2240dbd22 922 default:
andreikovacs 0:4eb2240dbd22 923 break;
andreikovacs 0:4eb2240dbd22 924 }
andreikovacs 0:4eb2240dbd22 925 return bBackFlag;
andreikovacs 0:4eb2240dbd22 926 }
andreikovacs 0:4eb2240dbd22 927
andreikovacs 0:4eb2240dbd22 928 /************************************************************************************
andreikovacs 0:4eb2240dbd22 929 *
andreikovacs 0:4eb2240dbd22 930 * PER Handler for board that is performing TX
andreikovacs 0:4eb2240dbd22 931 *
andreikovacs 0:4eb2240dbd22 932 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 933 bool_t PacketErrorRateTx(void)
andreikovacs 0:4eb2240dbd22 934 {
andreikovacs 0:4eb2240dbd22 935 const uint16_t u16TotalPacketsOptions[] = {1,25,100,500,1000,2000,5000,10000,65535};
andreikovacs 0:4eb2240dbd22 936 static uint16_t u16TotalPackets;
andreikovacs 0:4eb2240dbd22 937 static uint16_t u16SentPackets;
andreikovacs 0:4eb2240dbd22 938 static uint32_t miliSecDelay;
andreikovacs 0:4eb2240dbd22 939 static uint32_t u32MinDelay = 4;
andreikovacs 0:4eb2240dbd22 940 uint8_t u8Index;
andreikovacs 0:4eb2240dbd22 941 bool_t bBackFlag = FALSE;
andreikovacs 0:4eb2240dbd22 942
andreikovacs 0:4eb2240dbd22 943 if(evTestParameters)
andreikovacs 0:4eb2240dbd22 944 {
andreikovacs 0:4eb2240dbd22 945 (void)MLMERXDisableRequest();
andreikovacs 0:4eb2240dbd22 946 #if CT_Feature_Calibration
andreikovacs 0:4eb2240dbd22 947 (void)MLMESetAdditionalRFOffset(gOffsetIncrement);
andreikovacs 0:4eb2240dbd22 948 #endif
andreikovacs 0:4eb2240dbd22 949 (void)MLMESetChannelRequest(testChannel);
andreikovacs 0:4eb2240dbd22 950 (void)MLMEPAOutputAdjust(testPower);
andreikovacs 0:4eb2240dbd22 951 PrintTestParameters(TRUE);
andreikovacs 0:4eb2240dbd22 952 evTestParameters = FALSE;
andreikovacs 0:4eb2240dbd22 953 }
andreikovacs 0:4eb2240dbd22 954
andreikovacs 0:4eb2240dbd22 955 switch(perTxState)
andreikovacs 0:4eb2240dbd22 956 {
andreikovacs 0:4eb2240dbd22 957 case gPerTxStateInit_c:
andreikovacs 0:4eb2240dbd22 958 PrintMenu(cu8ShortCutsBar, mAppSer);
andreikovacs 0:4eb2240dbd22 959 PrintMenu(cu8PerTxTestMenu, mAppSer);
andreikovacs 0:4eb2240dbd22 960 PrintTestParameters(FALSE);
andreikovacs 0:4eb2240dbd22 961 shortCutsEnabled = TRUE;
andreikovacs 0:4eb2240dbd22 962 perTxState = gPerTxStateSelectPacketNum_c;
andreikovacs 0:4eb2240dbd22 963 miliSecDelay = 0;
andreikovacs 0:4eb2240dbd22 964 u32MinDelay = 4;
andreikovacs 0:4eb2240dbd22 965 (void)MLMERXDisableRequest();
andreikovacs 0:4eb2240dbd22 966 break;
andreikovacs 0:4eb2240dbd22 967 case gPerTxStateSelectPacketNum_c:
andreikovacs 0:4eb2240dbd22 968 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 969 {
andreikovacs 0:4eb2240dbd22 970 if((gu8UartData >= '0') && (gu8UartData <= '8'))
andreikovacs 0:4eb2240dbd22 971 {
andreikovacs 0:4eb2240dbd22 972 u16TotalPackets = u16TotalPacketsOptions[gu8UartData - '0'];
andreikovacs 0:4eb2240dbd22 973 shortCutsEnabled = FALSE;
andreikovacs 0:4eb2240dbd22 974 u32MinDelay += (GetTransmissionTime(testPayloadLen, crtBitrate) / 1000);
andreikovacs 0:4eb2240dbd22 975 uart.printf("\r\n\r\n Please type TX interval in miliseconds ( > %d ms ) and press [ENTER]\r\n", u32MinDelay);
andreikovacs 0:4eb2240dbd22 976 perTxState = gPerTxStateInputPacketDelay_c;
andreikovacs 0:4eb2240dbd22 977 }
andreikovacs 0:4eb2240dbd22 978 else if('p' == gu8UartData)
andreikovacs 0:4eb2240dbd22 979 {
andreikovacs 0:4eb2240dbd22 980 bBackFlag = TRUE;
andreikovacs 0:4eb2240dbd22 981 }
andreikovacs 0:4eb2240dbd22 982 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 983 }
andreikovacs 0:4eb2240dbd22 984 break;
andreikovacs 0:4eb2240dbd22 985 case gPerTxStateInputPacketDelay_c:
andreikovacs 0:4eb2240dbd22 986 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 987 {
andreikovacs 0:4eb2240dbd22 988 if(gu8UartData == '\r')
andreikovacs 0:4eb2240dbd22 989 {
andreikovacs 0:4eb2240dbd22 990 if(miliSecDelay < u32MinDelay)
andreikovacs 0:4eb2240dbd22 991 {
andreikovacs 0:4eb2240dbd22 992 uart.printf("\r\n\tError: TX Interval too small\r\n");
andreikovacs 0:4eb2240dbd22 993 perTxState = gPerTxStateInit_c;
andreikovacs 0:4eb2240dbd22 994 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 995 }
andreikovacs 0:4eb2240dbd22 996 else
andreikovacs 0:4eb2240dbd22 997 {
andreikovacs 0:4eb2240dbd22 998 perTxState = gPerTxStateStartTest_c;
andreikovacs 0:4eb2240dbd22 999 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1000 }
andreikovacs 0:4eb2240dbd22 1001 }
andreikovacs 0:4eb2240dbd22 1002 else if((gu8UartData >= '0') && (gu8UartData <='9'))
andreikovacs 0:4eb2240dbd22 1003 {
andreikovacs 0:4eb2240dbd22 1004 miliSecDelay = miliSecDelay*10 + (gu8UartData - '0');
andreikovacs 0:4eb2240dbd22 1005 uart.printf("%d", (uint32_t)(gu8UartData - '0'));
andreikovacs 0:4eb2240dbd22 1006 }
andreikovacs 0:4eb2240dbd22 1007 else if('p' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1008 {
andreikovacs 0:4eb2240dbd22 1009 perTxState = gPerTxStateInit_c;
andreikovacs 0:4eb2240dbd22 1010 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1011 }
andreikovacs 0:4eb2240dbd22 1012 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1013 }
andreikovacs 0:4eb2240dbd22 1014 break;
andreikovacs 0:4eb2240dbd22 1015 case gPerTxStateStartTest_c:
andreikovacs 0:4eb2240dbd22 1016 gAppTxPacket->u8DataLength = testPayloadLen;
andreikovacs 0:4eb2240dbd22 1017 u16SentPackets = 0;
andreikovacs 0:4eb2240dbd22 1018
andreikovacs 0:4eb2240dbd22 1019 gAppTxPacket->smacPdu.smacPdu[0] = (u16TotalPackets >> 8);
andreikovacs 0:4eb2240dbd22 1020 gAppTxPacket->smacPdu.smacPdu[1] = (uint8_t)u16TotalPackets;
andreikovacs 0:4eb2240dbd22 1021 gAppTxPacket->smacPdu.smacPdu[2] = ((u16SentPackets+1) >> 8);
andreikovacs 0:4eb2240dbd22 1022 gAppTxPacket->smacPdu.smacPdu[3] = (uint8_t)(u16SentPackets+1);
andreikovacs 0:4eb2240dbd22 1023 FLib_MemCpy(&(gAppTxPacket->smacPdu.smacPdu[4]), (void*)"SMAC PER Demo",13);
andreikovacs 0:4eb2240dbd22 1024 if(17 < testPayloadLen)
andreikovacs 0:4eb2240dbd22 1025 {
andreikovacs 0:4eb2240dbd22 1026 for(u8Index=17;u8Index<testPayloadLen;u8Index++)
andreikovacs 0:4eb2240dbd22 1027 {
andreikovacs 0:4eb2240dbd22 1028 gAppTxPacket->smacPdu.smacPdu[u8Index] = (u8Index%10)+'0';
andreikovacs 0:4eb2240dbd22 1029 }
andreikovacs 0:4eb2240dbd22 1030 }
andreikovacs 0:4eb2240dbd22 1031 bTxDone = FALSE;
andreikovacs 0:4eb2240dbd22 1032 (void)MCPSDataRequest(gAppTxPacket);
andreikovacs 0:4eb2240dbd22 1033 u16SentPackets++;
andreikovacs 0:4eb2240dbd22 1034 uart.printf("\f\r\n Running PER Tx, Sending %d Packets",(uint32_t)u16TotalPackets);
andreikovacs 0:4eb2240dbd22 1035 perTxState = gPerTxStateRunningTest_c;
andreikovacs 0:4eb2240dbd22 1036 Thread::wait(miliSecDelay);
andreikovacs 0:4eb2240dbd22 1037 break;
andreikovacs 0:4eb2240dbd22 1038 case gPerTxStateRunningTest_c:
andreikovacs 0:4eb2240dbd22 1039 if(bTxDone && timePassed)
andreikovacs 0:4eb2240dbd22 1040 {
andreikovacs 0:4eb2240dbd22 1041 uart.printf("\r\n Packet %d ",(uint32_t)u16SentPackets);
andreikovacs 0:4eb2240dbd22 1042 if(u16SentPackets == u16TotalPackets)
andreikovacs 0:4eb2240dbd22 1043 {
andreikovacs 0:4eb2240dbd22 1044 uart.printf("\r\n\r\nSending last %d frames \r\n",(uint32_t)mTotalFinalFrames_c);
andreikovacs 0:4eb2240dbd22 1045 FLib_MemCpy(&(gAppTxPacket->smacPdu.smacPdu[4]), (void *)"DONE",4);
andreikovacs 0:4eb2240dbd22 1046 gAppTxPacket->u8DataLength = 8;
andreikovacs 0:4eb2240dbd22 1047 u16SentPackets = 0;
andreikovacs 0:4eb2240dbd22 1048 u16TotalPackets = mTotalFinalFrames_c;
andreikovacs 0:4eb2240dbd22 1049 gAppTxPacket->u8DataLength = 8;
andreikovacs 0:4eb2240dbd22 1050 perTxState = gPerTxStateSendingLastFrames_c;
andreikovacs 0:4eb2240dbd22 1051 }
andreikovacs 0:4eb2240dbd22 1052 else
andreikovacs 0:4eb2240dbd22 1053 {
andreikovacs 0:4eb2240dbd22 1054 gAppTxPacket->smacPdu.smacPdu[2] = ((u16SentPackets+1) >> 8);
andreikovacs 0:4eb2240dbd22 1055 gAppTxPacket->smacPdu.smacPdu[3] = (uint8_t)(u16SentPackets+1);
andreikovacs 0:4eb2240dbd22 1056 gAppTxPacket->u8DataLength = testPayloadLen;
andreikovacs 0:4eb2240dbd22 1057 }
andreikovacs 0:4eb2240dbd22 1058 bTxDone = FALSE;
andreikovacs 0:4eb2240dbd22 1059 (void)MCPSDataRequest(gAppTxPacket);
andreikovacs 0:4eb2240dbd22 1060 u16SentPackets++;
andreikovacs 0:4eb2240dbd22 1061 timePassed = FALSE;
andreikovacs 0:4eb2240dbd22 1062 Thread::wait(miliSecDelay);
andreikovacs 0:4eb2240dbd22 1063 }
andreikovacs 0:4eb2240dbd22 1064 if(evDataFromUART && gu8UartData == ' ')
andreikovacs 0:4eb2240dbd22 1065 {
andreikovacs 0:4eb2240dbd22 1066 uart.printf("\r\n\r\n-Test interrupted by user. Press [ENTER] to continue\r\n\r\n");
andreikovacs 0:4eb2240dbd22 1067 perTxState = gPerTxStateIdle_c;
andreikovacs 0:4eb2240dbd22 1068 }
andreikovacs 0:4eb2240dbd22 1069 break;
andreikovacs 0:4eb2240dbd22 1070 case gPerTxStateSendingLastFrames_c:
andreikovacs 0:4eb2240dbd22 1071 if(bTxDone && timePassed)
andreikovacs 0:4eb2240dbd22 1072 {
andreikovacs 0:4eb2240dbd22 1073 bTxDone = FALSE;
andreikovacs 0:4eb2240dbd22 1074 timePassed = FALSE;
andreikovacs 0:4eb2240dbd22 1075 uart.printf("\r\n Final Packet %d",(uint32_t)u16SentPackets);
andreikovacs 0:4eb2240dbd22 1076 if(u16SentPackets == u16TotalPackets)
andreikovacs 0:4eb2240dbd22 1077 {
andreikovacs 0:4eb2240dbd22 1078 uart.printf( "\r\n PER Tx DONE \r\n");
andreikovacs 0:4eb2240dbd22 1079 uart.printf( "\r\n\r\n Press [enter] to go back to the PER Tx test menu ");
andreikovacs 0:4eb2240dbd22 1080 perTxState = gPerTxStateIdle_c;
andreikovacs 0:4eb2240dbd22 1081 AppDelayTmr.stop();
andreikovacs 0:4eb2240dbd22 1082 timePassed = FALSE;
andreikovacs 0:4eb2240dbd22 1083 }
andreikovacs 0:4eb2240dbd22 1084 else
andreikovacs 0:4eb2240dbd22 1085 {
andreikovacs 0:4eb2240dbd22 1086 gAppTxPacket->u8DataLength = 8;
andreikovacs 0:4eb2240dbd22 1087 (void)MCPSDataRequest(gAppTxPacket);
andreikovacs 0:4eb2240dbd22 1088 u16SentPackets++;
andreikovacs 0:4eb2240dbd22 1089 Thread::wait(miliSecDelay);
andreikovacs 0:4eb2240dbd22 1090 }
andreikovacs 0:4eb2240dbd22 1091 }
andreikovacs 0:4eb2240dbd22 1092 if(evDataFromUART && gu8UartData == ' ')
andreikovacs 0:4eb2240dbd22 1093 {
andreikovacs 0:4eb2240dbd22 1094 uart.printf("\r\n\r\n-Test interrupted by user. Press [ENTER] to continue\r\n\r\n");
andreikovacs 0:4eb2240dbd22 1095 perTxState = gPerTxStateIdle_c;
andreikovacs 0:4eb2240dbd22 1096 }
andreikovacs 0:4eb2240dbd22 1097 break;
andreikovacs 0:4eb2240dbd22 1098 case gPerTxStateIdle_c:
andreikovacs 0:4eb2240dbd22 1099 if((evDataFromUART) && ('\r' == gu8UartData))
andreikovacs 0:4eb2240dbd22 1100 {
andreikovacs 0:4eb2240dbd22 1101 perTxState = gPerTxStateInit_c;
andreikovacs 0:4eb2240dbd22 1102 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1103 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1104 }
andreikovacs 0:4eb2240dbd22 1105 break;
andreikovacs 0:4eb2240dbd22 1106 default:
andreikovacs 0:4eb2240dbd22 1107 break;
andreikovacs 0:4eb2240dbd22 1108 }
andreikovacs 0:4eb2240dbd22 1109
andreikovacs 0:4eb2240dbd22 1110 return bBackFlag;
andreikovacs 0:4eb2240dbd22 1111 }
andreikovacs 0:4eb2240dbd22 1112
andreikovacs 0:4eb2240dbd22 1113 /************************************************************************************
andreikovacs 0:4eb2240dbd22 1114 *
andreikovacs 0:4eb2240dbd22 1115 * PER Handler for board that is performing RX
andreikovacs 0:4eb2240dbd22 1116 *
andreikovacs 0:4eb2240dbd22 1117 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 1118 bool_t PacketErrorRateRx(void)
andreikovacs 0:4eb2240dbd22 1119 {
andreikovacs 0:4eb2240dbd22 1120 static uint16_t u16ReceivedPackets;
andreikovacs 0:4eb2240dbd22 1121 static uint16_t u16PacketsIndex;
andreikovacs 0:4eb2240dbd22 1122 static uint16_t u16TotalPackets;
andreikovacs 0:4eb2240dbd22 1123 static uint16_t u16FinalPacketsCount;
andreikovacs 0:4eb2240dbd22 1124 static uint32_t u32RssiSum;
andreikovacs 0:4eb2240dbd22 1125 static uint8_t u8AverageRssi;
andreikovacs 0:4eb2240dbd22 1126 uint8_t u8TempRssivalue;
andreikovacs 0:4eb2240dbd22 1127
andreikovacs 0:4eb2240dbd22 1128 bool_t bBackFlag = FALSE;
andreikovacs 0:4eb2240dbd22 1129 if(evTestParameters)
andreikovacs 0:4eb2240dbd22 1130 {
andreikovacs 0:4eb2240dbd22 1131 #if CT_Feature_Calibration
andreikovacs 0:4eb2240dbd22 1132 (void)MLMESetAdditionalRFOffset(gOffsetIncrement);
andreikovacs 0:4eb2240dbd22 1133 #endif
andreikovacs 0:4eb2240dbd22 1134 (void)MLMESetChannelRequest(testChannel);
andreikovacs 0:4eb2240dbd22 1135 (void)MLMEPAOutputAdjust(testPower);
andreikovacs 0:4eb2240dbd22 1136 PrintTestParameters(TRUE);
andreikovacs 0:4eb2240dbd22 1137 evTestParameters = FALSE;
andreikovacs 0:4eb2240dbd22 1138 }
andreikovacs 0:4eb2240dbd22 1139 switch(perRxState)
andreikovacs 0:4eb2240dbd22 1140 {
andreikovacs 0:4eb2240dbd22 1141 case gPerRxStateInit_c:
andreikovacs 0:4eb2240dbd22 1142 u16TotalPackets = 0;
andreikovacs 0:4eb2240dbd22 1143 u16ReceivedPackets = 0;
andreikovacs 0:4eb2240dbd22 1144 u16PacketsIndex = 0;
andreikovacs 0:4eb2240dbd22 1145 u32RssiSum = 0;
andreikovacs 0:4eb2240dbd22 1146 PrintMenu(cu8ShortCutsBar, mAppSer);
andreikovacs 0:4eb2240dbd22 1147 PrintMenu(cu8PerRxTestMenu, mAppSer);
andreikovacs 0:4eb2240dbd22 1148 PrintTestParameters(FALSE);
andreikovacs 0:4eb2240dbd22 1149 shortCutsEnabled = TRUE;
andreikovacs 0:4eb2240dbd22 1150 perRxState = gPerRxWaitStartTest_c;
andreikovacs 0:4eb2240dbd22 1151 break;
andreikovacs 0:4eb2240dbd22 1152 case gPerRxWaitStartTest_c:
andreikovacs 0:4eb2240dbd22 1153 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 1154 {
andreikovacs 0:4eb2240dbd22 1155 if(' ' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1156 {
andreikovacs 0:4eb2240dbd22 1157 uart.printf("\f\n\rPER Test Rx Running\r\n\r\n");
andreikovacs 0:4eb2240dbd22 1158 SetRadioRxOnNoTimeOut();
andreikovacs 0:4eb2240dbd22 1159 shortCutsEnabled = FALSE;
andreikovacs 0:4eb2240dbd22 1160 perRxState = gPerRxStateStartTest_c;
andreikovacs 0:4eb2240dbd22 1161 }
andreikovacs 0:4eb2240dbd22 1162 else if('p' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1163 {
andreikovacs 0:4eb2240dbd22 1164 bBackFlag = TRUE;
andreikovacs 0:4eb2240dbd22 1165 }
andreikovacs 0:4eb2240dbd22 1166 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1167 }
andreikovacs 0:4eb2240dbd22 1168 break;
andreikovacs 0:4eb2240dbd22 1169 case gPerRxStateStartTest_c:
andreikovacs 0:4eb2240dbd22 1170 if(bRxDone)
andreikovacs 0:4eb2240dbd22 1171 {
andreikovacs 0:4eb2240dbd22 1172 if (gAppRxPacket->rxStatus == rxSuccessStatus_c)
andreikovacs 0:4eb2240dbd22 1173 {
andreikovacs 0:4eb2240dbd22 1174 if(stringComp((uint8_t*)"SMAC PER Demo",&gAppRxPacket->smacPdu.smacPdu[4],13))
andreikovacs 0:4eb2240dbd22 1175 {
andreikovacs 0:4eb2240dbd22 1176 u16TotalPackets = ((uint16_t)gAppRxPacket->smacPdu.smacPdu[0] <<8) + gAppRxPacket->smacPdu.smacPdu[1];
andreikovacs 0:4eb2240dbd22 1177 u16PacketsIndex = ((uint16_t)gAppRxPacket->smacPdu.smacPdu[2] <<8) + gAppRxPacket->smacPdu.smacPdu[3];
andreikovacs 0:4eb2240dbd22 1178 u16ReceivedPackets++;
andreikovacs 0:4eb2240dbd22 1179 u8TempRssivalue= u8LastRxRssiValue; //@CMA, Conn Test. New line
andreikovacs 0:4eb2240dbd22 1180 u32RssiSum += u8TempRssivalue;
andreikovacs 0:4eb2240dbd22 1181 u8AverageRssi = (uint8_t)(u32RssiSum/u16ReceivedPackets);
andreikovacs 0:4eb2240dbd22 1182 uart.printf("Packet %d . Packet index: %d . Rssi during RX: - %d\r\n",(uint32_t)u16ReceivedPackets, (uint32_t)u16PacketsIndex, (uint32_t)u8LastRxRssiValue);
andreikovacs 0:4eb2240dbd22 1183 if(u16PacketsIndex == u16TotalPackets)
andreikovacs 0:4eb2240dbd22 1184 {
andreikovacs 0:4eb2240dbd22 1185 u16FinalPacketsCount = 0;
andreikovacs 0:4eb2240dbd22 1186 perRxState = gPerRxStateReceivingLastFrames_c;
andreikovacs 0:4eb2240dbd22 1187 }
andreikovacs 0:4eb2240dbd22 1188 }
andreikovacs 0:4eb2240dbd22 1189 else if(stringComp((uint8_t*)"DONE",&gAppRxPacket->smacPdu.smacPdu[4],4))
andreikovacs 0:4eb2240dbd22 1190 {
andreikovacs 0:4eb2240dbd22 1191 u16FinalPacketsCount = 0;
andreikovacs 0:4eb2240dbd22 1192 perRxState = gPerRxStateReceivingLastFrames_c;
andreikovacs 0:4eb2240dbd22 1193 }
andreikovacs 0:4eb2240dbd22 1194 }
andreikovacs 0:4eb2240dbd22 1195 else
andreikovacs 0:4eb2240dbd22 1196 {
andreikovacs 0:4eb2240dbd22 1197 if(u16TotalPackets)
andreikovacs 0:4eb2240dbd22 1198 {
andreikovacs 0:4eb2240dbd22 1199 u16PacketsIndex++;
andreikovacs 0:4eb2240dbd22 1200 if(u16PacketsIndex == u16TotalPackets)
andreikovacs 0:4eb2240dbd22 1201 {
andreikovacs 0:4eb2240dbd22 1202 u16FinalPacketsCount = 0;
andreikovacs 0:4eb2240dbd22 1203 perRxState = gPerRxStateReceivingLastFrames_c;
andreikovacs 0:4eb2240dbd22 1204 }
andreikovacs 0:4eb2240dbd22 1205 }
andreikovacs 0:4eb2240dbd22 1206 }
andreikovacs 0:4eb2240dbd22 1207
andreikovacs 0:4eb2240dbd22 1208 SetRadioRxOnNoTimeOut();
andreikovacs 0:4eb2240dbd22 1209 }
andreikovacs 0:4eb2240dbd22 1210 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 1211 {
andreikovacs 0:4eb2240dbd22 1212 if(' ' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1213 {
andreikovacs 0:4eb2240dbd22 1214 (void)MLMERXDisableRequest();
andreikovacs 0:4eb2240dbd22 1215 uart.printf("\r\nAverage Rssi during PER: -");
andreikovacs 0:4eb2240dbd22 1216 uart.printf("%d",(uint32_t)u8AverageRssi);
andreikovacs 0:4eb2240dbd22 1217 uart.printf(" dBm\r\n");
andreikovacs 0:4eb2240dbd22 1218 uart.printf( "\n\rPER Test Rx Stopped\r\n\r\n");
andreikovacs 0:4eb2240dbd22 1219 PrintPerRxFinalLine(u16ReceivedPackets,u16TotalPackets);
andreikovacs 0:4eb2240dbd22 1220 perRxState = gPerRxStateIdle_c;
andreikovacs 0:4eb2240dbd22 1221 }
andreikovacs 0:4eb2240dbd22 1222 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1223 }
andreikovacs 0:4eb2240dbd22 1224 break;
andreikovacs 0:4eb2240dbd22 1225 case gPerRxStateReceivingLastFrames_c:
andreikovacs 0:4eb2240dbd22 1226 if(bRxDone)
andreikovacs 0:4eb2240dbd22 1227 {
andreikovacs 0:4eb2240dbd22 1228 u16FinalPacketsCount++;
andreikovacs 0:4eb2240dbd22 1229 if(mTotalFinalFrames_c == u16FinalPacketsCount)
andreikovacs 0:4eb2240dbd22 1230 {
andreikovacs 0:4eb2240dbd22 1231 uart.printf("\r\nAverage Rssi during PER: -");
andreikovacs 0:4eb2240dbd22 1232 uart.printf("%d",(uint32_t)u8AverageRssi);
andreikovacs 0:4eb2240dbd22 1233 uart.printf(" dBm\r\n");
andreikovacs 0:4eb2240dbd22 1234 uart.printf( "\n\rPER Test Finished\r\n\r\n");
andreikovacs 0:4eb2240dbd22 1235 PrintPerRxFinalLine(u16ReceivedPackets,u16TotalPackets);
andreikovacs 0:4eb2240dbd22 1236 perRxState = gPerRxStateIdle_c;
andreikovacs 0:4eb2240dbd22 1237 }
andreikovacs 0:4eb2240dbd22 1238 else
andreikovacs 0:4eb2240dbd22 1239 {
andreikovacs 0:4eb2240dbd22 1240 SetRadioRxOnNoTimeOut();
andreikovacs 0:4eb2240dbd22 1241 }
andreikovacs 0:4eb2240dbd22 1242 }
andreikovacs 0:4eb2240dbd22 1243 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 1244 {
andreikovacs 0:4eb2240dbd22 1245 if(' ' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1246 {
andreikovacs 0:4eb2240dbd22 1247 (void)MLMERXDisableRequest();
andreikovacs 0:4eb2240dbd22 1248 uart.printf("\r\nAverage Rssi during PER: -");
andreikovacs 0:4eb2240dbd22 1249 uart.printf("%d",(uint32_t)u8AverageRssi);
andreikovacs 0:4eb2240dbd22 1250 uart.printf(" dBm\r\n");
andreikovacs 0:4eb2240dbd22 1251 uart.printf( "\n\rPER Test Rx Stopped\r\n\r\n");
andreikovacs 0:4eb2240dbd22 1252 PrintPerRxFinalLine(u16ReceivedPackets,u16TotalPackets);
andreikovacs 0:4eb2240dbd22 1253 perRxState = gPerRxStateIdle_c;
andreikovacs 0:4eb2240dbd22 1254 }
andreikovacs 0:4eb2240dbd22 1255 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1256 }
andreikovacs 0:4eb2240dbd22 1257 break;
andreikovacs 0:4eb2240dbd22 1258 case gPerRxStateIdle_c:
andreikovacs 0:4eb2240dbd22 1259 if((evDataFromUART) && ('\r' == gu8UartData))
andreikovacs 0:4eb2240dbd22 1260 {
andreikovacs 0:4eb2240dbd22 1261 perRxState = gPerRxStateInit_c;
andreikovacs 0:4eb2240dbd22 1262 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1263 }
andreikovacs 0:4eb2240dbd22 1264 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1265 break;
andreikovacs 0:4eb2240dbd22 1266 default:
andreikovacs 0:4eb2240dbd22 1267 break;
andreikovacs 0:4eb2240dbd22 1268 }
andreikovacs 0:4eb2240dbd22 1269 return bBackFlag;
andreikovacs 0:4eb2240dbd22 1270 }
andreikovacs 0:4eb2240dbd22 1271
andreikovacs 0:4eb2240dbd22 1272 /************************************************************************************
andreikovacs 0:4eb2240dbd22 1273 *
andreikovacs 0:4eb2240dbd22 1274 * Range Test Handler for board that is performing TX
andreikovacs 0:4eb2240dbd22 1275 *
andreikovacs 0:4eb2240dbd22 1276 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 1277 bool_t RangeTx(void)
andreikovacs 0:4eb2240dbd22 1278 {
andreikovacs 0:4eb2240dbd22 1279 bool_t bBackFlag = FALSE;
andreikovacs 0:4eb2240dbd22 1280 static uint32_t u32RSSISum;
andreikovacs 0:4eb2240dbd22 1281 static uint16_t u16ReceivedPackets;
andreikovacs 0:4eb2240dbd22 1282 static uint16_t u16PacketsDropped;
andreikovacs 0:4eb2240dbd22 1283 uint8_t u8AverageRSSI;
andreikovacs 0:4eb2240dbd22 1284 uint8_t u8CurrentRSSI;
andreikovacs 0:4eb2240dbd22 1285
andreikovacs 0:4eb2240dbd22 1286 if(evTestParameters)
andreikovacs 0:4eb2240dbd22 1287 {
andreikovacs 0:4eb2240dbd22 1288 #if CT_Feature_Calibration
andreikovacs 0:4eb2240dbd22 1289 (void)MLMESetAdditionalRFOffset(gOffsetIncrement);
andreikovacs 0:4eb2240dbd22 1290 #endif
andreikovacs 0:4eb2240dbd22 1291 (void)MLMESetChannelRequest(testChannel);
andreikovacs 0:4eb2240dbd22 1292 (void)MLMEPAOutputAdjust(testPower);
andreikovacs 0:4eb2240dbd22 1293 PrintTestParameters(TRUE);
andreikovacs 0:4eb2240dbd22 1294 evTestParameters = FALSE;
andreikovacs 0:4eb2240dbd22 1295 }
andreikovacs 0:4eb2240dbd22 1296
andreikovacs 0:4eb2240dbd22 1297 switch(rangeTxState)
andreikovacs 0:4eb2240dbd22 1298 {
andreikovacs 0:4eb2240dbd22 1299 case gRangeTxStateInit_c:
andreikovacs 0:4eb2240dbd22 1300 u32RSSISum = 0;
andreikovacs 0:4eb2240dbd22 1301 u16ReceivedPackets = 0;
andreikovacs 0:4eb2240dbd22 1302 u16PacketsDropped = 0;
andreikovacs 0:4eb2240dbd22 1303 PrintMenu(cu8ShortCutsBar, mAppSer);
andreikovacs 0:4eb2240dbd22 1304 PrintMenu(cu8RangeTxTestMenu, mAppSer);
andreikovacs 0:4eb2240dbd22 1305 PrintTestParameters(FALSE);
andreikovacs 0:4eb2240dbd22 1306 shortCutsEnabled = TRUE;
andreikovacs 0:4eb2240dbd22 1307 rangeTxState = gRangeTxWaitStartTest_c;
andreikovacs 0:4eb2240dbd22 1308 break;
andreikovacs 0:4eb2240dbd22 1309 case gRangeTxWaitStartTest_c:
andreikovacs 0:4eb2240dbd22 1310 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 1311 {
andreikovacs 0:4eb2240dbd22 1312 if(' ' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1313 {
andreikovacs 0:4eb2240dbd22 1314 shortCutsEnabled = FALSE;
andreikovacs 0:4eb2240dbd22 1315 uart.printf( "\f\r\nRange Test Tx Running\r\n");
andreikovacs 0:4eb2240dbd22 1316 rangeTxState = gRangeTxStateStartTest_c;
andreikovacs 0:4eb2240dbd22 1317 Thread::wait(200);
andreikovacs 0:4eb2240dbd22 1318 }
andreikovacs 0:4eb2240dbd22 1319 else if('p' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1320 {
andreikovacs 0:4eb2240dbd22 1321 bBackFlag = TRUE;
andreikovacs 0:4eb2240dbd22 1322 }
andreikovacs 0:4eb2240dbd22 1323 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1324 }
andreikovacs 0:4eb2240dbd22 1325 break;
andreikovacs 0:4eb2240dbd22 1326 case gRangeTxStateStartTest_c:
andreikovacs 0:4eb2240dbd22 1327 if(!timePassed) //waiting 200 ms
andreikovacs 0:4eb2240dbd22 1328 break;
andreikovacs 0:4eb2240dbd22 1329 timePassed = FALSE;
andreikovacs 0:4eb2240dbd22 1330 bTxDone = FALSE;
andreikovacs 0:4eb2240dbd22 1331 gAppTxPacket->u8DataLength = 16;
andreikovacs 0:4eb2240dbd22 1332 gAppTxPacket->smacPdu.smacPdu[0] = 0;
andreikovacs 0:4eb2240dbd22 1333 FLib_MemCpy(&(gAppTxPacket->smacPdu.smacPdu[1]), (void*)"SMAC Range Demo",15);
andreikovacs 0:4eb2240dbd22 1334 MLMERXDisableRequest();
andreikovacs 0:4eb2240dbd22 1335 //RangeTestTmr.stop(); //@CMA, Conn Test. Stop Rx timer
andreikovacs 0:4eb2240dbd22 1336 (void)MCPSDataRequest(gAppTxPacket);
andreikovacs 0:4eb2240dbd22 1337 rangeTxState = gRangeTxStateRunningTest_c;
andreikovacs 0:4eb2240dbd22 1338 break;
andreikovacs 0:4eb2240dbd22 1339 case gRangeTxStateRunningTest_c:
andreikovacs 0:4eb2240dbd22 1340 if(bTxDone)
andreikovacs 0:4eb2240dbd22 1341 {
andreikovacs 0:4eb2240dbd22 1342 RangeTestTmr.attach_us(RangeTest_Timer_CallBack, 80000); //@CMA, Conn Test. Start Timer
andreikovacs 0:4eb2240dbd22 1343 SetRadioRxOnNoTimeOut();
andreikovacs 0:4eb2240dbd22 1344 rangeTxState = gRangeTxStatePrintTestResults_c;
andreikovacs 0:4eb2240dbd22 1345 }
andreikovacs 0:4eb2240dbd22 1346 break;
andreikovacs 0:4eb2240dbd22 1347 case gRangeTxStatePrintTestResults_c:
andreikovacs 0:4eb2240dbd22 1348 if(bRxDone)
andreikovacs 0:4eb2240dbd22 1349 {
andreikovacs 0:4eb2240dbd22 1350 if(gAppRxPacket->rxStatus == rxSuccessStatus_c)
andreikovacs 0:4eb2240dbd22 1351 {
andreikovacs 0:4eb2240dbd22 1352 if(stringComp((uint8_t*)"SMAC Range Demo",&gAppRxPacket->smacPdu.smacPdu[1],15))
andreikovacs 0:4eb2240dbd22 1353 {
andreikovacs 0:4eb2240dbd22 1354 u8CurrentRSSI = (gAppRxPacket->smacPdu.smacPdu[0]);
andreikovacs 0:4eb2240dbd22 1355 u32RSSISum += u8CurrentRSSI;
andreikovacs 0:4eb2240dbd22 1356 u16ReceivedPackets++;
andreikovacs 0:4eb2240dbd22 1357 u8AverageRSSI = (uint8_t)(u32RSSISum/u16ReceivedPackets);
andreikovacs 0:4eb2240dbd22 1358 uart.printf( "\r\n RSSI = -");
andreikovacs 0:4eb2240dbd22 1359 uart.printf("%d", (uint32_t)u8CurrentRSSI);
andreikovacs 0:4eb2240dbd22 1360 uart.printf(" dBm");
andreikovacs 0:4eb2240dbd22 1361 }
andreikovacs 0:4eb2240dbd22 1362 else
andreikovacs 0:4eb2240dbd22 1363 {
andreikovacs 0:4eb2240dbd22 1364 RangeTestTmr.attach_us(RangeTest_Timer_CallBack, 80000); //@CMA, Conn Test. Start Timer
andreikovacs 0:4eb2240dbd22 1365 SetRadioRxOnNoTimeOut();
andreikovacs 0:4eb2240dbd22 1366 }
andreikovacs 0:4eb2240dbd22 1367 }
andreikovacs 0:4eb2240dbd22 1368 else
andreikovacs 0:4eb2240dbd22 1369 {
andreikovacs 0:4eb2240dbd22 1370 u16PacketsDropped++;
andreikovacs 0:4eb2240dbd22 1371 uart.printf( "\r\nPacket Dropped");
andreikovacs 0:4eb2240dbd22 1372 bRxDone= FALSE; //@CMA, Conn Test. Added
andreikovacs 0:4eb2240dbd22 1373 }
andreikovacs 0:4eb2240dbd22 1374 if(evDataFromUART && (' ' == gu8UartData))
andreikovacs 0:4eb2240dbd22 1375 {
andreikovacs 0:4eb2240dbd22 1376 uart.printf( "\n\r\n\rRange Test Tx Stopped\r\n\r\n");
andreikovacs 0:4eb2240dbd22 1377 u8AverageRSSI = (uint8_t)(u32RSSISum/u16ReceivedPackets);
andreikovacs 0:4eb2240dbd22 1378 uart.printf( "Average RSSI -");
andreikovacs 0:4eb2240dbd22 1379 uart.printf("%d", (uint32_t)u8AverageRSSI);
andreikovacs 0:4eb2240dbd22 1380 uart.printf(" dBm");
andreikovacs 0:4eb2240dbd22 1381 uart.printf( "\r\nPackets dropped ");
andreikovacs 0:4eb2240dbd22 1382 uart.printf("%d", (uint32_t)u16PacketsDropped);
andreikovacs 0:4eb2240dbd22 1383 uart.printf( "\r\n\r\n Press [enter] to go back to the Range Tx test menu");
andreikovacs 0:4eb2240dbd22 1384 rangeTxState = gRangeTxStateIdle_c;
andreikovacs 0:4eb2240dbd22 1385 (void)MLMERXDisableRequest();
andreikovacs 0:4eb2240dbd22 1386 AppDelayTmr.stop();
andreikovacs 0:4eb2240dbd22 1387 timePassed = FALSE;
andreikovacs 0:4eb2240dbd22 1388 }
andreikovacs 0:4eb2240dbd22 1389 else
andreikovacs 0:4eb2240dbd22 1390 {
andreikovacs 0:4eb2240dbd22 1391 rangeTxState = gRangeTxStateStartTest_c;
andreikovacs 0:4eb2240dbd22 1392 Thread::wait(200);
andreikovacs 0:4eb2240dbd22 1393 }
andreikovacs 0:4eb2240dbd22 1394 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1395 }
andreikovacs 0:4eb2240dbd22 1396
andreikovacs 0:4eb2240dbd22 1397 break;
andreikovacs 0:4eb2240dbd22 1398 case gRangeTxStateIdle_c:
andreikovacs 0:4eb2240dbd22 1399 if((evDataFromUART) && ('\r' == gu8UartData))
andreikovacs 0:4eb2240dbd22 1400 {
andreikovacs 0:4eb2240dbd22 1401 rangeTxState = gRangeTxStateInit_c;
andreikovacs 0:4eb2240dbd22 1402 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1403 }
andreikovacs 0:4eb2240dbd22 1404 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1405 break;
andreikovacs 0:4eb2240dbd22 1406 default:
andreikovacs 0:4eb2240dbd22 1407 break;
andreikovacs 0:4eb2240dbd22 1408 }
andreikovacs 0:4eb2240dbd22 1409 return bBackFlag;
andreikovacs 0:4eb2240dbd22 1410 }
andreikovacs 0:4eb2240dbd22 1411
andreikovacs 0:4eb2240dbd22 1412 /************************************************************************************
andreikovacs 0:4eb2240dbd22 1413 *
andreikovacs 0:4eb2240dbd22 1414 * Range Test Handler for board that is performing RX
andreikovacs 0:4eb2240dbd22 1415 *
andreikovacs 0:4eb2240dbd22 1416 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 1417 bool_t RangeRx(void)
andreikovacs 0:4eb2240dbd22 1418 {
andreikovacs 0:4eb2240dbd22 1419 bool_t bBackFlag = FALSE;
andreikovacs 0:4eb2240dbd22 1420 static uint32_t u32RSSISum;
andreikovacs 0:4eb2240dbd22 1421 static uint16_t u16ReceivedPackets;
andreikovacs 0:4eb2240dbd22 1422 uint8_t u8AverageRSSI, u8TempRSSIvalue;
andreikovacs 0:4eb2240dbd22 1423 uint8_t u8CurrentRSSI;
andreikovacs 0:4eb2240dbd22 1424
andreikovacs 0:4eb2240dbd22 1425 if(evTestParameters)
andreikovacs 0:4eb2240dbd22 1426 {
andreikovacs 0:4eb2240dbd22 1427 #if CT_Feature_Calibration
andreikovacs 0:4eb2240dbd22 1428 (void)MLMESetAdditionalRFOffset(gOffsetIncrement);
andreikovacs 0:4eb2240dbd22 1429 #endif
andreikovacs 0:4eb2240dbd22 1430 (void)MLMESetChannelRequest(testChannel);
andreikovacs 0:4eb2240dbd22 1431 (void)MLMEPAOutputAdjust(testPower);
andreikovacs 0:4eb2240dbd22 1432 PrintTestParameters(TRUE);
andreikovacs 0:4eb2240dbd22 1433 evTestParameters = FALSE;
andreikovacs 0:4eb2240dbd22 1434 }
andreikovacs 0:4eb2240dbd22 1435
andreikovacs 0:4eb2240dbd22 1436 switch(rangeRxState)
andreikovacs 0:4eb2240dbd22 1437 {
andreikovacs 0:4eb2240dbd22 1438 case gRangeRxStateInit_c:
andreikovacs 0:4eb2240dbd22 1439 u32RSSISum = 0;
andreikovacs 0:4eb2240dbd22 1440 u16ReceivedPackets = 0;
andreikovacs 0:4eb2240dbd22 1441 PrintMenu(cu8ShortCutsBar, mAppSer);
andreikovacs 0:4eb2240dbd22 1442 PrintMenu(cu8RangeRxTestMenu, mAppSer);
andreikovacs 0:4eb2240dbd22 1443 PrintTestParameters(FALSE);
andreikovacs 0:4eb2240dbd22 1444 shortCutsEnabled = TRUE;
andreikovacs 0:4eb2240dbd22 1445 rangeRxState = gRangeRxWaitStartTest_c;
andreikovacs 0:4eb2240dbd22 1446 break;
andreikovacs 0:4eb2240dbd22 1447 case gRangeRxWaitStartTest_c:
andreikovacs 0:4eb2240dbd22 1448 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 1449 {
andreikovacs 0:4eb2240dbd22 1450 if(' ' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1451 {
andreikovacs 0:4eb2240dbd22 1452 shortCutsEnabled = FALSE;
andreikovacs 0:4eb2240dbd22 1453 uart.printf( "\f\r\nRange Test Rx Running\r\n");
andreikovacs 0:4eb2240dbd22 1454 rangeRxState = gRangeRxStateStartTest_c;
andreikovacs 0:4eb2240dbd22 1455 }
andreikovacs 0:4eb2240dbd22 1456 else if('p' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1457 {
andreikovacs 0:4eb2240dbd22 1458 bBackFlag = TRUE;
andreikovacs 0:4eb2240dbd22 1459 }
andreikovacs 0:4eb2240dbd22 1460 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1461 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1462 }
andreikovacs 0:4eb2240dbd22 1463 break;
andreikovacs 0:4eb2240dbd22 1464 case gRangeRxStateStartTest_c:
andreikovacs 0:4eb2240dbd22 1465 SetRadioRxOnNoTimeOut();
andreikovacs 0:4eb2240dbd22 1466 rangeRxState = gRangeRxStateRunningTest_c;
andreikovacs 0:4eb2240dbd22 1467 break;
andreikovacs 0:4eb2240dbd22 1468 case gRangeRxStateRunningTest_c:
andreikovacs 0:4eb2240dbd22 1469 if(evDataFromUART && (' ' == gu8UartData))
andreikovacs 0:4eb2240dbd22 1470 {
andreikovacs 0:4eb2240dbd22 1471 (void)MLMERXDisableRequest();
andreikovacs 0:4eb2240dbd22 1472 uart.printf( "\n\r\n\rRange Test Rx Stopped\r\n\r\n");
andreikovacs 0:4eb2240dbd22 1473 u8AverageRSSI = (uint8_t)(u32RSSISum/u16ReceivedPackets);
andreikovacs 0:4eb2240dbd22 1474 uart.printf( "Average RSSI ");
andreikovacs 0:4eb2240dbd22 1475 if(u8AverageRSSI != 0)
andreikovacs 0:4eb2240dbd22 1476 {
andreikovacs 0:4eb2240dbd22 1477 uart.printf("-");
andreikovacs 0:4eb2240dbd22 1478 }
andreikovacs 0:4eb2240dbd22 1479 uart.printf("%d", (uint32_t)u8AverageRSSI);
andreikovacs 0:4eb2240dbd22 1480 uart.printf(" dBm");
andreikovacs 0:4eb2240dbd22 1481 uart.printf( "\r\n\r\n Press [enter] to go back to the Range Rx test menu");
andreikovacs 0:4eb2240dbd22 1482 rangeRxState = gRangeRxStateIdle_c;
andreikovacs 0:4eb2240dbd22 1483 }
andreikovacs 0:4eb2240dbd22 1484 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1485 if(bRxDone)
andreikovacs 0:4eb2240dbd22 1486 {
andreikovacs 0:4eb2240dbd22 1487 if(gAppRxPacket->rxStatus == rxSuccessStatus_c)
andreikovacs 0:4eb2240dbd22 1488 {
andreikovacs 0:4eb2240dbd22 1489 if(stringComp((uint8_t*)"SMAC Range Demo",&gAppRxPacket->smacPdu.smacPdu[1],15))
andreikovacs 0:4eb2240dbd22 1490 {
andreikovacs 0:4eb2240dbd22 1491 bRxDone = FALSE;
andreikovacs 0:4eb2240dbd22 1492 Thread::wait(4);
andreikovacs 0:4eb2240dbd22 1493 }
andreikovacs 0:4eb2240dbd22 1494 else
andreikovacs 0:4eb2240dbd22 1495 {
andreikovacs 0:4eb2240dbd22 1496 SetRadioRxOnNoTimeOut();
andreikovacs 0:4eb2240dbd22 1497 }
andreikovacs 0:4eb2240dbd22 1498 }
andreikovacs 0:4eb2240dbd22 1499 else
andreikovacs 0:4eb2240dbd22 1500 {
andreikovacs 0:4eb2240dbd22 1501 SetRadioRxOnNoTimeOut();
andreikovacs 0:4eb2240dbd22 1502 }
andreikovacs 0:4eb2240dbd22 1503 }
andreikovacs 0:4eb2240dbd22 1504 if(timePassed)
andreikovacs 0:4eb2240dbd22 1505 {
andreikovacs 0:4eb2240dbd22 1506 timePassed = FALSE;
andreikovacs 0:4eb2240dbd22 1507 bTxDone = FALSE;
andreikovacs 0:4eb2240dbd22 1508 u8TempRSSIvalue= u8LastRxRssiValue;
andreikovacs 0:4eb2240dbd22 1509 gAppTxPacket->smacPdu.smacPdu[0] = u8TempRSSIvalue;
andreikovacs 0:4eb2240dbd22 1510 FLib_MemCpy(&(gAppTxPacket->smacPdu.smacPdu[1]), (void *)"SMAC Range Demo",15);
andreikovacs 0:4eb2240dbd22 1511 gAppTxPacket->u8DataLength = 16;
andreikovacs 0:4eb2240dbd22 1512 (void)MCPSDataRequest(gAppTxPacket);
andreikovacs 0:4eb2240dbd22 1513 rangeRxState = gRangeRxStatePrintTestResults_c;
andreikovacs 0:4eb2240dbd22 1514 }
andreikovacs 0:4eb2240dbd22 1515 break;
andreikovacs 0:4eb2240dbd22 1516 case gRangeRxStatePrintTestResults_c:
andreikovacs 0:4eb2240dbd22 1517 if(bTxDone)
andreikovacs 0:4eb2240dbd22 1518 {
andreikovacs 0:4eb2240dbd22 1519 u8CurrentRSSI= u8LastRxRssiValue;
andreikovacs 0:4eb2240dbd22 1520 u32RSSISum += u8CurrentRSSI;
andreikovacs 0:4eb2240dbd22 1521 u16ReceivedPackets++;
andreikovacs 0:4eb2240dbd22 1522 u8AverageRSSI = (uint8_t)(u32RSSISum/u16ReceivedPackets);
andreikovacs 0:4eb2240dbd22 1523 uart.printf( "\r\n RSSI = -");
andreikovacs 0:4eb2240dbd22 1524 uart.printf("%d", (uint32_t)u8CurrentRSSI);
andreikovacs 0:4eb2240dbd22 1525 uart.printf(" dBm");
andreikovacs 0:4eb2240dbd22 1526 rangeRxState = gRangeRxStateStartTest_c;
andreikovacs 0:4eb2240dbd22 1527 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1528 }
andreikovacs 0:4eb2240dbd22 1529 break;
andreikovacs 0:4eb2240dbd22 1530 case gRangeRxStateIdle_c:
andreikovacs 0:4eb2240dbd22 1531 if((evDataFromUART) && ('\r' == gu8UartData))
andreikovacs 0:4eb2240dbd22 1532 {
andreikovacs 0:4eb2240dbd22 1533 rangeRxState = gRangeRxStateInit_c;
andreikovacs 0:4eb2240dbd22 1534 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1535 }
andreikovacs 0:4eb2240dbd22 1536 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1537 break;
andreikovacs 0:4eb2240dbd22 1538 default:
andreikovacs 0:4eb2240dbd22 1539 break;
andreikovacs 0:4eb2240dbd22 1540 }
andreikovacs 0:4eb2240dbd22 1541 return bBackFlag;
andreikovacs 0:4eb2240dbd22 1542 }
andreikovacs 0:4eb2240dbd22 1543
andreikovacs 0:4eb2240dbd22 1544 /************************************************************************************
andreikovacs 0:4eb2240dbd22 1545 *
andreikovacs 0:4eb2240dbd22 1546 * Handler for viewing/modifying XCVR registers
andreikovacs 0:4eb2240dbd22 1547 *
andreikovacs 0:4eb2240dbd22 1548 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 1549 bool_t EditRegisters(void)
andreikovacs 0:4eb2240dbd22 1550 {
andreikovacs 0:4eb2240dbd22 1551 bool_t bBackFlag = FALSE;
andreikovacs 0:4eb2240dbd22 1552 if(evTestParameters)
andreikovacs 0:4eb2240dbd22 1553 {
andreikovacs 0:4eb2240dbd22 1554 #if CT_Feature_Calibration
andreikovacs 0:4eb2240dbd22 1555 (void)MLMESetAdditionalRFOffset(gOffsetIncrement);
andreikovacs 0:4eb2240dbd22 1556 #endif
andreikovacs 0:4eb2240dbd22 1557 (void)MLMESetChannelRequest(testChannel);
andreikovacs 0:4eb2240dbd22 1558 (void)MLMEPAOutputAdjust(testPower);
andreikovacs 0:4eb2240dbd22 1559 PrintTestParameters(TRUE);
andreikovacs 0:4eb2240dbd22 1560 evTestParameters = FALSE;
andreikovacs 0:4eb2240dbd22 1561 }
andreikovacs 0:4eb2240dbd22 1562
andreikovacs 0:4eb2240dbd22 1563 switch(eRState)
andreikovacs 0:4eb2240dbd22 1564 {
andreikovacs 0:4eb2240dbd22 1565 case gERStateInit_c:
andreikovacs 0:4eb2240dbd22 1566 PrintMenu(cu8ShortCutsBar, mAppSer);
andreikovacs 0:4eb2240dbd22 1567 PrintMenu(cu8RadioRegistersEditMenu, mAppSer);
andreikovacs 0:4eb2240dbd22 1568 PrintTestParameters(FALSE);
andreikovacs 0:4eb2240dbd22 1569 shortCutsEnabled = TRUE;
andreikovacs 0:4eb2240dbd22 1570 eRState = gERWaitSelection_c;
andreikovacs 0:4eb2240dbd22 1571 break;
andreikovacs 0:4eb2240dbd22 1572 case gERWaitSelection_c:
andreikovacs 0:4eb2240dbd22 1573 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 1574 {
andreikovacs 0:4eb2240dbd22 1575 #if CT_Feature_Direct_Registers
andreikovacs 0:4eb2240dbd22 1576 if('1' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1577 {
andreikovacs 0:4eb2240dbd22 1578 bIsRegisterDirect = TRUE;
andreikovacs 0:4eb2240dbd22 1579 oRState = gORStateInit_c;
andreikovacs 0:4eb2240dbd22 1580 eRState = gERStateOverrideReg_c;
andreikovacs 0:4eb2240dbd22 1581 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1582 }
andreikovacs 0:4eb2240dbd22 1583 else if('2' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1584 {
andreikovacs 0:4eb2240dbd22 1585 bIsRegisterDirect = TRUE;
andreikovacs 0:4eb2240dbd22 1586 rRState = gRRStateInit_c;
andreikovacs 0:4eb2240dbd22 1587 eRState = gERStateReadReg_c;
andreikovacs 0:4eb2240dbd22 1588 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1589 }
andreikovacs 0:4eb2240dbd22 1590 #if CT_Feature_Indirect_Registers
andreikovacs 0:4eb2240dbd22 1591 else if('3' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1592 {
andreikovacs 0:4eb2240dbd22 1593 bIsRegisterDirect = FALSE;
andreikovacs 0:4eb2240dbd22 1594 oRState = gORStateInit_c;
andreikovacs 0:4eb2240dbd22 1595 eRState = gERStateOverrideReg_c;
andreikovacs 0:4eb2240dbd22 1596 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1597 }
andreikovacs 0:4eb2240dbd22 1598 else if('4' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1599 {
andreikovacs 0:4eb2240dbd22 1600 bIsRegisterDirect = FALSE;
andreikovacs 0:4eb2240dbd22 1601 rRState = gRRStateInit_c;
andreikovacs 0:4eb2240dbd22 1602 eRState = gERStateReadReg_c;
andreikovacs 0:4eb2240dbd22 1603 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1604 }
andreikovacs 0:4eb2240dbd22 1605 else if('5' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1606 {
andreikovacs 0:4eb2240dbd22 1607 dRState = gDRStateInit_c;
andreikovacs 0:4eb2240dbd22 1608 eRState = gERStateDumpAllRegs_c;
andreikovacs 0:4eb2240dbd22 1609 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1610 }
andreikovacs 0:4eb2240dbd22 1611 #else
andreikovacs 0:4eb2240dbd22 1612 else if('3' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1613 {
andreikovacs 0:4eb2240dbd22 1614 dRState = gDRStateInit_c;
andreikovacs 0:4eb2240dbd22 1615 eRState = gERStateDumpAllRegs_c;
andreikovacs 0:4eb2240dbd22 1616 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1617 }
andreikovacs 0:4eb2240dbd22 1618 #endif
andreikovacs 0:4eb2240dbd22 1619 else
andreikovacs 0:4eb2240dbd22 1620 #endif
andreikovacs 0:4eb2240dbd22 1621 if('p' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1622 {
andreikovacs 0:4eb2240dbd22 1623 bBackFlag = TRUE;
andreikovacs 0:4eb2240dbd22 1624 }
andreikovacs 0:4eb2240dbd22 1625 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1626 }
andreikovacs 0:4eb2240dbd22 1627 break;
andreikovacs 0:4eb2240dbd22 1628 case gERStateOverrideReg_c:
andreikovacs 0:4eb2240dbd22 1629 if(OverrideRegisters())
andreikovacs 0:4eb2240dbd22 1630 {
andreikovacs 0:4eb2240dbd22 1631 eRState = gERStateInit_c;
andreikovacs 0:4eb2240dbd22 1632 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1633 }
andreikovacs 0:4eb2240dbd22 1634 break;
andreikovacs 0:4eb2240dbd22 1635 case gERStateReadReg_c:
andreikovacs 0:4eb2240dbd22 1636 if(ReadRegisters())
andreikovacs 0:4eb2240dbd22 1637 {
andreikovacs 0:4eb2240dbd22 1638 eRState = gERStateInit_c;
andreikovacs 0:4eb2240dbd22 1639 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1640 }
andreikovacs 0:4eb2240dbd22 1641 break;
andreikovacs 0:4eb2240dbd22 1642 case gERStateDumpAllRegs_c:
andreikovacs 0:4eb2240dbd22 1643 if(DumpRegisters()) {
andreikovacs 0:4eb2240dbd22 1644 eRState = gERStateInit_c;
andreikovacs 0:4eb2240dbd22 1645 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1646 }
andreikovacs 0:4eb2240dbd22 1647 break;
andreikovacs 0:4eb2240dbd22 1648 default:
andreikovacs 0:4eb2240dbd22 1649 break;
andreikovacs 0:4eb2240dbd22 1650 }
andreikovacs 0:4eb2240dbd22 1651 return bBackFlag;
andreikovacs 0:4eb2240dbd22 1652 }
andreikovacs 0:4eb2240dbd22 1653
andreikovacs 0:4eb2240dbd22 1654 /************************************************************************************
andreikovacs 0:4eb2240dbd22 1655 *
andreikovacs 0:4eb2240dbd22 1656 * Dump registers
andreikovacs 0:4eb2240dbd22 1657 *
andreikovacs 0:4eb2240dbd22 1658 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 1659 bool_t DumpRegisters(void)
andreikovacs 0:4eb2240dbd22 1660 {
andreikovacs 0:4eb2240dbd22 1661 bool_t bBackFlag = FALSE;
andreikovacs 0:4eb2240dbd22 1662
andreikovacs 0:4eb2240dbd22 1663 switch(dRState)
andreikovacs 0:4eb2240dbd22 1664 {
andreikovacs 0:4eb2240dbd22 1665 case gDRStateInit_c:
andreikovacs 0:4eb2240dbd22 1666 uart.printf( "\f\r\rDump Registers\r\n");
andreikovacs 0:4eb2240dbd22 1667 uart.printf( "\r\n-Press [space] to dump registers\r\n");
andreikovacs 0:4eb2240dbd22 1668 uart.printf( "\r\n-Press [p] Previous Menu\r\n");
andreikovacs 0:4eb2240dbd22 1669 shortCutsEnabled = FALSE;
andreikovacs 0:4eb2240dbd22 1670 dRState = gDRStateDumpRegs_c;
andreikovacs 0:4eb2240dbd22 1671 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1672 break;
andreikovacs 0:4eb2240dbd22 1673 case gDRStateDumpRegs_c:
andreikovacs 0:4eb2240dbd22 1674 if(evDataFromUART){
andreikovacs 0:4eb2240dbd22 1675 if(gu8UartData == 'p')
andreikovacs 0:4eb2240dbd22 1676 {
andreikovacs 0:4eb2240dbd22 1677 bBackFlag = TRUE;
andreikovacs 0:4eb2240dbd22 1678 }
andreikovacs 0:4eb2240dbd22 1679 else if (gu8UartData == ' ')
andreikovacs 0:4eb2240dbd22 1680 {
andreikovacs 0:4eb2240dbd22 1681 uart.printf( "\r\n -Dumping registers... \r\n");
andreikovacs 0:4eb2240dbd22 1682 const registerLimits_t* interval = registerIntervals;
andreikovacs 0:4eb2240dbd22 1683
andreikovacs 0:4eb2240dbd22 1684 while(!((*interval).regStart == 0 && (*interval).regEnd == 0))
andreikovacs 0:4eb2240dbd22 1685 {
andreikovacs 0:4eb2240dbd22 1686 uart.printf( "\r\n -Access type: ");
andreikovacs 0:4eb2240dbd22 1687 if( (*interval).bIsRegisterDirect )
andreikovacs 0:4eb2240dbd22 1688 uart.printf("direct\r\n");
andreikovacs 0:4eb2240dbd22 1689 else
andreikovacs 0:4eb2240dbd22 1690 uart.printf("indirect\r\n");
andreikovacs 0:4eb2240dbd22 1691 bIsRegisterDirect = (*interval).bIsRegisterDirect;
andreikovacs 0:4eb2240dbd22 1692 ReadRFRegs((*interval).regStart, (*interval).regEnd);
andreikovacs 0:4eb2240dbd22 1693 interval++;
andreikovacs 0:4eb2240dbd22 1694 }
andreikovacs 0:4eb2240dbd22 1695 dRState = gDRStateInit_c;
andreikovacs 0:4eb2240dbd22 1696 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1697 }
andreikovacs 0:4eb2240dbd22 1698 }
andreikovacs 0:4eb2240dbd22 1699 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1700 break;
andreikovacs 0:4eb2240dbd22 1701 default:
andreikovacs 0:4eb2240dbd22 1702 break;
andreikovacs 0:4eb2240dbd22 1703 }
andreikovacs 0:4eb2240dbd22 1704 return bBackFlag;
andreikovacs 0:4eb2240dbd22 1705 }
andreikovacs 0:4eb2240dbd22 1706
andreikovacs 0:4eb2240dbd22 1707 /************************************************************************************
andreikovacs 0:4eb2240dbd22 1708 *
andreikovacs 0:4eb2240dbd22 1709 * Read and print register values with addresses from u8RegStartAddress
andreikovacs 0:4eb2240dbd22 1710 * to u8RegStopAddress
andreikovacs 0:4eb2240dbd22 1711 *
andreikovacs 0:4eb2240dbd22 1712 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 1713 void ReadRFRegs(registerAddressSize_t rasRegStartAddress, registerAddressSize_t rasRegStopAddress)
andreikovacs 0:4eb2240dbd22 1714 {
andreikovacs 0:4eb2240dbd22 1715
andreikovacs 0:4eb2240dbd22 1716 static uint16_t rasRegAddress;
andreikovacs 0:4eb2240dbd22 1717 registerSize_t rsRegValue;
andreikovacs 0:4eb2240dbd22 1718 uart.printf( " --------------------------------------- ");
andreikovacs 0:4eb2240dbd22 1719 for(rasRegAddress = rasRegStartAddress; rasRegAddress <= rasRegStopAddress; rasRegAddress+=(gRegisterSize_c))
andreikovacs 0:4eb2240dbd22 1720 {
andreikovacs 0:4eb2240dbd22 1721 uart.printf( "\r\n| Address : 0x");
andreikovacs 0:4eb2240dbd22 1722 uart.printf("%x", (uint8_t*)&rasRegAddress);
andreikovacs 0:4eb2240dbd22 1723 aspTestRequestMsg.msgType = aspMsgTypeXcvrReadReq_c;
andreikovacs 0:4eb2240dbd22 1724 aspTestRequestMsg.msgData.aspXcvrData.addr = (uint16_t)rasRegAddress;
andreikovacs 0:4eb2240dbd22 1725 aspTestRequestMsg.msgData.aspXcvrData.len = gRegisterSize_c;
andreikovacs 0:4eb2240dbd22 1726 aspTestRequestMsg.msgData.aspXcvrData.mode = !bIsRegisterDirect;
andreikovacs 0:4eb2240dbd22 1727
andreikovacs 0:4eb2240dbd22 1728 APP_ASP_SapHandler(&aspTestRequestMsg, 0);
andreikovacs 0:4eb2240dbd22 1729 rsRegValue = *((registerSize_t*)aspTestRequestMsg.msgData.aspXcvrData.data);
andreikovacs 0:4eb2240dbd22 1730 uart.printf( " Data value : 0x");
andreikovacs 0:4eb2240dbd22 1731 uart.printf("%x", (uint8_t*)&rsRegValue);
andreikovacs 0:4eb2240dbd22 1732 uart.printf( " |");
andreikovacs 0:4eb2240dbd22 1733 }
andreikovacs 0:4eb2240dbd22 1734 uart.printf( "\r\n --------------------------------------- \r\n");
andreikovacs 0:4eb2240dbd22 1735 }
andreikovacs 0:4eb2240dbd22 1736
andreikovacs 0:4eb2240dbd22 1737 /************************************************************************************
andreikovacs 0:4eb2240dbd22 1738 *
andreikovacs 0:4eb2240dbd22 1739 * Read register
andreikovacs 0:4eb2240dbd22 1740 *
andreikovacs 0:4eb2240dbd22 1741 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 1742 bool_t ReadRegisters(void)
andreikovacs 0:4eb2240dbd22 1743 {
andreikovacs 0:4eb2240dbd22 1744 bool_t bBackFlag = FALSE;
andreikovacs 0:4eb2240dbd22 1745 static uint8_t au8RxString[5];
andreikovacs 0:4eb2240dbd22 1746 static uint8_t u8Index;
andreikovacs 0:4eb2240dbd22 1747 static registerAddressSize_t rasRegAddress;
andreikovacs 0:4eb2240dbd22 1748 static registerSize_t rsRegValue;
andreikovacs 0:4eb2240dbd22 1749 static char auxToPrint[2];
andreikovacs 0:4eb2240dbd22 1750
andreikovacs 0:4eb2240dbd22 1751 switch(rRState)
andreikovacs 0:4eb2240dbd22 1752 {
andreikovacs 0:4eb2240dbd22 1753 case gRRStateInit_c:
andreikovacs 0:4eb2240dbd22 1754 uart.printf( "\f\r\rRead Registers\r\n");
andreikovacs 0:4eb2240dbd22 1755 uart.printf( "\r\n-Press [p] Previous Menu\r\n");
andreikovacs 0:4eb2240dbd22 1756 shortCutsEnabled = FALSE;
andreikovacs 0:4eb2240dbd22 1757 rRState = gRRStateStart_c;
andreikovacs 0:4eb2240dbd22 1758 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1759 break;
andreikovacs 0:4eb2240dbd22 1760 case gRRStateStart_c:
andreikovacs 0:4eb2240dbd22 1761 uart.printf( "\r\n -write the Register address in Hex and [enter]: 0x");
andreikovacs 0:4eb2240dbd22 1762 u8Index = 0;
andreikovacs 0:4eb2240dbd22 1763 rRState = gRRWaitForTheAddress_c;
andreikovacs 0:4eb2240dbd22 1764 break;
andreikovacs 0:4eb2240dbd22 1765 case gRRWaitForTheAddress_c:
andreikovacs 0:4eb2240dbd22 1766 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 1767 {
andreikovacs 0:4eb2240dbd22 1768 if((!isAsciiHex(gu8UartData)) && ('\r' != gu8UartData))
andreikovacs 0:4eb2240dbd22 1769 {
andreikovacs 0:4eb2240dbd22 1770 if('p' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1771 {
andreikovacs 0:4eb2240dbd22 1772 bBackFlag = TRUE;
andreikovacs 0:4eb2240dbd22 1773 }
andreikovacs 0:4eb2240dbd22 1774 else
andreikovacs 0:4eb2240dbd22 1775 {
andreikovacs 0:4eb2240dbd22 1776 uart.printf( "\r\n -Invalid Character!! ");
andreikovacs 0:4eb2240dbd22 1777 rRState = gRRStateStart_c;
andreikovacs 0:4eb2240dbd22 1778 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1779 }
andreikovacs 0:4eb2240dbd22 1780 }
andreikovacs 0:4eb2240dbd22 1781 else if((gRegisterAddressASCII_c == u8Index) && ('\r' != gu8UartData))
andreikovacs 0:4eb2240dbd22 1782 {
andreikovacs 0:4eb2240dbd22 1783 uart.printf( "\r\n -Value out of Range!! ");
andreikovacs 0:4eb2240dbd22 1784 rRState = gRRStateStart_c;
andreikovacs 0:4eb2240dbd22 1785 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1786 }
andreikovacs 0:4eb2240dbd22 1787 else if(isAsciiHex(gu8UartData))
andreikovacs 0:4eb2240dbd22 1788 {
andreikovacs 0:4eb2240dbd22 1789 au8RxString[u8Index++] = gu8UartData;
andreikovacs 0:4eb2240dbd22 1790 auxToPrint[0] = gu8UartData;
andreikovacs 0:4eb2240dbd22 1791 auxToPrint[1] = '\0';
andreikovacs 0:4eb2240dbd22 1792 uart.printf( auxToPrint);
andreikovacs 0:4eb2240dbd22 1793 }
andreikovacs 0:4eb2240dbd22 1794 else
andreikovacs 0:4eb2240dbd22 1795 {
andreikovacs 0:4eb2240dbd22 1796 au8RxString[u8Index] = 0;
andreikovacs 0:4eb2240dbd22 1797 rasRegAddress = (registerAddressSize_t)HexString2Dec(au8RxString);
andreikovacs 0:4eb2240dbd22 1798 aspTestRequestMsg.msgType = aspMsgTypeXcvrReadReq_c;
andreikovacs 0:4eb2240dbd22 1799 aspTestRequestMsg.msgData.aspXcvrData.addr = (uint16_t)rasRegAddress;
andreikovacs 0:4eb2240dbd22 1800 aspTestRequestMsg.msgData.aspXcvrData.len = gRegisterSize_c;
andreikovacs 0:4eb2240dbd22 1801 aspTestRequestMsg.msgData.aspXcvrData.mode = !bIsRegisterDirect;
andreikovacs 0:4eb2240dbd22 1802 APP_ASP_SapHandler(&aspTestRequestMsg, 0);
andreikovacs 0:4eb2240dbd22 1803 rsRegValue = *((registerSize_t*)aspTestRequestMsg.msgData.aspXcvrData.data);
andreikovacs 0:4eb2240dbd22 1804
andreikovacs 0:4eb2240dbd22 1805 uart.printf( "\r\n -Register value : 0x");
andreikovacs 0:4eb2240dbd22 1806 uart.printf("%x", (uint8_t*)&rsRegValue);
andreikovacs 0:4eb2240dbd22 1807 uart.printf( "\r\n");
andreikovacs 0:4eb2240dbd22 1808
andreikovacs 0:4eb2240dbd22 1809 rRState = gRRStateStart_c;
andreikovacs 0:4eb2240dbd22 1810 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1811 }
andreikovacs 0:4eb2240dbd22 1812 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1813 }
andreikovacs 0:4eb2240dbd22 1814 break;
andreikovacs 0:4eb2240dbd22 1815 default:
andreikovacs 0:4eb2240dbd22 1816 break;
andreikovacs 0:4eb2240dbd22 1817 }
andreikovacs 0:4eb2240dbd22 1818 return bBackFlag;
andreikovacs 0:4eb2240dbd22 1819 }
andreikovacs 0:4eb2240dbd22 1820
andreikovacs 0:4eb2240dbd22 1821 /************************************************************************************
andreikovacs 0:4eb2240dbd22 1822 *
andreikovacs 0:4eb2240dbd22 1823 * Override Register
andreikovacs 0:4eb2240dbd22 1824 *
andreikovacs 0:4eb2240dbd22 1825 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 1826 bool_t OverrideRegisters(void)
andreikovacs 0:4eb2240dbd22 1827 {
andreikovacs 0:4eb2240dbd22 1828 bool_t bBackFlag = FALSE;
andreikovacs 0:4eb2240dbd22 1829 static uint8_t au8RxString[5];
andreikovacs 0:4eb2240dbd22 1830 static uint8_t u8Index;
andreikovacs 0:4eb2240dbd22 1831 static registerAddressSize_t rasRegAddress;
andreikovacs 0:4eb2240dbd22 1832 static registerSize_t rsRegValue;
andreikovacs 0:4eb2240dbd22 1833 static char auxToPrint[2];
andreikovacs 0:4eb2240dbd22 1834
andreikovacs 0:4eb2240dbd22 1835 switch(oRState)
andreikovacs 0:4eb2240dbd22 1836 {
andreikovacs 0:4eb2240dbd22 1837 case gORStateInit_c:
andreikovacs 0:4eb2240dbd22 1838 uart.printf("\f\r\nWrite Registers\r\n");
andreikovacs 0:4eb2240dbd22 1839 uart.printf("\r\n-Press [p] Previous Menu\r\n");
andreikovacs 0:4eb2240dbd22 1840 shortCutsEnabled = FALSE;
andreikovacs 0:4eb2240dbd22 1841 oRState = gORStateStart_c;
andreikovacs 0:4eb2240dbd22 1842 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1843 break;
andreikovacs 0:4eb2240dbd22 1844 case gORStateStart_c:
andreikovacs 0:4eb2240dbd22 1845 uart.printf("\r\n -write the Register address in Hex and [enter]: 0x");
andreikovacs 0:4eb2240dbd22 1846 u8Index = 0;
andreikovacs 0:4eb2240dbd22 1847 oRState = gORWaitForTheAddress_c;
andreikovacs 0:4eb2240dbd22 1848 break;
andreikovacs 0:4eb2240dbd22 1849 case gORWaitForTheAddress_c:
andreikovacs 0:4eb2240dbd22 1850 if(evDataFromUART){
andreikovacs 0:4eb2240dbd22 1851 if((!isAsciiHex(gu8UartData)) && ('\r' != gu8UartData))
andreikovacs 0:4eb2240dbd22 1852 {
andreikovacs 0:4eb2240dbd22 1853 if('p' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1854 {
andreikovacs 0:4eb2240dbd22 1855 bBackFlag = TRUE;
andreikovacs 0:4eb2240dbd22 1856 }
andreikovacs 0:4eb2240dbd22 1857 else
andreikovacs 0:4eb2240dbd22 1858 {
andreikovacs 0:4eb2240dbd22 1859 uart.printf("\r\n -Invalid Character!! ");
andreikovacs 0:4eb2240dbd22 1860 oRState = gORStateStart_c;
andreikovacs 0:4eb2240dbd22 1861 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1862 }
andreikovacs 0:4eb2240dbd22 1863 }
andreikovacs 0:4eb2240dbd22 1864 else if((gRegisterAddressASCII_c == u8Index) && ('\r' != gu8UartData))
andreikovacs 0:4eb2240dbd22 1865 {
andreikovacs 0:4eb2240dbd22 1866 uart.printf("\r\n -Value out of Range!! ");
andreikovacs 0:4eb2240dbd22 1867 oRState = gORStateStart_c;
andreikovacs 0:4eb2240dbd22 1868 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1869 }
andreikovacs 0:4eb2240dbd22 1870 else if(isAsciiHex(gu8UartData))
andreikovacs 0:4eb2240dbd22 1871 {
andreikovacs 0:4eb2240dbd22 1872 au8RxString[u8Index++] = gu8UartData;
andreikovacs 0:4eb2240dbd22 1873 auxToPrint[0] = gu8UartData;
andreikovacs 0:4eb2240dbd22 1874 auxToPrint[1] = '\0';
andreikovacs 0:4eb2240dbd22 1875 uart.printf(auxToPrint);
andreikovacs 0:4eb2240dbd22 1876 }
andreikovacs 0:4eb2240dbd22 1877 else
andreikovacs 0:4eb2240dbd22 1878 {
andreikovacs 0:4eb2240dbd22 1879 au8RxString[u8Index] = 0;
andreikovacs 0:4eb2240dbd22 1880 rasRegAddress = (registerAddressSize_t)HexString2Dec(au8RxString);
andreikovacs 0:4eb2240dbd22 1881 uart.printf("\r\n -write the Register value to override in Hex and [enter]: 0x");
andreikovacs 0:4eb2240dbd22 1882 u8Index = 0;
andreikovacs 0:4eb2240dbd22 1883 oRState = gORWaitForTheValue_c;
andreikovacs 0:4eb2240dbd22 1884 }
andreikovacs 0:4eb2240dbd22 1885 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1886 }
andreikovacs 0:4eb2240dbd22 1887 break;
andreikovacs 0:4eb2240dbd22 1888 case gORWaitForTheValue_c:
andreikovacs 0:4eb2240dbd22 1889 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 1890 {
andreikovacs 0:4eb2240dbd22 1891 if((!isAsciiHex(gu8UartData)) && ('\r' != gu8UartData))
andreikovacs 0:4eb2240dbd22 1892 {
andreikovacs 0:4eb2240dbd22 1893 if('p' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1894 {
andreikovacs 0:4eb2240dbd22 1895 bBackFlag = TRUE;
andreikovacs 0:4eb2240dbd22 1896 }
andreikovacs 0:4eb2240dbd22 1897 else
andreikovacs 0:4eb2240dbd22 1898 {
andreikovacs 0:4eb2240dbd22 1899 uart.printf("\r\n -Invalid Character!! ");
andreikovacs 0:4eb2240dbd22 1900 oRState = gORStateStart_c;
andreikovacs 0:4eb2240dbd22 1901 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1902 }
andreikovacs 0:4eb2240dbd22 1903 }
andreikovacs 0:4eb2240dbd22 1904 else if((2 == u8Index) && ('\r' != gu8UartData))
andreikovacs 0:4eb2240dbd22 1905 {
andreikovacs 0:4eb2240dbd22 1906 uart.printf("\r\n -Value out of Range!! ");
andreikovacs 0:4eb2240dbd22 1907 oRState = gORStateStart_c;
andreikovacs 0:4eb2240dbd22 1908 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1909 }
andreikovacs 0:4eb2240dbd22 1910 else if(isAsciiHex(gu8UartData))
andreikovacs 0:4eb2240dbd22 1911 {
andreikovacs 0:4eb2240dbd22 1912 au8RxString[u8Index++] = gu8UartData;
andreikovacs 0:4eb2240dbd22 1913 auxToPrint[0] = gu8UartData;
andreikovacs 0:4eb2240dbd22 1914 auxToPrint[1] = '\0';
andreikovacs 0:4eb2240dbd22 1915 uart.printf(auxToPrint);
andreikovacs 0:4eb2240dbd22 1916 }
andreikovacs 0:4eb2240dbd22 1917 else
andreikovacs 0:4eb2240dbd22 1918 {
andreikovacs 0:4eb2240dbd22 1919 au8RxString[u8Index] = 0;
andreikovacs 0:4eb2240dbd22 1920 rsRegValue = (registerSize_t)HexString2Dec(au8RxString);
andreikovacs 0:4eb2240dbd22 1921 aspTestRequestMsg.msgType = aspMsgTypeXcvrWriteReq_c;
andreikovacs 0:4eb2240dbd22 1922 aspTestRequestMsg.msgData.aspXcvrData.addr = (uint16_t)rasRegAddress;
andreikovacs 0:4eb2240dbd22 1923 aspTestRequestMsg.msgData.aspXcvrData.len = gRegisterAddress_c;
andreikovacs 0:4eb2240dbd22 1924 aspTestRequestMsg.msgData.aspXcvrData.mode = !bIsRegisterDirect;
andreikovacs 0:4eb2240dbd22 1925 FLib_MemCpy(aspTestRequestMsg.msgData.aspXcvrData.data, &rsRegValue, gRegisterSize_c);
andreikovacs 0:4eb2240dbd22 1926 APP_ASP_SapHandler(&aspTestRequestMsg, 0);
andreikovacs 0:4eb2240dbd22 1927
andreikovacs 0:4eb2240dbd22 1928 uart.printf("\r\n Register overridden \r\n");
andreikovacs 0:4eb2240dbd22 1929 u8Index = 0;
andreikovacs 0:4eb2240dbd22 1930 oRState = gORStateStart_c;
andreikovacs 0:4eb2240dbd22 1931 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1932 }
andreikovacs 0:4eb2240dbd22 1933 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1934 }
andreikovacs 0:4eb2240dbd22 1935 break;
andreikovacs 0:4eb2240dbd22 1936 default:
andreikovacs 0:4eb2240dbd22 1937 break;
andreikovacs 0:4eb2240dbd22 1938 }
andreikovacs 0:4eb2240dbd22 1939 return bBackFlag;
andreikovacs 0:4eb2240dbd22 1940 }
andreikovacs 0:4eb2240dbd22 1941
andreikovacs 0:4eb2240dbd22 1942 /************************************************************************************
andreikovacs 0:4eb2240dbd22 1943 *
andreikovacs 0:4eb2240dbd22 1944 * Handler for Carrier Sense Test and Transmission Control Test
andreikovacs 0:4eb2240dbd22 1945 *
andreikovacs 0:4eb2240dbd22 1946 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 1947 bool_t CSenseAndTCtrl(void)
andreikovacs 0:4eb2240dbd22 1948 {
andreikovacs 0:4eb2240dbd22 1949 bool_t bBackFlag = FALSE;
andreikovacs 0:4eb2240dbd22 1950 static uint8_t testSelector = 0;
andreikovacs 0:4eb2240dbd22 1951
andreikovacs 0:4eb2240dbd22 1952 if(evTestParameters){
andreikovacs 0:4eb2240dbd22 1953 (void)MLMESetChannelRequest(testChannel);
andreikovacs 0:4eb2240dbd22 1954 #if CT_Feature_Calibration
andreikovacs 0:4eb2240dbd22 1955 (void)MLMESetAdditionalRFOffset(gOffsetIncrement);
andreikovacs 0:4eb2240dbd22 1956 #endif
andreikovacs 0:4eb2240dbd22 1957 (void)MLMEPAOutputAdjust(testPower);
andreikovacs 0:4eb2240dbd22 1958 PrintTestParameters(TRUE);
andreikovacs 0:4eb2240dbd22 1959 evTestParameters = FALSE;
andreikovacs 0:4eb2240dbd22 1960 }
andreikovacs 0:4eb2240dbd22 1961
andreikovacs 0:4eb2240dbd22 1962 switch(cstcState)
andreikovacs 0:4eb2240dbd22 1963 {
andreikovacs 0:4eb2240dbd22 1964 case gCsTcStateInit_c:
andreikovacs 0:4eb2240dbd22 1965 TestMode(gTestModeForceIdle_c);
andreikovacs 0:4eb2240dbd22 1966 PrintMenu(cu8ShortCutsBar, mAppSer);
andreikovacs 0:4eb2240dbd22 1967 PrintMenu(cu8RadioCSTCSelectMenu, mAppSer);
andreikovacs 0:4eb2240dbd22 1968 PrintTestParameters(FALSE);
andreikovacs 0:4eb2240dbd22 1969 shortCutsEnabled = TRUE;
andreikovacs 0:4eb2240dbd22 1970 bTxDone = FALSE;
andreikovacs 0:4eb2240dbd22 1971 bScanDone = FALSE;
andreikovacs 0:4eb2240dbd22 1972 timePassed = FALSE;
andreikovacs 0:4eb2240dbd22 1973
andreikovacs 0:4eb2240dbd22 1974 cstcState = gCsTcStateSelectTest_c;
andreikovacs 0:4eb2240dbd22 1975 break;
andreikovacs 0:4eb2240dbd22 1976 case gCsTcStateSelectTest_c:
andreikovacs 0:4eb2240dbd22 1977 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 1978 {
andreikovacs 0:4eb2240dbd22 1979 if('1' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1980 {
andreikovacs 0:4eb2240dbd22 1981 cstcState = gCsTcStateCarrierSenseStart_c;
andreikovacs 0:4eb2240dbd22 1982 testSelector = 1;
andreikovacs 0:4eb2240dbd22 1983 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1984 }
andreikovacs 0:4eb2240dbd22 1985 else if ('2' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1986 {
andreikovacs 0:4eb2240dbd22 1987 cstcState = gCsTcStateTransmissionControlStart_c;
andreikovacs 0:4eb2240dbd22 1988 testSelector = 2;
andreikovacs 0:4eb2240dbd22 1989 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 1990 }
andreikovacs 0:4eb2240dbd22 1991 else if( 'p' == gu8UartData)
andreikovacs 0:4eb2240dbd22 1992 {
andreikovacs 0:4eb2240dbd22 1993 cstcState = gCsTcStateInit_c;
andreikovacs 0:4eb2240dbd22 1994 testSelector = 0;
andreikovacs 0:4eb2240dbd22 1995 bBackFlag = TRUE;
andreikovacs 0:4eb2240dbd22 1996 }
andreikovacs 0:4eb2240dbd22 1997 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 1998 }
andreikovacs 0:4eb2240dbd22 1999 break;
andreikovacs 0:4eb2240dbd22 2000 default:
andreikovacs 0:4eb2240dbd22 2001 if(testSelector == 1)
andreikovacs 0:4eb2240dbd22 2002 CarrierSenseHandler();
andreikovacs 0:4eb2240dbd22 2003 else if(testSelector == 2)
andreikovacs 0:4eb2240dbd22 2004 TransmissionControlHandler();
andreikovacs 0:4eb2240dbd22 2005 break;
andreikovacs 0:4eb2240dbd22 2006 }
andreikovacs 0:4eb2240dbd22 2007 return bBackFlag;
andreikovacs 0:4eb2240dbd22 2008 }
andreikovacs 0:4eb2240dbd22 2009
andreikovacs 0:4eb2240dbd22 2010 /************************************************************************************
andreikovacs 0:4eb2240dbd22 2011 *
andreikovacs 0:4eb2240dbd22 2012 * Handler for Transmission Control Test called by above function
andreikovacs 0:4eb2240dbd22 2013 *
andreikovacs 0:4eb2240dbd22 2014 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 2015 void TransmissionControlHandler(void)
andreikovacs 0:4eb2240dbd22 2016 {
andreikovacs 0:4eb2240dbd22 2017 const uint16_t u16TotalPacketsOptions[] = {1,25,100,500,1000,2000,5000,10000,65535};
andreikovacs 0:4eb2240dbd22 2018 static uint16_t u16TotalPackets;
andreikovacs 0:4eb2240dbd22 2019 static uint16_t u16PacketCounter = 0;
andreikovacs 0:4eb2240dbd22 2020 static uint16_t miliSecDelay = 0;
andreikovacs 0:4eb2240dbd22 2021 static phyTime_t startTime;
andreikovacs 0:4eb2240dbd22 2022 int8_t fillIndex = 0;
andreikovacs 0:4eb2240dbd22 2023 uint8_t* smacPduPtr;
andreikovacs 0:4eb2240dbd22 2024 uint32_t totalTimeMs;
andreikovacs 0:4eb2240dbd22 2025
andreikovacs 0:4eb2240dbd22 2026 switch(cstcState)
andreikovacs 0:4eb2240dbd22 2027 {
andreikovacs 0:4eb2240dbd22 2028 case gCsTcStateTransmissionControlStart_c:
andreikovacs 0:4eb2240dbd22 2029 PrintMenu(cu8ShortCutsBar, mAppSer);
andreikovacs 0:4eb2240dbd22 2030 PrintMenu(cu8CsTcTestMenu, mAppSer);
andreikovacs 0:4eb2240dbd22 2031 PrintTestParameters(FALSE);
andreikovacs 0:4eb2240dbd22 2032 miliSecDelay = 0;
andreikovacs 0:4eb2240dbd22 2033 u16TotalPackets = 0;
andreikovacs 0:4eb2240dbd22 2034 u16PacketCounter = 0;
andreikovacs 0:4eb2240dbd22 2035 fillIndex = testPayloadLen / gPrbs9BufferLength_c;
andreikovacs 0:4eb2240dbd22 2036
andreikovacs 0:4eb2240dbd22 2037 while(fillIndex > 0)
andreikovacs 0:4eb2240dbd22 2038 {
andreikovacs 0:4eb2240dbd22 2039 fillIndex--;
andreikovacs 0:4eb2240dbd22 2040 smacPduPtr = gAppTxPacket->smacPdu.smacPdu + fillIndex * gPrbs9BufferLength_c;
andreikovacs 0:4eb2240dbd22 2041 FLib_MemCpy(smacPduPtr, u8Prbs9Buffer, gPrbs9BufferLength_c);
andreikovacs 0:4eb2240dbd22 2042 }
andreikovacs 0:4eb2240dbd22 2043 smacPduPtr = gAppTxPacket->smacPdu.smacPdu + ((testPayloadLen / gPrbs9BufferLength_c)*gPrbs9BufferLength_c);
andreikovacs 0:4eb2240dbd22 2044 FLib_MemCpy(smacPduPtr, u8Prbs9Buffer, (testPayloadLen % gPrbs9BufferLength_c));
andreikovacs 0:4eb2240dbd22 2045
andreikovacs 0:4eb2240dbd22 2046 gAppTxPacket->u8DataLength = testPayloadLen;
andreikovacs 0:4eb2240dbd22 2047
andreikovacs 0:4eb2240dbd22 2048 cstcState = gCsTcStateTransmissionControlSelectNumOfPackets_c;
andreikovacs 0:4eb2240dbd22 2049 break;
andreikovacs 0:4eb2240dbd22 2050 case gCsTcStateTransmissionControlSelectNumOfPackets_c:
andreikovacs 0:4eb2240dbd22 2051 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 2052 {
andreikovacs 0:4eb2240dbd22 2053 if((gu8UartData >= '0') && (gu8UartData <= '8'))
andreikovacs 0:4eb2240dbd22 2054 {
andreikovacs 0:4eb2240dbd22 2055 u16TotalPackets = u16TotalPacketsOptions[gu8UartData - '0'];
andreikovacs 0:4eb2240dbd22 2056 cstcState = gCsTcStateTransmissionControlSelectInterpacketDelay_c;
andreikovacs 0:4eb2240dbd22 2057 uart.printf("\r\n\r\n Please type InterPacket delay in miliseconds and press [ENTER]");
andreikovacs 0:4eb2240dbd22 2058 uart.printf("\r\n(During test, exit by pressing [SPACE])\r\n\r\n");
andreikovacs 0:4eb2240dbd22 2059 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 2060 }
andreikovacs 0:4eb2240dbd22 2061 else if('p' == gu8UartData)
andreikovacs 0:4eb2240dbd22 2062 {
andreikovacs 0:4eb2240dbd22 2063 cstcState = gCsTcStateInit_c;
andreikovacs 0:4eb2240dbd22 2064 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 2065 }
andreikovacs 0:4eb2240dbd22 2066 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 2067 }
andreikovacs 0:4eb2240dbd22 2068 break;
andreikovacs 0:4eb2240dbd22 2069 case gCsTcStateTransmissionControlSelectInterpacketDelay_c:
andreikovacs 0:4eb2240dbd22 2070 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 2071 {
andreikovacs 0:4eb2240dbd22 2072 if(gu8UartData == '\r' && miliSecDelay != 0)
andreikovacs 0:4eb2240dbd22 2073 {
andreikovacs 0:4eb2240dbd22 2074 cstcState = gCsTcStateTransmissionControlPerformingTest_c;
andreikovacs 0:4eb2240dbd22 2075 startTime = GetTimestampUS();
andreikovacs 0:4eb2240dbd22 2076 (void)MLMEScanRequest(testChannel);
andreikovacs 0:4eb2240dbd22 2077 }
andreikovacs 0:4eb2240dbd22 2078 else if((gu8UartData >= '0') && (gu8UartData <='9'))
andreikovacs 0:4eb2240dbd22 2079 {
andreikovacs 0:4eb2240dbd22 2080 miliSecDelay = miliSecDelay*10 + (gu8UartData - '0');
andreikovacs 0:4eb2240dbd22 2081 uart.printf("%d",(uint32_t)(gu8UartData - '0'));
andreikovacs 0:4eb2240dbd22 2082 }
andreikovacs 0:4eb2240dbd22 2083 else if('p' == gu8UartData)
andreikovacs 0:4eb2240dbd22 2084 {
andreikovacs 0:4eb2240dbd22 2085 cstcState = gCsTcStateInit_c;
andreikovacs 0:4eb2240dbd22 2086 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 2087 }
andreikovacs 0:4eb2240dbd22 2088 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 2089 }
andreikovacs 0:4eb2240dbd22 2090 break;
andreikovacs 0:4eb2240dbd22 2091 case gCsTcStateTransmissionControlPerformingTest_c:
andreikovacs 0:4eb2240dbd22 2092 if(bScanDone)
andreikovacs 0:4eb2240dbd22 2093 {
andreikovacs 0:4eb2240dbd22 2094 bScanDone = FALSE;
andreikovacs 0:4eb2240dbd22 2095 (void)MCPSDataRequest(gAppTxPacket);
andreikovacs 0:4eb2240dbd22 2096 }
andreikovacs 0:4eb2240dbd22 2097 if(bTxDone)
andreikovacs 0:4eb2240dbd22 2098 {
andreikovacs 0:4eb2240dbd22 2099 bTxDone = FALSE;
andreikovacs 0:4eb2240dbd22 2100 u16PacketCounter++;
andreikovacs 0:4eb2240dbd22 2101 uart.printf("\r\n\tPacket number: ");
andreikovacs 0:4eb2240dbd22 2102 uart.printf("%d", (uint32_t)(u16PacketCounter));
andreikovacs 0:4eb2240dbd22 2103 uart.printf("; RSSI value: -");
andreikovacs 0:4eb2240dbd22 2104 uart.printf("%d",(uint32_t)au8ScanResults[testChannel]);
andreikovacs 0:4eb2240dbd22 2105 uart.printf(" dBm\r\n");
andreikovacs 0:4eb2240dbd22 2106 if(u16PacketCounter < u16TotalPackets)
andreikovacs 0:4eb2240dbd22 2107 {
andreikovacs 0:4eb2240dbd22 2108 totalTimeMs = (uint32_t)(GetTimestampUS() - startTime);
andreikovacs 0:4eb2240dbd22 2109 totalTimeMs -= GetTransmissionTime(testPayloadLen, crtBitrate);
andreikovacs 0:4eb2240dbd22 2110 totalTimeMs = (totalTimeMs % 1000 < 500) ? totalTimeMs/1000 : (totalTimeMs/1000)+1;
andreikovacs 0:4eb2240dbd22 2111 if(totalTimeMs > miliSecDelay)
andreikovacs 0:4eb2240dbd22 2112 {
andreikovacs 0:4eb2240dbd22 2113 uart.printf( " Overhead + Transmission + ED = ~");
andreikovacs 0:4eb2240dbd22 2114 uart.printf("%d", totalTimeMs);
andreikovacs 0:4eb2240dbd22 2115 uart.printf("ms\r\n Interpacket delay too small (Press [ENTER] to continue)\r\n");
andreikovacs 0:4eb2240dbd22 2116 cstcState = gCsTcStateTransmissionControlEndTest_c;
andreikovacs 0:4eb2240dbd22 2117 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 2118 break;
andreikovacs 0:4eb2240dbd22 2119 }
andreikovacs 0:4eb2240dbd22 2120 Thread::wait(miliSecDelay - totalTimeMs);
andreikovacs 0:4eb2240dbd22 2121 }
andreikovacs 0:4eb2240dbd22 2122 else
andreikovacs 0:4eb2240dbd22 2123 {
andreikovacs 0:4eb2240dbd22 2124 uart.printf("\r\n\r\nFinished transmitting ");
andreikovacs 0:4eb2240dbd22 2125 uart.printf("%d", (uint32_t)u16TotalPackets);
andreikovacs 0:4eb2240dbd22 2126 uart.printf(" packets!\r\n\r\n");
andreikovacs 0:4eb2240dbd22 2127 uart.printf("\r\n -Press [ENTER] to end Transmission Control Test");
andreikovacs 0:4eb2240dbd22 2128 cstcState = gCsTcStateTransmissionControlEndTest_c;
andreikovacs 0:4eb2240dbd22 2129 }
andreikovacs 0:4eb2240dbd22 2130 }
andreikovacs 0:4eb2240dbd22 2131 if(timePassed)
andreikovacs 0:4eb2240dbd22 2132 {
andreikovacs 0:4eb2240dbd22 2133 timePassed = FALSE;
andreikovacs 0:4eb2240dbd22 2134 startTime = GetTimestampUS();
andreikovacs 0:4eb2240dbd22 2135 (void)MLMEScanRequest(testChannel);
andreikovacs 0:4eb2240dbd22 2136 }
andreikovacs 0:4eb2240dbd22 2137 if(evDataFromUART && gu8UartData == ' ')
andreikovacs 0:4eb2240dbd22 2138 {
andreikovacs 0:4eb2240dbd22 2139 uart.printf("\r\n\r\n-Test interrupted by user. Press [ENTER] to continue\r\n\r\n");
andreikovacs 0:4eb2240dbd22 2140 cstcState = gCsTcStateTransmissionControlEndTest_c;
andreikovacs 0:4eb2240dbd22 2141 }
andreikovacs 0:4eb2240dbd22 2142 break;
andreikovacs 0:4eb2240dbd22 2143 case gCsTcStateTransmissionControlEndTest_c:
andreikovacs 0:4eb2240dbd22 2144 if(evDataFromUART && gu8UartData == '\r')
andreikovacs 0:4eb2240dbd22 2145 {
andreikovacs 0:4eb2240dbd22 2146 cstcState = gCsTcStateInit_c;
andreikovacs 0:4eb2240dbd22 2147 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 2148 }
andreikovacs 0:4eb2240dbd22 2149 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 2150 break;
andreikovacs 0:4eb2240dbd22 2151 }
andreikovacs 0:4eb2240dbd22 2152 }
andreikovacs 0:4eb2240dbd22 2153 /************************************************************************************
andreikovacs 0:4eb2240dbd22 2154 *
andreikovacs 0:4eb2240dbd22 2155 * Handler for Carrier Sense Test
andreikovacs 0:4eb2240dbd22 2156 *
andreikovacs 0:4eb2240dbd22 2157 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 2158 void CarrierSenseHandler(void)
andreikovacs 0:4eb2240dbd22 2159 {
andreikovacs 0:4eb2240dbd22 2160 int8_t fillIndex = 0;
andreikovacs 0:4eb2240dbd22 2161 uint8_t* smacPduPtr;
andreikovacs 0:4eb2240dbd22 2162 switch(cstcState)
andreikovacs 0:4eb2240dbd22 2163 {
andreikovacs 0:4eb2240dbd22 2164 case gCsTcStateCarrierSenseStart_c:
andreikovacs 0:4eb2240dbd22 2165 #if CT_Feature_Calibration
andreikovacs 0:4eb2240dbd22 2166 if( gMode1Bitrate_c == crtBitrate )
andreikovacs 0:4eb2240dbd22 2167 {
andreikovacs 0:4eb2240dbd22 2168 (void)MLMESetAdditionalRFOffset(gOffsetIncrement + 30);
andreikovacs 0:4eb2240dbd22 2169 }
andreikovacs 0:4eb2240dbd22 2170 else
andreikovacs 0:4eb2240dbd22 2171 {
andreikovacs 0:4eb2240dbd22 2172 (void)MLMESetAdditionalRFOffset(gOffsetIncrement + 60);
andreikovacs 0:4eb2240dbd22 2173 }
andreikovacs 0:4eb2240dbd22 2174 #endif
andreikovacs 0:4eb2240dbd22 2175 (void)MLMESetChannelRequest(testChannel);
andreikovacs 0:4eb2240dbd22 2176
andreikovacs 0:4eb2240dbd22 2177 uart.printf( "\r\n\r\n Press [SPACE] to begin/interrupt test");
andreikovacs 0:4eb2240dbd22 2178 uart.printf( "\r\n Press [p] to return to previous menu");
andreikovacs 0:4eb2240dbd22 2179 // PrintTestParameters(FALSE);
andreikovacs 0:4eb2240dbd22 2180 shortCutsEnabled = FALSE;
andreikovacs 0:4eb2240dbd22 2181 uart.printf("\r\n");
andreikovacs 0:4eb2240dbd22 2182
andreikovacs 0:4eb2240dbd22 2183 fillIndex = testPayloadLen / gPrbs9BufferLength_c;
andreikovacs 0:4eb2240dbd22 2184 while(fillIndex > 0)
andreikovacs 0:4eb2240dbd22 2185 {
andreikovacs 0:4eb2240dbd22 2186 fillIndex--;
andreikovacs 0:4eb2240dbd22 2187 smacPduPtr = gAppTxPacket->smacPdu.smacPdu + fillIndex * gPrbs9BufferLength_c;
andreikovacs 0:4eb2240dbd22 2188 FLib_MemCpy(smacPduPtr, u8Prbs9Buffer, gPrbs9BufferLength_c);
andreikovacs 0:4eb2240dbd22 2189 }
andreikovacs 0:4eb2240dbd22 2190 smacPduPtr = gAppTxPacket->smacPdu.smacPdu + ((testPayloadLen / gPrbs9BufferLength_c)*gPrbs9BufferLength_c);
andreikovacs 0:4eb2240dbd22 2191 FLib_MemCpy(smacPduPtr, u8Prbs9Buffer, (testPayloadLen % gPrbs9BufferLength_c));
andreikovacs 0:4eb2240dbd22 2192
andreikovacs 0:4eb2240dbd22 2193 gAppTxPacket->u8DataLength = testPayloadLen;
andreikovacs 0:4eb2240dbd22 2194
andreikovacs 0:4eb2240dbd22 2195 cstcState = gCsTcStateCarrierSenseSelectType_c;
andreikovacs 0:4eb2240dbd22 2196 break;
andreikovacs 0:4eb2240dbd22 2197 case gCsTcStateCarrierSenseSelectType_c:
andreikovacs 0:4eb2240dbd22 2198 if(evDataFromUART)
andreikovacs 0:4eb2240dbd22 2199 {
andreikovacs 0:4eb2240dbd22 2200 if(' ' == gu8UartData)
andreikovacs 0:4eb2240dbd22 2201 {
andreikovacs 0:4eb2240dbd22 2202 cstcState = gCsTcStateCarrierSensePerformingTest_c;
andreikovacs 0:4eb2240dbd22 2203 (void)MLMEScanRequest(testChannel);
andreikovacs 0:4eb2240dbd22 2204 }
andreikovacs 0:4eb2240dbd22 2205 else if ('p' == gu8UartData)
andreikovacs 0:4eb2240dbd22 2206 {
andreikovacs 0:4eb2240dbd22 2207 #if CT_Feature_Calibration
andreikovacs 0:4eb2240dbd22 2208 (void)MLMESetAdditionalRFOffset(gOffsetIncrement);
andreikovacs 0:4eb2240dbd22 2209 #endif
andreikovacs 0:4eb2240dbd22 2210 (void)MLMESetChannelRequest(testChannel);
andreikovacs 0:4eb2240dbd22 2211 cstcState = gCsTcStateInit_c;
andreikovacs 0:4eb2240dbd22 2212 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 2213 }
andreikovacs 0:4eb2240dbd22 2214 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 2215 }
andreikovacs 0:4eb2240dbd22 2216 break;
andreikovacs 0:4eb2240dbd22 2217 case gCsTcStateCarrierSensePerformingTest_c:
andreikovacs 0:4eb2240dbd22 2218 if(bScanDone)
andreikovacs 0:4eb2240dbd22 2219 {
andreikovacs 0:4eb2240dbd22 2220 bScanDone = FALSE;
andreikovacs 0:4eb2240dbd22 2221 uart.printf( "\r\n\tSampling done. RSSI value: -");
andreikovacs 0:4eb2240dbd22 2222 uart.printf("%d", (uint32_t) au8ScanResults[testChannel]);
andreikovacs 0:4eb2240dbd22 2223 uart.printf( "dBm");
andreikovacs 0:4eb2240dbd22 2224 if(au8ScanResults[testChannel] > ccaThresh)
andreikovacs 0:4eb2240dbd22 2225 {
andreikovacs 0:4eb2240dbd22 2226 (void)MCPSDataRequest(gAppTxPacket);
andreikovacs 0:4eb2240dbd22 2227 }
andreikovacs 0:4eb2240dbd22 2228 else
andreikovacs 0:4eb2240dbd22 2229 {
andreikovacs 0:4eb2240dbd22 2230 (void)MLMEScanRequest(testChannel);
andreikovacs 0:4eb2240dbd22 2231 }
andreikovacs 0:4eb2240dbd22 2232 }
andreikovacs 0:4eb2240dbd22 2233 if(bTxDone)
andreikovacs 0:4eb2240dbd22 2234 {
andreikovacs 0:4eb2240dbd22 2235 bTxDone = FALSE;
andreikovacs 0:4eb2240dbd22 2236
andreikovacs 0:4eb2240dbd22 2237 uart.printf("\r\n Transmission Performed\r\n");
andreikovacs 0:4eb2240dbd22 2238 uart.printf("\r\n -Press [ENTER] to end Carrier Sense Test");
andreikovacs 0:4eb2240dbd22 2239 cstcState = gCsTcStateCarrierSenseEndTest_c;
andreikovacs 0:4eb2240dbd22 2240 }
andreikovacs 0:4eb2240dbd22 2241 if(evDataFromUART && gu8UartData == ' ')
andreikovacs 0:4eb2240dbd22 2242 {
andreikovacs 0:4eb2240dbd22 2243 uart.printf("\r\n\r\n-Test interrupted by user. Press [ENTER] to continue\r\n\r\n");
andreikovacs 0:4eb2240dbd22 2244 cstcState = gCsTcStateCarrierSenseEndTest_c;
andreikovacs 0:4eb2240dbd22 2245 }
andreikovacs 0:4eb2240dbd22 2246 break;
andreikovacs 0:4eb2240dbd22 2247 case gCsTcStateCarrierSenseEndTest_c:
andreikovacs 0:4eb2240dbd22 2248 if(evDataFromUART && gu8UartData == '\r')
andreikovacs 0:4eb2240dbd22 2249 {
andreikovacs 0:4eb2240dbd22 2250 #if CT_Feature_Calibration
andreikovacs 0:4eb2240dbd22 2251 (void)MLMESetAdditionalRFOffset(gOffsetIncrement);
andreikovacs 0:4eb2240dbd22 2252 #endif
andreikovacs 0:4eb2240dbd22 2253 (void)MLMESetChannelRequest(testChannel);
andreikovacs 0:4eb2240dbd22 2254 cstcState = gCsTcStateInit_c;
andreikovacs 0:4eb2240dbd22 2255 SelfNotificationEvent();
andreikovacs 0:4eb2240dbd22 2256 }
andreikovacs 0:4eb2240dbd22 2257 evDataFromUART = FALSE;
andreikovacs 0:4eb2240dbd22 2258 break;
andreikovacs 0:4eb2240dbd22 2259 }
andreikovacs 0:4eb2240dbd22 2260 }
andreikovacs 0:4eb2240dbd22 2261
andreikovacs 0:4eb2240dbd22 2262 /************************************************************************************
andreikovacs 0:4eb2240dbd22 2263 *
andreikovacs 0:4eb2240dbd22 2264 * Auxiliary Functions
andreikovacs 0:4eb2240dbd22 2265 *
andreikovacs 0:4eb2240dbd22 2266 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 2267
andreikovacs 0:4eb2240dbd22 2268 /**************************************************************************************/
andreikovacs 0:4eb2240dbd22 2269 void SetRadioRxOnNoTimeOut(void)
andreikovacs 0:4eb2240dbd22 2270 {
andreikovacs 0:4eb2240dbd22 2271 bRxDone = FALSE;
andreikovacs 0:4eb2240dbd22 2272 gAppRxPacket->u8MaxDataLength = gMaxSmacSDULength_c;
andreikovacs 0:4eb2240dbd22 2273 (void)MLMERXEnableRequest(gAppRxPacket, 0);
andreikovacs 0:4eb2240dbd22 2274 }
andreikovacs 0:4eb2240dbd22 2275
andreikovacs 0:4eb2240dbd22 2276 /**************************************************************************************/
andreikovacs 0:4eb2240dbd22 2277 void PrintPerRxFinalLine(uint16_t u16Received, uint16_t u16Total)
andreikovacs 0:4eb2240dbd22 2278 {
andreikovacs 0:4eb2240dbd22 2279 uart.printf("Received ");
andreikovacs 0:4eb2240dbd22 2280 uart.printf("%d",(uint32_t)u16Received);
andreikovacs 0:4eb2240dbd22 2281 uart.printf(" of ");
andreikovacs 0:4eb2240dbd22 2282 uart.printf("%d",(uint32_t)u16Total);
andreikovacs 0:4eb2240dbd22 2283 uart.printf(" packets transmitted \r\n");
andreikovacs 0:4eb2240dbd22 2284 uart.printf("\r\n Press [enter] to go back to the Per Rx test menu");
andreikovacs 0:4eb2240dbd22 2285 }
andreikovacs 0:4eb2240dbd22 2286
andreikovacs 0:4eb2240dbd22 2287 /************************************************************************************
andreikovacs 0:4eb2240dbd22 2288 *
andreikovacs 0:4eb2240dbd22 2289 *
andreikovacs 0:4eb2240dbd22 2290 * By employing this function, users can execute a test of the radio. Test mode
andreikovacs 0:4eb2240dbd22 2291 * implements the following:
andreikovacs 0:4eb2240dbd22 2292 * -PRBS9 Mode,
andreikovacs 0:4eb2240dbd22 2293 * -Force_idle,
andreikovacs 0:4eb2240dbd22 2294 * -Continuos TX without modulation,
andreikovacs 0:4eb2240dbd22 2295 * -Continuos TX with modulation.(0's,1's and PN patterns)
andreikovacs 0:4eb2240dbd22 2296 *
andreikovacs 0:4eb2240dbd22 2297 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 2298 smacErrors_t TestMode
andreikovacs 0:4eb2240dbd22 2299 (
andreikovacs 0:4eb2240dbd22 2300 smacTestMode_t mode /*IN: The test mode to start.*/
andreikovacs 0:4eb2240dbd22 2301 )
andreikovacs 0:4eb2240dbd22 2302 {
andreikovacs 0:4eb2240dbd22 2303 aspTestRequestMsg.msgType = aspMsgTypeTelecTest_c;
andreikovacs 0:4eb2240dbd22 2304
andreikovacs 0:4eb2240dbd22 2305 #if(TRUE == smacParametersValidation_d)
andreikovacs 0:4eb2240dbd22 2306 if(gMaxTestMode_c <= mode)
andreikovacs 0:4eb2240dbd22 2307 {
andreikovacs 0:4eb2240dbd22 2308 return gErrorOutOfRange_c;
andreikovacs 0:4eb2240dbd22 2309 }
andreikovacs 0:4eb2240dbd22 2310 #endif
andreikovacs 0:4eb2240dbd22 2311
andreikovacs 0:4eb2240dbd22 2312 if(gTestModeForceIdle_c == mode)
andreikovacs 0:4eb2240dbd22 2313 {
andreikovacs 0:4eb2240dbd22 2314 aspTestRequestMsg.msgData.aspTelecTest.mode = gTestForceIdle_c;
andreikovacs 0:4eb2240dbd22 2315 }
andreikovacs 0:4eb2240dbd22 2316 else if(gTestModeContinuousTxModulated_c == mode)
andreikovacs 0:4eb2240dbd22 2317 {
andreikovacs 0:4eb2240dbd22 2318 if(contTxModBitValue==gContTxModSelectOnes_c)
andreikovacs 0:4eb2240dbd22 2319 {
andreikovacs 0:4eb2240dbd22 2320 aspTestRequestMsg.msgData.aspTelecTest.mode = gTestContinuousTxModOne_c;
andreikovacs 0:4eb2240dbd22 2321 }
andreikovacs 0:4eb2240dbd22 2322 else if(contTxModBitValue == gContTxModSelectZeros_c)
andreikovacs 0:4eb2240dbd22 2323 {
andreikovacs 0:4eb2240dbd22 2324 aspTestRequestMsg.msgData.aspTelecTest.mode = gTestContinuousTxModZero_c;
andreikovacs 0:4eb2240dbd22 2325 }
andreikovacs 0:4eb2240dbd22 2326 else if(contTxModBitValue == gContTxModSelectPN9_c)
andreikovacs 0:4eb2240dbd22 2327 {
andreikovacs 0:4eb2240dbd22 2328 #ifdef gPHY_802_15_4g_d
andreikovacs 0:4eb2240dbd22 2329 aspTestRequestMsg.msgData.aspTelecTest.mode = gTestContinuousTxContPN9_c;
andreikovacs 0:4eb2240dbd22 2330 #else
andreikovacs 0:4eb2240dbd22 2331 aspTestRequestMsg.msgData.aspTelecTest.mode = gTestPulseTxPrbs9_c;
andreikovacs 0:4eb2240dbd22 2332 #endif
andreikovacs 0:4eb2240dbd22 2333 }
andreikovacs 0:4eb2240dbd22 2334 }
andreikovacs 0:4eb2240dbd22 2335 else if(gTestModeContinuousTxUnmodulated_c == mode)
andreikovacs 0:4eb2240dbd22 2336 {
andreikovacs 0:4eb2240dbd22 2337 aspTestRequestMsg.msgData.aspTelecTest.mode = gTestContinuousTxNoMod_c;
andreikovacs 0:4eb2240dbd22 2338 }
andreikovacs 0:4eb2240dbd22 2339 else if(gTestModeContinuousRxBER_c == mode)
andreikovacs 0:4eb2240dbd22 2340 {
andreikovacs 0:4eb2240dbd22 2341 aspTestRequestMsg.msgData.aspTelecTest.mode = gTestContinuousRx_c;
andreikovacs 0:4eb2240dbd22 2342 }
andreikovacs 0:4eb2240dbd22 2343 else if(gTestModePRBS9_c == mode)
andreikovacs 0:4eb2240dbd22 2344 {
andreikovacs 0:4eb2240dbd22 2345 /*Set Data Mode*/
andreikovacs 0:4eb2240dbd22 2346 gAppTxPacket->u8DataLength = gPrbs9BufferLength_c;
andreikovacs 0:4eb2240dbd22 2347 FLib_MemCpy(gAppTxPacket->smacPdu.smacPdu, u8Prbs9Buffer, gPrbs9BufferLength_c);
andreikovacs 0:4eb2240dbd22 2348 PacketHandler_Prbs9();
andreikovacs 0:4eb2240dbd22 2349 }
andreikovacs 0:4eb2240dbd22 2350 if(gTestModePRBS9_c != mode)
andreikovacs 0:4eb2240dbd22 2351 (void)APP_ASP_SapHandler(&aspTestRequestMsg, 0);
andreikovacs 0:4eb2240dbd22 2352
andreikovacs 0:4eb2240dbd22 2353 return gErrorNoError_c;
andreikovacs 0:4eb2240dbd22 2354 }
andreikovacs 0:4eb2240dbd22 2355
andreikovacs 0:4eb2240dbd22 2356 /************************************************************************************
andreikovacs 0:4eb2240dbd22 2357 * PacketHandler_Prbs9
andreikovacs 0:4eb2240dbd22 2358 *
andreikovacs 0:4eb2240dbd22 2359 * This function sends OTA the content of a PRBS9 polynomial of 65 bytes of payload.
andreikovacs 0:4eb2240dbd22 2360 *
andreikovacs 0:4eb2240dbd22 2361 *
andreikovacs 0:4eb2240dbd22 2362 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 2363
andreikovacs 0:4eb2240dbd22 2364 void PacketHandler_Prbs9(void)
andreikovacs 0:4eb2240dbd22 2365 {
andreikovacs 0:4eb2240dbd22 2366 smacErrors_t err;
andreikovacs 0:4eb2240dbd22 2367 /*@CMA, Need to set Smac to Idle in order to get PRBS9 to work after a second try on the Conn Test menu*/
andreikovacs 0:4eb2240dbd22 2368 (void)MLMERXDisableRequest();
andreikovacs 0:4eb2240dbd22 2369 (void)MLMETXDisableRequest();
andreikovacs 0:4eb2240dbd22 2370 err = MCPSDataRequest(gAppTxPacket);
andreikovacs 0:4eb2240dbd22 2371 if(err != gErrorNoError_c)
andreikovacs 0:4eb2240dbd22 2372 {
andreikovacs 0:4eb2240dbd22 2373 failedPRBS9 = TRUE;
andreikovacs 0:4eb2240dbd22 2374 SelfNotificationEvent(); //in case data isn't sent, no confirm event will fire.
andreikovacs 0:4eb2240dbd22 2375 //this way we need to make sure the application will not freeze.
andreikovacs 0:4eb2240dbd22 2376 }
andreikovacs 0:4eb2240dbd22 2377 }
andreikovacs 0:4eb2240dbd22 2378
andreikovacs 0:4eb2240dbd22 2379 /*****************************************************************************
andreikovacs 0:4eb2240dbd22 2380 * UartRxCallBack function
andreikovacs 0:4eb2240dbd22 2381 *
andreikovacs 0:4eb2240dbd22 2382 * Interface assumptions:
andreikovacs 0:4eb2240dbd22 2383 * This callback is triggered when a new byte is received over the UART
andreikovacs 0:4eb2240dbd22 2384 *
andreikovacs 0:4eb2240dbd22 2385 * Return Value:
andreikovacs 0:4eb2240dbd22 2386 * None
andreikovacs 0:4eb2240dbd22 2387 *****************************************************************************/
andreikovacs 0:4eb2240dbd22 2388 void UartRxCallBack(void * param)
andreikovacs 0:4eb2240dbd22 2389 {
andreikovacs 0:4eb2240dbd22 2390 uint16_t readBytes;
andreikovacs 0:4eb2240dbd22 2391 gu8UartData = uart.getc();
andreikovacs 0:4eb2240dbd22 2392 gTaskEventFlags |= gUART_RX_EVENT_c;
andreikovacs 0:4eb2240dbd22 2393 }
andreikovacs 0:4eb2240dbd22 2394
andreikovacs 0:4eb2240dbd22 2395 /*@CMA, Conn Test. Range Test CallBack*/
andreikovacs 0:4eb2240dbd22 2396 void RangeTest_Timer_CallBack ()
andreikovacs 0:4eb2240dbd22 2397 {
andreikovacs 0:4eb2240dbd22 2398 gTaskEventFlags |= gRangeTest_EVENT_c;
andreikovacs 0:4eb2240dbd22 2399 }
andreikovacs 0:4eb2240dbd22 2400
andreikovacs 0:4eb2240dbd22 2401
andreikovacs 0:4eb2240dbd22 2402
andreikovacs 0:4eb2240dbd22 2403 /************************************************************************************
andreikovacs 0:4eb2240dbd22 2404 *
andreikovacs 0:4eb2240dbd22 2405 * Increments channel on the ED Confirm event and fires a new ED measurement request
andreikovacs 0:4eb2240dbd22 2406 *
andreikovacs 0:4eb2240dbd22 2407 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 2408 void IncrementChannelOnEdEvent()
andreikovacs 0:4eb2240dbd22 2409 {
andreikovacs 0:4eb2240dbd22 2410 bScanDone = FALSE;
andreikovacs 0:4eb2240dbd22 2411 smacErrors_t err;
andreikovacs 0:4eb2240dbd22 2412 if (ChannelToScan <= gMaxChannel_c)
andreikovacs 0:4eb2240dbd22 2413 {
andreikovacs 0:4eb2240dbd22 2414 err = MLMEScanRequest((channels_t)ChannelToScan);
andreikovacs 0:4eb2240dbd22 2415 if(err == gErrorNoError_c)
andreikovacs 0:4eb2240dbd22 2416 ChannelToScan++; //Increment channel to scan
andreikovacs 0:4eb2240dbd22 2417 }
andreikovacs 0:4eb2240dbd22 2418 else
andreikovacs 0:4eb2240dbd22 2419 {
andreikovacs 0:4eb2240dbd22 2420 bScanDone = TRUE; //PRINT ALL CHANNEL RESULTS
andreikovacs 0:4eb2240dbd22 2421 Thread::wait(300); //Add delay between channel scanning series.
andreikovacs 0:4eb2240dbd22 2422 }
andreikovacs 0:4eb2240dbd22 2423 }
andreikovacs 0:4eb2240dbd22 2424
andreikovacs 0:4eb2240dbd22 2425 /***********************************************************************
andreikovacs 0:4eb2240dbd22 2426 *********************Utilities Software********************************
andreikovacs 0:4eb2240dbd22 2427 ************************************************************************/
andreikovacs 0:4eb2240dbd22 2428
andreikovacs 0:4eb2240dbd22 2429 bool_t stringComp(uint8_t * au8leftString, uint8_t * au8RightString, uint8_t bytesToCompare)
andreikovacs 0:4eb2240dbd22 2430 {
andreikovacs 0:4eb2240dbd22 2431 do
andreikovacs 0:4eb2240dbd22 2432 {
andreikovacs 0:4eb2240dbd22 2433 }while((*au8leftString++ == *au8RightString++) && --bytesToCompare);
andreikovacs 0:4eb2240dbd22 2434 return(0 == bytesToCompare);
andreikovacs 0:4eb2240dbd22 2435 }
andreikovacs 0:4eb2240dbd22 2436
andreikovacs 0:4eb2240dbd22 2437 uint32_t HexString2Dec(uint8_t* au8String)
andreikovacs 0:4eb2240dbd22 2438 {
andreikovacs 0:4eb2240dbd22 2439 uint8_t u8LocIndex=0;
andreikovacs 0:4eb2240dbd22 2440 uint8_t u8LocIndex2=0;
andreikovacs 0:4eb2240dbd22 2441 uint32_t u32DecValue = 0;
andreikovacs 0:4eb2240dbd22 2442
andreikovacs 0:4eb2240dbd22 2443 while(au8String[u8LocIndex]){
andreikovacs 0:4eb2240dbd22 2444 u8LocIndex++;
andreikovacs 0:4eb2240dbd22 2445 }
andreikovacs 0:4eb2240dbd22 2446
andreikovacs 0:4eb2240dbd22 2447 while(u8LocIndex--){
andreikovacs 0:4eb2240dbd22 2448 if((au8String[u8LocIndex] >= '0') && (au8String[u8LocIndex] <= '9'))
andreikovacs 0:4eb2240dbd22 2449 u32DecValue |= ((uint32_t)(au8String[u8LocIndex] - '0'))<<(u8LocIndex2*4);
andreikovacs 0:4eb2240dbd22 2450 else if((au8String[u8LocIndex] >= 'A') && (au8String[u8LocIndex] <= 'F')){
andreikovacs 0:4eb2240dbd22 2451 u32DecValue |= ((uint32_t)(au8String[u8LocIndex] - 'A' + 0x0A))<<(u8LocIndex2*4);
andreikovacs 0:4eb2240dbd22 2452 }else{
andreikovacs 0:4eb2240dbd22 2453 u32DecValue |= ((uint32_t)(au8String[u8LocIndex] - 'a' + 0x0A))<<(u8LocIndex2*4);
andreikovacs 0:4eb2240dbd22 2454 }
andreikovacs 0:4eb2240dbd22 2455 u8LocIndex2++;
andreikovacs 0:4eb2240dbd22 2456 }
andreikovacs 0:4eb2240dbd22 2457
andreikovacs 0:4eb2240dbd22 2458 return u32DecValue;
andreikovacs 0:4eb2240dbd22 2459 }
andreikovacs 0:4eb2240dbd22 2460
andreikovacs 0:4eb2240dbd22 2461 static void DelayTimeElapsed()
andreikovacs 0:4eb2240dbd22 2462 {
andreikovacs 0:4eb2240dbd22 2463 timePassed = TRUE;
andreikovacs 0:4eb2240dbd22 2464 gTaskEventFlags |= gTimePassed_EVENT_c;
andreikovacs 0:4eb2240dbd22 2465 }
andreikovacs 0:4eb2240dbd22 2466
andreikovacs 0:4eb2240dbd22 2467 /***********************************************************************************
andreikovacs 0:4eb2240dbd22 2468 *
andreikovacs 0:4eb2240dbd22 2469 * PrintMenu
andreikovacs 0:4eb2240dbd22 2470 *
andreikovacs 0:4eb2240dbd22 2471 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 2472 void PrintMenu(char * const pu8Menu[], uint8_t port)
andreikovacs 0:4eb2240dbd22 2473 {
andreikovacs 0:4eb2240dbd22 2474 uint8_t u8Index = 0;
andreikovacs 0:4eb2240dbd22 2475 (void)port;
andreikovacs 0:4eb2240dbd22 2476 while(pu8Menu[u8Index]){
andreikovacs 0:4eb2240dbd22 2477 uart.printf(pu8Menu[u8Index]);
andreikovacs 0:4eb2240dbd22 2478 u8Index++;
andreikovacs 0:4eb2240dbd22 2479 }
andreikovacs 0:4eb2240dbd22 2480 }
andreikovacs 0:4eb2240dbd22 2481
andreikovacs 0:4eb2240dbd22 2482 /***********************************************************************
andreikovacs 0:4eb2240dbd22 2483 ************************************************************************/
andreikovacs 0:4eb2240dbd22 2484
andreikovacs 0:4eb2240dbd22 2485 /************************************************************************************
andreikovacs 0:4eb2240dbd22 2486 *
andreikovacs 0:4eb2240dbd22 2487 * PrintTestParameters
andreikovacs 0:4eb2240dbd22 2488 *
andreikovacs 0:4eb2240dbd22 2489 ************************************************************************************/
andreikovacs 0:4eb2240dbd22 2490 void PrintTestParameters(bool_t bEraseLine)
andreikovacs 0:4eb2240dbd22 2491 {
andreikovacs 0:4eb2240dbd22 2492 uint8_t u8lineLen = 63;
andreikovacs 0:4eb2240dbd22 2493 uint8_t u8Index;
andreikovacs 0:4eb2240dbd22 2494
andreikovacs 0:4eb2240dbd22 2495 if(bEraseLine)
andreikovacs 0:4eb2240dbd22 2496 {
andreikovacs 0:4eb2240dbd22 2497 for(u8Index = 0;u8Index<u8lineLen;u8Index++)
andreikovacs 0:4eb2240dbd22 2498 {
andreikovacs 0:4eb2240dbd22 2499 uart.printf("\b");
andreikovacs 0:4eb2240dbd22 2500 }
andreikovacs 0:4eb2240dbd22 2501 }
andreikovacs 0:4eb2240dbd22 2502
andreikovacs 0:4eb2240dbd22 2503 uart.printf("Mode ");
andreikovacs 0:4eb2240dbd22 2504 if(mTxOperation_c == testOpMode)
andreikovacs 0:4eb2240dbd22 2505 {
andreikovacs 0:4eb2240dbd22 2506 uart.printf("Tx");
andreikovacs 0:4eb2240dbd22 2507 }
andreikovacs 0:4eb2240dbd22 2508 else
andreikovacs 0:4eb2240dbd22 2509 {
andreikovacs 0:4eb2240dbd22 2510 uart.printf("Rx");
andreikovacs 0:4eb2240dbd22 2511 }
andreikovacs 0:4eb2240dbd22 2512 uart.printf(", Channel ");
andreikovacs 0:4eb2240dbd22 2513 uart.printf("%d", (uint32_t)testChannel);
andreikovacs 0:4eb2240dbd22 2514 uart.printf(", Power ");
andreikovacs 0:4eb2240dbd22 2515 uart.printf("%d",(uint32_t)testPower);
andreikovacs 0:4eb2240dbd22 2516 uart.printf(", Payload ");
andreikovacs 0:4eb2240dbd22 2517 uart.printf("%d", (uint32_t)testPayloadLen);
andreikovacs 0:4eb2240dbd22 2518 uart.printf(", CCA Thresh ");
andreikovacs 0:4eb2240dbd22 2519 if(ccaThresh != 0)
andreikovacs 0:4eb2240dbd22 2520 {
andreikovacs 0:4eb2240dbd22 2521 uart.printf("-");
andreikovacs 0:4eb2240dbd22 2522 }
andreikovacs 0:4eb2240dbd22 2523 uart.printf("%d", (uint32_t)ccaThresh);
andreikovacs 0:4eb2240dbd22 2524 uart.printf("dBm");
andreikovacs 0:4eb2240dbd22 2525 uart.printf(" >");
andreikovacs 0:4eb2240dbd22 2526 }
andreikovacs 0:4eb2240dbd22 2527 /*****************************************************************************/
andreikovacs 0:4eb2240dbd22 2528
andreikovacs 0:4eb2240dbd22 2529 int main()
andreikovacs 0:4eb2240dbd22 2530 {
andreikovacs 0:4eb2240dbd22 2531 mainTask = new Thread(main_task);
andreikovacs 0:4eb2240dbd22 2532 while(1)
andreikovacs 0:4eb2240dbd22 2533 {
andreikovacs 0:4eb2240dbd22 2534
andreikovacs 0:4eb2240dbd22 2535 }
andreikovacs 0:4eb2240dbd22 2536 return 0;
andreikovacs 0:4eb2240dbd22 2537 }