The MCR20A Connectivity Test application is an SMAC based demo application which provides the user with means to test basic transmission-reception functionalities along with several advanced testing features based on the ASP and SMAC APIs.

Dependencies:   fsl_phy_mcr20a fsl_smac mbed-rtos mbed

Fork of mcr20_connectivity_test by Freescale

Modes of Operation

The MCR20A Connectivity Test application has five main features:

Continuous Tests

This menu option displays several test suites

  • IDLE: This option sets the transceiver and all the state machines to idle.
  • Burst PRBS Transmission using packet mode: This option continuously sends packets which contain a pseudo-random payload of fixed length.
  • Continuous Modulated Transmission: This option allows the user to select between modulating 1’s, 0’s, or a pseudo-random sequence (PN) and sending them OTA continuously (in continuous mode).
  • Continuous Unmodulated Transmission: This option allows the user to send an unmodulated signal OTA having the frequency equal to the central frequency of the currently selected channel.
  • Continuous Reception: This test places the transceiver in reception and dumps the payload bytes of the received packets to the TERM in ASCII-converted hexadecimal characters.
  • Continuous Energy Detect: This option launches consecutive energy detect requests at fixed hard-coded intervals for the current channel, and prints their values to the TERM.
  • Continuous Scan: This option is similar to the previous one, except that at each iteration it obtains the energy values on all channels.
  • Continuous CCA: This option launches consecutive CCA requests for the currently selected channel at a fixed. hard-coded interval, and prints “Idle” or “Busy” depending on the CCA result.

Packet Error Rate

This menu option displays a configuration menu for testing the packet error rate. The menu displayed also depends on the ‘r’ or ‘t’ shortcut key. If ‘r’ is pressed, the following menu is for PER RX, otherwise it is for PER TX. For example, if two MCR20A platforms have Connectivity Test loaded, one of the boards can be set in RX and the other in TX as in the following figures.

Range Test

This test displays a configuration menu that performs a ‘ping-pong’ test to aid the user in determining the range (as distance between two platforms) in which the MCR20A platform can function properly. The sub-menu also depends on the ‘r’ and ‘t’ shortcuts so that one of the platforms can be the initializer (first to start a TX) and the other can respond to requests. The test is started and stopped only by user intervention and during its execution it will display the signal strength for each received packet. At the end of the test, the platform configured as the initializer (TX) displays a summary of how many packets were lost and what was the average RSSI.

Radio Registers Edit

This menu allows the user to read-write transceiver registers and to dump all address-value pairs from the transceiver registers to the TERM. The described features are accessible through the entries of this menu. For each access request (read or write) to a certain register, the register address is validated partially, and it is the responsibility of the user to access an existing register. For example, if the last accessible register is at 0xFD, the application only validates that the address is in the unsigned char range, but the user has the possibility to request register 0xFF. To ensure that a proper range is used, the user should first use the dump register feature to see the valid address ranges.

Carrier Sense and Transmission Control

This menu allows the user to choose between two tests. The former is the Carrier Sense test, which performs ED continuously until the ED value is above the CCA threshold (configured using ‘k’ and ‘l’ shortcuts) and then transmits a packet which contains pseudo-random data with the payload size configured using ‘n’ and ‘m’ shortcuts. The latter is the Transmission Control test, which displays a selection menu for number of packets identical with the one in PER TX test, then prompts the user to enter a decimal value resembling the inter-packet delay in milliseconds. After that, the application starts sending the selected number of packets with the selected inter-packet delay, using pseudo-random data for the payload with the size configured with ‘n’ and ‘m’ shortcuts.

Keys Usage

The following keys have the effect described below:

  • ‘t’ : Brings up the configuration menu for the transmitter in both PER and Range tests.
  • ‘r’ : Brings up the configuration menu for the receiver in both PER and Range tests.
  • ‘q’ : Increments channel number. If pressed when the current channel is 26, the channel number changes to 11.
  • ‘w’ : Decrements channel number. If pressed when the current channel is 11, the channel number will change to 26.
  • ‘a’ : Increments output power value. If output power is at maximum and this key is pressed, the output power goes to the minimum (in this case 0x03).
  • ‘s’ : Decrements output power value. If output power is at minimum and this key is pressed, the output power goes to the maximum (in this case 0x1F). These are not directly mapped to dBm values. Instead the output power value is written to the appropriate register. The user should consult the reference manual to determine the relationship between selected value and power in dBm.
  • ‘n’ : Increments the length of the payload. This value is used in both PER TX test to build-up the payload and in Transmission Control test for the same reason.
  • ‘m’ : Decrements the length of the payload. Incrementation and decrementation are performed in the [17, 116] interval. All overflows at one end lead to setting the other end’s value.
  • ‘k’ : Increments the CCA threshold for the Carrier Sense test. In this test the CCA before TX algorithm is implemented at application level, and the channel idle threshold is established using this parameter.
  • ‘l’ : Decrements the CCA threshold for the Carrier Sense test.

Documentation

SMAC Demo Applications User Guide

Committer:
andreikovacs
Date:
Fri Jul 31 13:49:46 2015 +0000
Revision:
6:85e288fb2556
Parent:
5:ad78d222bbcd
Changed some printed messages format

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