Home | History | Annotate | Download | only in hw_ctrl
      1 /****************************************************************************
      2 **+-----------------------------------------------------------------------+**
      3 **|                                                                       |**
      4 **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
      5 **| All rights reserved.                                                  |**
      6 **|                                                                       |**
      7 **| Redistribution and use in source and binary forms, with or without    |**
      8 **| modification, are permitted provided that the following conditions    |**
      9 **| are met:                                                              |**
     10 **|                                                                       |**
     11 **|  * Redistributions of source code must retain the above copyright     |**
     12 **|    notice, this list of conditions and the following disclaimer.      |**
     13 **|  * Redistributions in binary form must reproduce the above copyright  |**
     14 **|    notice, this list of conditions and the following disclaimer in    |**
     15 **|    the documentation and/or other materials provided with the         |**
     16 **|    distribution.                                                      |**
     17 **|  * Neither the name Texas Instruments nor the names of its            |**
     18 **|    contributors may be used to endorse or promote products derived    |**
     19 **|    from this software without specific prior written permission.      |**
     20 **|                                                                       |**
     21 **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
     22 **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
     23 **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
     24 **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
     25 **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
     26 **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
     27 **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
     28 **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
     29 **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
     30 **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
     31 **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
     32 **|                                                                       |**
     33 **+-----------------------------------------------------------------------+**
     34 ****************************************************************************/
     35 
     36 /****************************************************************************
     37  *
     38  *   MODULE:  whalHwMboxCmdBit.c
     39  *   PURPOSE: wlan hardware BIT commands handler
     40  *
     41  ****************************************************************************/
     42 
     43 #include "whalCommon.h"
     44 #include "CmdQueue_api.h"
     45 #include "public_infoele.h"
     46 #include "commonTypes.h"
     47 #include "whalHwMboxCmdBit.h"
     48 
     49 
     50 
     51 /*******************************************
     52  * Wlan hardware Test (BIT)
     53  * =================
     54  *
     55  * Tests description:
     56  * ==================
     57  * FCC           = Continuous modulated transmission (should not emit carrier)
     58  * TELEC         = Continuous unmodulated carrier transmission (carrier only)
     59  * PER_TX_STOP   = Stops the TX test in progress (FCC or TELEC).
     60  * ReadRegister  = Read a register value.
     61  * WriteRegister = Sets a register value.
     62 *
     63 * Rx PER test
     64 * ========
     65 * PerRxStart       = Start or resume the PER measurement. This function will put the device in promiscuous mode, and resume counters update.
     66 * PerRxStop        = Stop Rx PER measurements. This function stop counters update and make it is safe to read the PER test result.
     67 * PerRxGetResults  = Get the last Rx PER test results.
     68 * PerRxClear       = Clear the Rx PER test results.
     69  */
     70 
     71 enum
     72 {
     73 /* 0 */   TEST_MOD_QPSK,
     74 /* 1 */   TEST_MOD_CCK,
     75 /* 2 */   TEST_MOD_PBCC,
     76 
     77    TEST_MOD_NUMOF
     78 };
     79 
     80 enum
     81 {
     82 /* 0 */   TEST_MOD_LONG_PREAMBLE,
     83 /* 1 */   TEST_MOD_SHORT_PREAMBLE
     84 };
     85 
     86 enum
     87 {
     88 /* 0 */   TEST_BAND_2_4GHZ,
     89 /* 1 */   TEST_BAND_5GHZ,
     90 /* 2 */   TEST_BAND_4_9GHZ
     91 };
     92 
     93 
     94 #define TEST_MOD_MIN_GAP           200
     95 #define TEST_MOD_MIN_TX_BODYLEN    0
     96 #define TEST_MOD_MAX_TX_BODYLEN    2304
     97 
     98 #define TEST_RX_CAL_SAFE_TIME      5000  /*uSec*/
     99 
    100 #define TEST_MOD_IS_GAP_OK(gap)     ((gap) >= TEST_MOD_MIN_GAP)
    101 
    102 #define TEST_MOD_IS_TX_BODYLEN_OK(len)  \
    103    (INRANGE((len), TEST_MOD_MIN_TX_BODYLEN, TEST_MOD_MAX_TX_BODYLEN) && \
    104    (((len) & 3) == 0) )
    105 
    106 #define TEST_MOD_IS_PREAMBLE_OK(p)  \
    107    INRANGE((p), TEST_MOD_LONG_PREAMBLE, TEST_MOD_SHORT_PREAMBLE)
    108 
    109 
    110 void whal_hwCmdBit_RxPer_Clear_CB(TI_HANDLE objectHandle,UINT16 MboxStatus,void *InterrogateParamsBuf);
    111 void whal_hwCmdBit_RxPer_GetResults_CB(TI_HANDLE objectHandle,UINT16 MboxStatus,void *InterrogateParamsBuf);
    112 void whal_hwCmdBit_RxCal_CB(TI_HANDLE objectHandle,UINT16 MboxStatus,void *InterrogateParamsBuf);
    113 void whal_hwCmdBit_RxCal_Complete_Event_CB( TI_HANDLE objectHandle, char* str, UINT32 strLen );
    114 
    115 /****************************************************************************
    116  *                      whal_hwMboxCmdBit_Create()
    117  ****************************************************************************
    118  * DESCRIPTION: Create the mailbox BIT commands object
    119  *
    120  * INPUTS:
    121  *
    122  * OUTPUT:  None
    123  *
    124  * RETURNS: The Created object
    125  ****************************************************************************/
    126 HwMboxCmdBit_T *whal_hwMboxCmdBit_Create(TI_HANDLE hOs)
    127 {
    128     HwMboxCmdBit_T *pObj;
    129 
    130     pObj = os_memoryAlloc(hOs, sizeof(HwMboxCmdBit_T));
    131     if (pObj == NULL)
    132         return NULL;
    133 
    134     os_memoryZero(hOs, (void *)pObj, sizeof(HwMboxCmdBit_T));
    135 
    136     pObj->hOs = hOs;
    137 
    138     return(pObj);
    139 }
    140 
    141 /****************************************************************************
    142  *                      whal_hwMboxCmdBit_Destroy()
    143  ****************************************************************************
    144  * DESCRIPTION: Destroy the object
    145  *
    146  * INPUTS:
    147  *      pHwMboxCmdBit       The object to free
    148  *
    149  * OUTPUT:  None
    150  *
    151  * RETURNS: OK or NOK
    152  ****************************************************************************/
    153 int whal_hwMboxCmdBit_Destroy(HwMboxCmdBit_T *pHwMboxCmdBit)
    154 {
    155     if (pHwMboxCmdBit)
    156     {
    157         whalCtrl_EventMbox_Disable( pHwMboxCmdBit->hWhalCtr, HAL_EVENT_PLT_RX_CALIBRATION_COMPLETE );
    158         os_memoryFree(pHwMboxCmdBit->hOs, pHwMboxCmdBit, sizeof(HwMboxCmdBit_T));
    159     }
    160     return OK;
    161 }
    162 
    163 /****************************************************************************
    164  *                      whal_hwMboxCmdBit_Config()
    165  ****************************************************************************
    166  * DESCRIPTION: Configure the object
    167  *
    168  * INPUTS:
    169  *
    170  * OUTPUT:  None
    171  *
    172  * RETURNS: OK or NOK
    173  ****************************************************************************/
    174 int whal_hwMboxCmdBit_Config(TI_HANDLE hWhalCtr, HwMboxCmdBit_T *pHwMboxCmdBit, TI_HANDLE hCmdQueue, TI_HANDLE hReport)
    175 {
    176     pHwMboxCmdBit->hReport = hReport;
    177     pHwMboxCmdBit->hCmdQueue = hCmdQueue;
    178     pHwMboxCmdBit->hWhalCtr = hWhalCtr;
    179 
    180     whalCtrl_EventMbox_RegisterForEvent( hWhalCtr,
    181                                          HAL_EVENT_PLT_RX_CALIBRATION_COMPLETE,
    182                                          (void *)whal_hwCmdBit_RxCal_Complete_Event_CB,
    183                                          (void*)pHwMboxCmdBit);
    184 
    185     whalCtrl_EventMbox_Enable( hWhalCtr, HAL_EVENT_PLT_RX_CALIBRATION_COMPLETE );
    186 
    187     pHwMboxCmdBit->PltData.RxTxCal.lastStatus = OK;
    188     return OK;
    189 }
    190 
    191 /*******************
    192  Helper functions
    193  *******************/
    194 
    195 static void errPrint_ChID(HwMboxCmdBit_T *pHwMboxCmdBit, int chID)
    196 {
    197     WLAN_REPORT_REPLY(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    198         ("Channel ID (%d) is out of range, use [%d..%d] for 2.4Ghz, [%d..%d] for 5Ghz and [%d %d %d] for 4.9Ghz.\n",
    199          chID,
    200          HAL_CTRL_CALIBRATION_CHANNEL_2_4_MIN, HAL_CTRL_CALIBRATION_CHANNEL_2_4_MAX,
    201          HAL_CTRL_CALIBRATION_CHANNEL_5_0_MIN, HAL_CTRL_CALIBRATION_CHANNEL_5_0_MAX,
    202          HAL_CTRL_CALIBRATION_CHANNEL_4_9_MIN, HAL_CTRL_CALIBRATION_CHANNEL_4_9_DEF, HAL_CTRL_CALIBRATION_CHANNEL_4_9_MAX));
    203 }
    204 
    205 static void errPrint_BandID(HwMboxCmdBit_T *pHwMboxCmdBit, int bandID)
    206 {
    207         WLAN_REPORT_REPLY(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    208         ("PLT whal_hwCmdBit_Fcc: Wrong band parameter 0x%x(must be 0x%x for 2.4Ghz or 0x%x for 5Ghz or 0x%x for 4.9Ghz).\n",
    209         bandID, TEST_BAND_2_4GHZ, TEST_BAND_5GHZ, TEST_BAND_4_9GHZ));
    210 }
    211 
    212 /* MACROS */
    213 int VALIDATE_BAND_CHID(HwMboxCmdBit_T *pHwMboxCmdBit, int chID, int bandID)
    214 {
    215    int minVal, maxVal;
    216    switch(bandID)
    217    {
    218    case TEST_BAND_2_4GHZ:
    219        minVal = HAL_CTRL_CALIBRATION_CHANNEL_2_4_MIN;
    220        maxVal = HAL_CTRL_CALIBRATION_CHANNEL_2_4_MAX;
    221     break;
    222 
    223    case TEST_BAND_5GHZ:
    224        minVal = HAL_CTRL_CALIBRATION_CHANNEL_5_0_MIN;
    225        maxVal = HAL_CTRL_CALIBRATION_CHANNEL_5_0_MAX;
    226        break;
    227 
    228     case TEST_BAND_4_9GHZ:
    229        minVal = HAL_CTRL_CALIBRATION_CHANNEL_4_9_MIN;
    230        maxVal = HAL_CTRL_CALIBRATION_CHANNEL_4_9_MAX;
    231        break;
    232 
    233    default:
    234        errPrint_BandID(pHwMboxCmdBit, bandID);
    235        return NOK;
    236    }
    237    if(!INRANGE(chID, minVal, maxVal))
    238    {
    239       errPrint_ChID(pHwMboxCmdBit, chID);
    240       return NOK;
    241    }
    242    return(OK);
    243 }
    244 
    245 /****************************************************************************
    246  *                       whal_hwCmdBit_Fcc()
    247  ****************************************************************************
    248  * DESCRIPTION: Performs FCC test
    249  *
    250  * INPUTS: chID, rate, Modulation, preamble, band, TestMode
    251  *
    252  * OUTPUT:  None
    253  *
    254  * RETURNS: OK or NOK
    255  ****************************************************************************/
    256 int whal_hwCmdBit_Fcc(HwMboxCmdBit_T *pHwMboxCmdBit,
    257                       int chID,
    258                       int rate,
    259                       int preamble,
    260                       int bandID,
    261                       int InterPacketDelay,
    262                       int TestMode,
    263                       uint32 numFrames,
    264                       uint32 seqNumMode,
    265                       uint32 frameBodySize,
    266                       uint8 *PeerMacAddr,
    267                       void *CB_Func, TI_HANDLE CB_Handle, void *CB_Buf)
    268 {
    269     int Modulation;
    270     TestCmd_t TestCmd;
    271     os_memoryZero(pHwMboxCmdBit->hOs, (void *)&TestCmd, sizeof(TestCmd));
    272 
    273     WLAN_REPORT_INFORMATION(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    274         ("whal_hwCmdBit_Fcc:\n chID = %d\n rate = %d preamble = %d, bandID %d, InterPacketDelay %d, TestMode %d numOfFrames %d\n ",
    275              chID,  rate,  preamble,
    276              bandID,  InterPacketDelay,  TestMode, numFrames));
    277 
    278     /*Check Channel and band*/
    279     if (VALIDATE_BAND_CHID(pHwMboxCmdBit, chID, bandID) == NOK)
    280         return NOK;
    281 
    282     /*Check rate and set Modulation*/
    283     if ((rate >= 1) && (rate <= 4))
    284         Modulation = MOD_CCK;
    285     else if ((rate >= 6) && (rate <= 13))
    286         Modulation =  MOD_OFDM;
    287     else
    288     {
    289         WLAN_REPORT_REPLY(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    290             ("PLT whal_hwCmdBit_Fcc: Wrong rate parameter %d(must be 1-4 to CCK modulation  or 6-13 for OFDM modulation) .\n",
    291             rate));
    292         return NOK;
    293     }
    294 
    295      /*Set FW rate */
    296     TestCmd.testCmd_u.fcc.dataRate = ConvertDrvRate2HwRate((rate_e)rate);
    297 
    298     /*Validate preamble*/
    299     if ((preamble!=0) && preamble != CTL_PREAMBLE)
    300     {
    301         WLAN_REPORT_REPLY(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    302         ("PLT whal_hwCmdBit_Fcc: Wrong preamble parameter 0x%x(must be (0x%x) for long preamble or short(0x%x)) .\n",
    303         preamble, 0, CTL_PREAMBLE));
    304 
    305         return NOK;
    306     }
    307 
    308     /*Validate test mode*/
    309     if ((TestMode != TEST_MODE_ZOZO_DATA) && (TestMode != TEST_MODE_RANDOM_DATA))
    310     {
    311         WLAN_REPORT_REPLY(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    312         ("PLT whal_hwCmdBit_Fcc: Wrong TestMode parameter 0x%x(must be RANDOM_DATA(0x%x) or ZOZO_DATA(0x%x)) .\n",
    313         TestMode, TEST_MODE_RANDOM_DATA, TEST_MODE_ZOZO_DATA));
    314         /*Not returning NOX for enabling GAP bit*/
    315     }
    316 
    317         /*Validate seq num mode*/
    318     if ((seqNumMode != TEST_SEQ_NUM_MODE_FIXED) && (seqNumMode != TEST_SEQ_NUM_MODE_INCREMENTED))
    319     {
    320         WLAN_REPORT_REPLY(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    321         ("PLT whal_hwCmdBit_Fcc: Wrong seqNumMode parameter 0x%x(must be TEST_SEQ_NUM_MODE_FIXED(0x%x) or TEST_SEQ_NUM_MODE_INCREMENTED(0x%x)) .\n",
    322         seqNumMode, TEST_SEQ_NUM_MODE_FIXED, TEST_SEQ_NUM_MODE_INCREMENTED));
    323 
    324         return NOK;
    325     }
    326 
    327     TestCmd.testCmd_u.fcc.seqNumMode = seqNumMode;
    328     TestCmd.testCmd_u.fcc.frameBodySize = frameBodySize;
    329     os_memoryCopy(pHwMboxCmdBit->hOs , TestCmd.testCmd_u.fcc.dest, PeerMacAddr,NUM_OF_MAC_ADDR_ELEMENTS);
    330 
    331     WLAN_REPORT_INFORMATION(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    332         ("whal_hwCmdBit_Fcc: \n seqNumMode = %d ,frameBodySize = 0x%x",
    333              TestCmd.testCmd_u.fcc.seqNumMode,
    334              TestCmd.testCmd_u.fcc.frameBodySize));
    335 
    336     WLAN_REPORT_INFORMATION(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    337         ("whal_hwCmdBit_Fcc: \n Dest = %02x:%02x:%02x:%02x:%02x:%02x",
    338              TestCmd.testCmd_u.fcc.dest[0],
    339              TestCmd.testCmd_u.fcc.dest[1],
    340              TestCmd.testCmd_u.fcc.dest[2],
    341              TestCmd.testCmd_u.fcc.dest[3],
    342              TestCmd.testCmd_u.fcc.dest[4],
    343              TestCmd.testCmd_u.fcc.dest[5]));
    344 
    345     TestCmd.testCmd_u.fcc.channel = chID;
    346 
    347     switch (Modulation)
    348     {
    349     case MOD_PBCC:
    350         Modulation = PBCC_MODULATION_MASK;
    351         break;
    352 
    353     case MOD_CCK:
    354         Modulation = 0x00;
    355         break;
    356 
    357     case MOD_OFDM:
    358         Modulation = OFDM_MODULATION_MASK;
    359         break;
    360     }
    361     /*Build preamble parameter*/
    362     TestCmd.testCmd_u.fcc.modPreamble = preamble;
    363     TestCmd.testCmd_u.fcc.band = bandID;
    364     TestCmd.testCmd_u.fcc.modulation = Modulation;
    365 
    366     TestCmd.testCmd_u.fcc.testModeCtrl = TestMode;
    367 
    368     /* Set command fields */
    369     TestCmd.testCmdId = TEST_CMD_FCC;
    370 
    371     WLAN_REPORT_INFORMATION(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    372         ("whal_hwCmdBit_Fcc: \n AcxCmd_TestFCC.channel = %d ,AcxCmd_TestFCC.dataRate = 0x%x,  AcxCmd_TestFCC.modPreamble = 0x%x, AcxCmd_TestFCC.testModeCtrl = 0x%x\n ",
    373              TestCmd.testCmd_u.fcc.channel,
    374              TestCmd.testCmd_u.fcc.dataRate,
    375              TestCmd.testCmd_u.fcc.modPreamble,
    376              TestCmd.testCmd_u.fcc.testModeCtrl));
    377 
    378 
    379     /*Set InterPacketDelay*/
    380     /*TestCmd.testCmd_u.fcc.interFrameGap = 1000 * InterPacketDelay; */ /*Convert ms to us*/
    381     TestCmd.testCmd_u.fcc.interFrameGap = InterPacketDelay; /*(uSec)*/
    382 
    383     /*Set numFrames */
    384     TestCmd.testCmd_u.fcc.numFrames = numFrames;
    385 
    386     return whal_hwCmdBit_TestCmd(pHwMboxCmdBit, CB_Func, CB_Handle, &TestCmd);
    387 }/* END whal_hwCmdBit_Fcc() */
    388 
    389 
    390 
    391 /****************************************************************************
    392  *                      whal_hwCmdBit_Telec()
    393  ****************************************************************************
    394  * DESCRIPTION: Performs TELEC test
    395  *
    396  * INPUTS: chID   - Channel number, between  1 (MIN_CHANNEL_ID) to  14 (MAX_CHANNEL_ID).
    397  *         bandID - Band ID number, 0 - 2.4Ghz, 1 - 5Ghz.
    398  *
    399  * OUTPUT:  None
    400  *
    401  * RETURNS: OK or NOK
    402  ****************************************************************************/
    403 int whal_hwCmdBit_Telec(HwMboxCmdBit_T *pHwMboxCmdBit, int chID, int bandID, void *CB_Func, TI_HANDLE CB_Handle, void *CB_Buf)
    404 {
    405     TestCmd_t   TestCmd;
    406     TestCmd_t  *pCmd = &TestCmd;
    407     WLAN_REPORT_INFORMATION(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    408          ("whal_hwCmdBit_Telec: chID = %d bandID = %d\n ", chID, bandID));
    409 
    410 
    411     /*Check Channel and band*/
    412     if (VALIDATE_BAND_CHID(pHwMboxCmdBit, chID, bandID) == NOK)
    413         return NOK;
    414 
    415     /* Set command fields; param1 = chID, param2 = BandID */
    416     os_memoryZero(pHwMboxCmdBit->hOs, (void *)pCmd, sizeof(*pCmd ));
    417     pCmd->testCmdId = TEST_CMD_TELEC;
    418     pCmd->testCmd_u.telec.channel = (UINT8)chID;
    419     pCmd->testCmd_u.telec.band = (UINT8)bandID;
    420 
    421     /* Send the command */
    422     return whal_hwCmdBit_TestCmd(pHwMboxCmdBit, CB_Func, CB_Handle, &TestCmd);
    423 }/* END whal_hwCmdBit_Telec() */
    424 
    425 /**************************
    426     REGISTER HANDLING
    427  *************************/
    428 
    429 /****************************************************************************
    430  *                      whal_hwCmdBit_ReadRegister()
    431  ****************************************************************************
    432  * DESCRIPTION: Performs PLT read register
    433  *
    434  * INPUTS: RegAddress - the address of the register to read
    435  *
    436  * OUTPUT:  None
    437  *
    438  * RETURNS: OK or NOK
    439  ****************************************************************************/
    440  int whal_hwCmdBit_ReadRegister(HwMboxCmdBit_T *pHwMboxCmdBit, TI_HANDLE CB_Handle, void *CB_Func, void *CB_Buf)
    441 {
    442     ReadWriteCommand_t* pCmd = CB_Buf;
    443 
    444      /* Send the command */
    445      return (CmdQueue_CommandWithCb(pHwMboxCmdBit->hCmdQueue, CMD_READ_MEMORY, (char *)pCmd, sizeof(*pCmd), CB_Func, CB_Handle, CB_Buf));
    446 }/* END whal_hwCmdBit_ReadRegister() */
    447 
    448 
    449 /****************************************************************************
    450  *                      whal_hwCmdBit_WriteRegister()
    451  ****************************************************************************
    452  * DESCRIPTION: Performs PLT write register
    453  *
    454  * INPUTS:  RegAddress - the address of the register to write to
    455  *          RegData - the data to write
    456  *
    457  * OUTPUT:  None
    458  *
    459  * RETURNS: OK or NOK
    460  ****************************************************************************/
    461  int whal_hwCmdBit_WriteRegister(HwMboxCmdBit_T *pHwMboxCmdBit, TI_HANDLE CB_Handle, void *CB_Func, void *Command_Buf)
    462 {
    463 
    464 
    465      /* Send the command */
    466      if (CB_Func)
    467         return (CmdQueue_CommandWithCb(pHwMboxCmdBit->hCmdQueue, CMD_WRITE_MEMORY, (char *)Command_Buf, sizeof(ReadWriteCommand_t), CB_Func, CB_Handle, NULL));
    468      else
    469         return (CmdQueue_Command(pHwMboxCmdBit->hCmdQueue, CMD_WRITE_MEMORY, (char *)Command_Buf, sizeof(ReadWriteCommand_t)));
    470 }/* END whal_hwCmdBit_WriteRegister() */
    471 
    472 
    473 /****************************************************************************
    474  *                      whal_hwCmdBit_perTxStop()
    475  ****************************************************************************
    476  * DESCRIPTION:   Packet Error Rate - stop test, no params.
    477  *                Does not clear statistics.
    478  * INPUTS: None
    479  *
    480  * OUTPUT:  None
    481  *
    482  * RETURNS: OK or NOK
    483  ****************************************************************************/
    484 int whal_hwCmdBit_perTxStop(HwMboxCmdBit_T *pHwMboxCmdBit, void *CB_Func, TI_HANDLE CB_Handle, void *CB_Buf)
    485 {
    486     TestCmd_t   TestCmd;
    487     TestCmd_t  *pCmd = &TestCmd;
    488 
    489     /* Set command fields*/
    490     os_memoryZero(pHwMboxCmdBit->hOs, (void *)pCmd,  sizeof(*pCmd ));
    491     pCmd->testCmdId = TEST_CMD_PLT_FCC_TELEC_TX_STOP;
    492 
    493     /* Send the command  */
    494     return whal_hwCmdBit_TestCmd(pHwMboxCmdBit, CB_Func, CB_Handle, pCmd);
    495 }/* END whal_hwCmdBit_perTxStop() */
    496 
    497 
    498 
    499 
    500   /****************************************************************************
    501   *                      whal_hwCmdBit_RxPER()
    502   ****************************************************************************
    503   * DESCRIPTION:   RX PER main function - All other RX per function are called using this function
    504   * INPUTS: None
    505   *
    506   * OUTPUT:  None
    507   *
    508   * RETURNS: OK or NOK
    509  ****************************************************************************/
    510 
    511  int whal_hwCmdBit_RxPER(HwMboxCmdBit_T *pHwMboxCmdBit, PLT_RxPerCmd_e eRxPerCmd, TI_HANDLE CB_Handle, void *CB_Func)
    512  {
    513      int ret = OK;
    514      ACXErrorCounters_t ACXErrorCounters;
    515      TestCmd_t   TestCmd;
    516      TestCmd_t  *pCmd = &TestCmd;
    517 
    518 
    519 
    520      /*Defining a local function that will support the Rx PER process
    521      in a sync mode (for the core) as well as Async mode (for GWSI, as callbacks)*/
    522 
    523      CmdQueue_InterrogateCB_t PltRxPerCBArr[PLT_RX_PER_MAX] =
    524      {
    525          NULL,                              //PLT_RX_PER_START
    526          NULL,                              //PLT_RX_PER_STOP
    527          whal_hwCmdBit_RxPer_Clear_CB,      //PLT_RX_PER_CLEAR
    528          whal_hwCmdBit_RxPer_GetResults_CB  //PLT_RX_PER_GETRESULTS
    529      };
    530 
    531     WLAN_REPORT_INFORMATION(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    532          ("whal_hwCmdBit_RxPER eRxPerCmd=%d, CB_Handle=0x%p,  CB_Func=0x%p\n", eRxPerCmd, CB_Handle, CB_Func));
    533 
    534 
    535      /*
    536      * Set information element header
    537      * Each call to ACX_ERROR_CNT - retrieve the F.W Rx Per and reset them.
    538      */
    539      ACXErrorCounters.EleHdr.id  = ACX_ERROR_CNT;
    540      ACXErrorCounters.EleHdr.len = sizeof(ACXErrorCounters) - sizeof(EleHdrStruct);
    541 
    542      if ((UINT32)eRxPerCmd >=  (UINT32)PLT_RX_PER_MAX)
    543          return PARAM_VALUE_NOT_VALID;
    544 
    545      pHwMboxCmdBit->PltData.RxPer.CB_Func = CB_Func;
    546      pHwMboxCmdBit->PltData.RxPer.CB_Handle = CB_Handle;
    547      pHwMboxCmdBit->PltData.RxPer.CB_RxPerCmd = eRxPerCmd;
    548 
    549      /*
    550      * Send the interrogation command
    551      */
    552      if((PLT_RX_PER_GETRESULTS == eRxPerCmd) || (PLT_RX_PER_CLEAR == eRxPerCmd))
    553      {
    554      ret = CmdQueue_CmdInterrogateWithCb(pHwMboxCmdBit->hCmdQueue,
    555          &ACXErrorCounters, sizeof(ACXErrorCounters),
    556          (void *) PltRxPerCBArr[eRxPerCmd], pHwMboxCmdBit,
    557          &pHwMboxCmdBit->PltData.RxPer.ACXErrCountTable);
    558      return ret;
    559  }
    560 
    561      /* Set command fields*/
    562      os_memoryZero(pHwMboxCmdBit->hOs, (void *)pCmd,  sizeof(*pCmd ));
    563 
    564      if(PLT_RX_PER_START == eRxPerCmd)
    565      {
    566         pCmd->testCmdId = TEST_CMD_RX_PER_START;
    567         /* Send the command  */
    568         if (CB_Func != NULL) {
    569             return (CmdQueue_CommandWithCb(pHwMboxCmdBit->hCmdQueue, CMD_TEST, (char *)pCmd, sizeof(*pCmd),CB_Func , CB_Handle, NULL));
    570         }
    571         else
    572         {
    573             return (CmdQueue_Command(pHwMboxCmdBit->hCmdQueue, CMD_TEST, (char *)pCmd, sizeof(*pCmd) ));
    574         }
    575      }
    576 
    577      if(PLT_RX_PER_STOP == eRxPerCmd)
    578      {
    579         pCmd->testCmdId = TEST_CMD_RX_PER_STOP;
    580         /* Send the command  */
    581         if (CB_Func != NULL) {
    582            return (CmdQueue_CommandWithCb(pHwMboxCmdBit->hCmdQueue, CMD_TEST, (char *)pCmd, sizeof(*pCmd),CB_Func, CB_Handle, NULL));
    583         }
    584         else
    585         {
    586             return (CmdQueue_Command(pHwMboxCmdBit->hCmdQueue, CMD_TEST, (char *)pCmd, sizeof(*pCmd) ));
    587         }
    588      }
    589 
    590      return NOK;
    591  }
    592 
    593  /****************************************************************************
    594  *                      whal_hwCmdBit_RxPer_Clear_CB()
    595  ****************************************************************************
    596  * DESCRIPTION:   Clear the RX per counters
    597  *.
    598  * INPUTS: None
    599  *
    600  * OUTPUT:  None
    601  *
    602  * RETURNS: OK or NOK
    603  ****************************************************************************/
    604  void whal_hwCmdBit_RxPer_Clear_CB(TI_HANDLE objectHandle,UINT16 MboxStatus,void *InterrogateParamsBuf)
    605  {
    606      HwMboxCmdBit_T *pHwMboxCmdBit = (HwMboxCmdBit_T*)objectHandle;
    607      CmdQueue_InterrogateCB_t CB_Func;
    608 
    609      /*Add the latest F.W. counter result to the total RX per counters*/
    610      pHwMboxCmdBit->PltData.RxPer.PltRxPer.FCSErrorCount   = 0;
    611      pHwMboxCmdBit->PltData.RxPer.PltRxPer.TotalFrameCount = 0;
    612      pHwMboxCmdBit->PltData.RxPer.PltRxPer.PLCPErrorCount  = 0;
    613      pHwMboxCmdBit->PltData.RxPer.PltRxPer.SeqNumMissCountRef = pHwMboxCmdBit->PltData.RxPer.ACXErrCountTable.seqNumMissCount; /* set as reference point for the mesurements */
    614 
    615 
    616      /* Call the saved CB function (if any)*/
    617      if (pHwMboxCmdBit->PltData.RxPer.CB_Func)
    618      {
    619          CB_Func = (CmdQueue_InterrogateCB_t)(pHwMboxCmdBit->PltData.RxPer.CB_Func);
    620          CB_Func(pHwMboxCmdBit->PltData.RxPer.CB_Handle, MboxStatus, &pHwMboxCmdBit->PltData.RxPer);
    621      }
    622  }
    623 
    624 
    625  /****************************************************************************
    626  *                      whal_hwCmdBit_RxPer_GetResults_CB()
    627  ****************************************************************************
    628  * DESCRIPTION:   Returns the accumulated counters.
    629  * INPUTS: None
    630  *
    631  * OUTPUT:  None
    632  *
    633  * RETURNS: OK or NOK
    634  ****************************************************************************/
    635   void whal_hwCmdBit_RxPer_GetResults_CB(TI_HANDLE objectHandle,UINT16 MboxStatus,void *InterrogateParamsBuf)
    636  {
    637      HwMboxCmdBit_T *pHwMboxCmdBit = (HwMboxCmdBit_T*)objectHandle;
    638      CmdQueue_InterrogateCB_t CB_Func;
    639 
    640 
    641      /*Accumulate the RX PER counters */
    642      pHwMboxCmdBit->PltData.RxPer.PltRxPer.FCSErrorCount   += (UINT16)pHwMboxCmdBit->PltData.RxPer.ACXErrCountTable.FCSErrorCount;
    643      pHwMboxCmdBit->PltData.RxPer.PltRxPer.PLCPErrorCount  += (UINT16)pHwMboxCmdBit->PltData.RxPer.ACXErrCountTable.PLCPErrorCount;
    644      pHwMboxCmdBit->PltData.RxPer.PltRxPer.TotalFrameCount += (UINT16)pHwMboxCmdBit->PltData.RxPer.ACXErrCountTable.validFrameCount;
    645      pHwMboxCmdBit->PltData.RxPer.PltRxPer.SeqNumMissCount  = (UINT16)(pHwMboxCmdBit->PltData.RxPer.ACXErrCountTable.seqNumMissCount -
    646                                                               pHwMboxCmdBit->PltData.RxPer.PltRxPer.SeqNumMissCountRef);
    647 
    648 
    649      /* Call the saved CB function (if any)*/
    650      if (pHwMboxCmdBit->PltData.RxPer.CB_Func)
    651      {
    652          CB_Func = (CmdQueue_InterrogateCB_t)(pHwMboxCmdBit->PltData.RxPer.CB_Func);
    653          CB_Func(pHwMboxCmdBit->PltData.RxPer.CB_Handle, MboxStatus, &(pHwMboxCmdBit->PltData.RxPer));
    654      }
    655  }
    656 
    657 
    658 
    659 /****************************************************************************
    660  *                      whal_hwCmdBit_TestCmd()
    661  ****************************************************************************
    662  * DESCRIPTION:
    663  * INPUTS: None
    664  *
    665  * OUTPUT:  None
    666  *
    667  * RETURNS: OK or NOK
    668  ****************************************************************************/
    669 int whal_hwCmdBit_TestCmd(HwMboxCmdBit_T *pHwMboxCmdBit, void *CB_Func, TI_HANDLE CB_Handle, TestCmd_t* pTestCmd_Buf)
    670 {
    671      int bIsCBfuncNecessary=TRUE;
    672 
    673      WLAN_REPORT_INFORMATION(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    674      ("%s CB_Handle=0x%p, CB_Func=0x%p, pTestCmd_Buf=%p\n",__FUNCTION__, CB_Handle, CB_Func, pTestCmd_Buf));
    675 
    676      if (NULL == pTestCmd_Buf)
    677      {
    678          WLAN_REPORT_ERROR(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    679          ("%s pTestCmd_Buf = NULL!!!\n",__FUNCTION__));
    680 
    681          return NOK;
    682      }
    683 
    684      WLAN_REPORT_INFORMATION(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    685      ("%s pTestCmd_Buf->testCmdId=%d\n",__FUNCTION__, pTestCmd_Buf->testCmdId));
    686 
    687      WLAN_REPORT_INFORMATION(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    688      ("%s pTestCmd_Buf (HEX DUMP):\n",__FUNCTION__));
    689      WLAN_REPORT_HEX_INFORMATION(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    690          (PUINT8)pTestCmd_Buf, sizeof(TestCmd_t));
    691 
    692 
    693      switch((TestCmdID_enum)pTestCmd_Buf->testCmdId)
    694      {
    695      case TEST_CMD_FCC:
    696      case TEST_CMD_TELEC:
    697      case TEST_CMD_PLT_FCC_TELEC_TX_STOP:
    698      case TEST_CMD_RADIO_TUNE:
    699         bIsCBfuncNecessary = FALSE;
    700         break;
    701 
    702      case TEST_CMD_PLT_GAIN_ADJUST:
    703      case TEST_CMD_PLT_TXPOWER_CAL_START:
    704      case TEST_CMD_PLT_TXPOWER_CAL_STOP:
    705      case TEST_CMD_PLT_GAIN_GET:
    706      case TEST_CMD_PLT_GET_NVS_UPDATE_BUFFER:
    707          bIsCBfuncNecessary = TRUE;
    708          break;
    709 
    710      case TEST_CMD_PLT_RX_CALIBRATION:
    711          /* Mark that a calibration operation is pending */
    712          pHwMboxCmdBit->PltData.RxTxCal.lastStatus = PENDING;
    713          /* Save the CB for the command response (GWSI oriented) */
    714          pHwMboxCmdBit->PltData.RxTxCal.CB_Func = CB_Func;
    715          pHwMboxCmdBit->PltData.RxTxCal.CB_Handle = CB_Handle;
    716 
    717          CB_Func = (void*)whal_hwCmdBit_RxCal_CB;
    718          CB_Handle = (TI_HANDLE)pHwMboxCmdBit;
    719          bIsCBfuncNecessary = TRUE;
    720          break;
    721 
    722      default:
    723      WLAN_REPORT_WARNING(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    724      ("%s Unsupported TestCmdId (%d)\n",__FUNCTION__, pTestCmd_Buf->testCmdId));
    725          break;
    726      }
    727 
    728     /* Send the command */
    729     if (CB_Func)
    730     {
    731          return (CmdQueue_CommandWithCb(pHwMboxCmdBit->hCmdQueue, CMD_TEST, (char *)pTestCmd_Buf, sizeof(*pTestCmd_Buf),
    732                                         CB_Func, CB_Handle, (void*)pTestCmd_Buf));
    733     }
    734     else
    735     {
    736         if (bIsCBfuncNecessary)
    737             return NOK;
    738         else
    739             return (CmdQueue_Command(pHwMboxCmdBit->hCmdQueue, CMD_TEST, (char *)pTestCmd_Buf, sizeof(*pTestCmd_Buf) ));
    740     }
    741 
    742 }/* END whal_hwCmdBit_TestCmd() */
    743 
    744 
    745 /****************************************************************************
    746  *                      whal_hwCmdBit_RxCal_CB()
    747  ****************************************************************************
    748  * DESCRIPTION:   Returns the accumulated counters.
    749  * INPUTS: None
    750  *
    751  * OUTPUT:  None
    752  *
    753  * RETURNS: OK or NOK
    754  ****************************************************************************/
    755 void whal_hwCmdBit_RxCal_CB(TI_HANDLE objectHandle,UINT16 MboxStatus,void *InterrogateParamsBuf)
    756 {
    757     HwMboxCmdBit_T *pHwMboxCmdBit = (HwMboxCmdBit_T*)objectHandle;
    758     CmdQueue_InterrogateCB_t CB_Func;
    759 
    760     WLAN_REPORT_INFORMATION(pHwMboxCmdBit->hReport, HAL_HW_CTRL_MODULE_LOG,
    761         ("%s MboxStatus = 0x%x\n",
    762        __FUNCTION__, MboxStatus));
    763 
    764     /* If there was an error in the RX Calibration command, mark the NOK status here rather than
    765         from the RX calibration complete event callback function (the event won't be sent)*/
    766     if (OK != MboxStatus)
    767     {
    768         pHwMboxCmdBit->PltData.RxTxCal.lastStatus = NOK;
    769     }
    770 
    771     /* Call the saved CB function (if any)*/
    772     if (pHwMboxCmdBit->PltData.RxTxCal.CB_Func)
    773     {
    774         CB_Func = (CmdQueue_InterrogateCB_t)(pHwMboxCmdBit->PltData.RxTxCal.CB_Func);
    775         CB_Func(pHwMboxCmdBit->PltData.RxTxCal.CB_Handle, MboxStatus, &pHwMboxCmdBit->PltData.RxTxCal);
    776     }
    777 
    778 }
    779 
    780 
    781  /****************************************************************************
    782  *                      whal_hwCmdBit_RxCal_Complete_Event_CB()
    783  ****************************************************************************
    784  * DESCRIPTION:   Returns the accumulated counters.
    785  * INPUTS: None
    786  *
    787  * OUTPUT:  None
    788  *
    789  * RETURNS: OK or NOK
    790  ****************************************************************************/
    791 void whal_hwCmdBit_RxCal_Complete_Event_CB( TI_HANDLE objectHandle, char* str, UINT32 strLen )
    792 {
    793     HwMboxCmdBit_T *pHwMboxCmdBit = (HwMboxCmdBit_T*)objectHandle;
    794 
    795     /* mark the status as completed */
    796     pHwMboxCmdBit->PltData.RxTxCal.lastStatus = OK;
    797 }
    798 
    799  /****************************************************************************
    800  *                      whal_hwCmdBit_GetPltRxCalibrationStatus()
    801  ****************************************************************************
    802  * DESCRIPTION:   Returns whether the last RX calibration is pending.
    803  * INPUTS: None
    804  *
    805  * OUTPUT:  None
    806  *
    807  * RETURNS: None
    808  ****************************************************************************/
    809 void whal_hwCmdBit_GetPltRxCalibrationStatus( TI_HANDLE objectHandle, TI_STATUS* pLastStatus  )
    810 {
    811     HwMboxCmdBit_T *pHwMboxCmdBit = (HwMboxCmdBit_T*)objectHandle;
    812 
    813     /* return the status of the last RX calibration */
    814     *pLastStatus = pHwMboxCmdBit->PltData.RxTxCal.lastStatus;
    815 }
    816