tracesrv/reference/sf/adapt/osrndtools.nokia/xtiv2/drivers/src/xtitx.cpp
branchBUG 3869 Reference XTI device driver for Open System Trace
changeset 61 0e5a77c79f1e
equal deleted inserted replaced
60:e54443a6878c 61:0e5a77c79f1e
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /** @file
       
    20 
       
    21 XtiTx
       
    22 
       
    23 *///=========================================================================
       
    24 
       
    25 
       
    26 //- Include Files  ----------------------------------------------------------
       
    27 
       
    28 #include <kernel/kern_priv.h>
       
    29 #include <rap.h>
       
    30 #include "xtitx.h"
       
    31 //- Namespace ---------------------------------------------------------------
       
    32 
       
    33 //- Using -------------------------------------------------------------------
       
    34 
       
    35 
       
    36 //- External Data -----------------------------------------------------------
       
    37 
       
    38 
       
    39 //- External Function Prototypes --------------------------------------------
       
    40 
       
    41 
       
    42 //- Constants ---------------------------------------------------------------
       
    43 
       
    44 // Definitions for XTI
       
    45 
       
    46 const TUint8  KHwOsmoMsgAsciiPrintfLE       = 0xC3;
       
    47 const TUint32 KHwOsmoChannelSize            = 0x40L;
       
    48 
       
    49 const TInt    KBitRateBufferSize            = 20; 
       
    50 const TUint8  KDataLengthAck                = 0x01;
       
    51 const TUint8  KDataMsgAck                   = 0x02;
       
    52 
       
    53 const TUint32 KHwOsmoControlOutputAddress   = KRapRegXTIOSMO + ( KOsmoTraceControlChannel * KXtiChannelSize );
       
    54 
       
    55 const TUint32 KHwOsmoSymbianChannel0Address = KRapRegXTIOSMO + ( KOsmoSymbianSystemChannel0 * KXtiChannelSize );
       
    56 
       
    57 const TUint32 KHwOsmoSymbianChannel1Address = KRapRegXTIOSMO + ( KOsmoSymbianSystemChannel1 * KXtiChannelSize );
       
    58 
       
    59 const TUint32 KHwOsmoTraceBoxConfigAddress  = KRapRegXTIOSMO + ( KOsmoTraceBoxConfigChannel * KHwOsmoChannelSize );
       
    60 
       
    61 const TUint32 KHwOsmoReceptionAckAddress    = KRapRegXTIOSMO + ( KOsmosReceptionAckChannel * KHwOsmoChannelSize );
       
    62 
       
    63 
       
    64 //- Macros ------------------------------------------------------------------
       
    65 
       
    66 
       
    67 //- Global and Local Variables ----------------------------------------------
       
    68 
       
    69 XtiTx* XtiTx::iXtiTxPtr = NULL;
       
    70 
       
    71 //- Local Function Prototypes -----------------------------------------------
       
    72 
       
    73 
       
    74 //===========================================================================
       
    75 
       
    76 //- Local Functions ---------------------------------------------------------
       
    77 
       
    78 //===========================================================================
       
    79 
       
    80 //- Member Functions --------------------------------------------------------
       
    81 
       
    82 /*
       
    83 -----------------------------------------------------------------------------
       
    84 
       
    85     XtiTx
       
    86 
       
    87     XtiTx
       
    88     
       
    89     Constructor
       
    90 -----------------------------------------------------------------------------
       
    91 */
       
    92 
       
    93 XtiTx::XtiTx()
       
    94     : iSymbianChannel0Open( EFalse )
       
    95      ,iSymbianChannel1Open( EFalse )
       
    96      ,iTraceEnabled( EFalse )
       
    97     {
       
    98     }
       
    99 
       
   100 
       
   101 /*
       
   102 -----------------------------------------------------------------------------
       
   103     XtiTx
       
   104 
       
   105     ~XtiTx
       
   106     
       
   107     Destructor
       
   108 -----------------------------------------------------------------------------
       
   109 */
       
   110 XtiTx::~XtiTx()
       
   111     {
       
   112     }
       
   113 
       
   114 /*
       
   115 ----------------------------------------------------------------------------
       
   116 
       
   117     XtiTx
       
   118 
       
   119     Instance
       
   120 
       
   121     Return an instance to XtiTx interface. This method returns the
       
   122     only XtiTx instance system can have, it is not possible to create
       
   123     new instances of this class.
       
   124 
       
   125     Return Values:          iXtiTxPtr* An instance to XtiTx class
       
   126 
       
   127 -----------------------------------------------------------------------------
       
   128 */
       
   129 XtiTx* XtiTx::Instance( )
       
   130     {
       
   131     // Allow only 1 instance of XtiTx to exists at any time
       
   132     if ( iXtiTxPtr == NULL )
       
   133         {
       
   134         iXtiTxPtr = new XtiTx();
       
   135         if( iXtiTxPtr != NULL )
       
   136             {
       
   137             if( iXtiTxPtr->CheckRDC() )
       
   138                 {
       
   139                 iXtiTxPtr->iTraceEnabled = ETrue;
       
   140                 }
       
   141             else
       
   142                 {
       
   143                 iXtiTxPtr->iTraceEnabled = EFalse;
       
   144                 }
       
   145             }                                
       
   146         }
       
   147     return iXtiTxPtr;
       
   148     }
       
   149 
       
   150 
       
   151 
       
   152 /*
       
   153 ----------------------------------------------------------------------------
       
   154 
       
   155     XtiTx
       
   156 
       
   157     StartWrite
       
   158 
       
   159     Start writing data to Symbian XTI channel. This method must be called before WriteData8, WriteData16 or 
       
   160     WriteData32 can be used.                 
       
   161     
       
   162     @param   aChannel     XTI channel number. Must be KOsmoSymbianSystemChannel0 or KOsmoSymbianSystemChannel1 
       
   163     
       
   164     @param   aMessageId   XTI message ID. Defines what type of messages are sent.
       
   165                           Must be KOsmoMsgSymbianTrace or KOsmoMsgAsciiPrintf.
       
   166 
       
   167     Return Values:        KErrNone, if succesfull. Otherwise KErrGeneral
       
   168 
       
   169 -----------------------------------------------------------------------------
       
   170 */
       
   171 EXPORT_C TInt XtiTx::StartWrite( TUint8 aChannel, TUint8 aMessageId )
       
   172     {
       
   173     TInt ret( KErrNone );
       
   174     // Message type must be MCU Symbian trace message or MCU ASCII printf message
       
   175     if( CheckMessageIdForStartWrite(aMessageId) && iXtiTxPtr->iTraceEnabled )
       
   176         {
       
   177          // OSMO channel must be 224 or 225
       
   178         if( aChannel == KOsmoSymbianSystemChannel0 )
       
   179             {
       
   180             // Check that the channel is free
       
   181             if( iXtiTxPtr->iSymbianChannel0Open == EFalse )
       
   182                 {
       
   183                 // Open the channel
       
   184                 TRap::SetRegister8( aMessageId, KHwOsmoSymbianChannel0Address );
       
   185                 iXtiTxPtr->iSymbianChannel0Open = ETrue;
       
   186                 }
       
   187             else
       
   188                 {
       
   189                 ret = KErrGeneral;
       
   190                 }
       
   191             }
       
   192         else if( aChannel == KOsmoSymbianSystemChannel1 )
       
   193             {
       
   194             // Check that the channel is free
       
   195             if( iXtiTxPtr->iSymbianChannel1Open == EFalse )
       
   196                 {
       
   197                 // Open the channel
       
   198                 TRap::SetRegister8( aMessageId, KHwOsmoSymbianChannel1Address );
       
   199                 iXtiTxPtr->iSymbianChannel1Open = ETrue;
       
   200                 }
       
   201             else
       
   202                 {
       
   203                 ret = KErrGeneral;
       
   204                 }                
       
   205             }
       
   206         else
       
   207             {
       
   208             ret = KErrGeneral;
       
   209             }
       
   210         }
       
   211     else
       
   212         {
       
   213         ret = KErrGeneral;
       
   214         }
       
   215     return ret;
       
   216     }
       
   217 
       
   218 /*
       
   219 ----------------------------------------------------------------------------
       
   220 
       
   221     XtiTx
       
   222 
       
   223     StopWrite
       
   224 
       
   225     Stop writing data to Symbian XTI channel which has been started by method StartWrite().
       
   226     
       
   227     Return Values:        KErrNone, if succesfull. Otherwise KErrGeneral                 
       
   228     
       
   229 -----------------------------------------------------------------------------
       
   230 */
       
   231 EXPORT_C TInt XtiTx::StopWrite( TUint8 aChannel )
       
   232     {
       
   233     TInt ret( KErrNone );
       
   234     
       
   235     // OSMO channel must be 224 or 225
       
   236     if( aChannel == KOsmoSymbianSystemChannel0 )
       
   237        {
       
   238        // Check that the channel is opened
       
   239         if( iXtiTxPtr->iSymbianChannel0Open )
       
   240             {
       
   241             // close the channel
       
   242             TRap::SetRegister8( KOsmoSymbianSystemChannel0, KHwOsmoControlOutputAddress );
       
   243             iXtiTxPtr->iSymbianChannel0Open = EFalse;
       
   244             }
       
   245         else
       
   246             {
       
   247             ret = KErrGeneral;
       
   248             }            
       
   249         }
       
   250     else if( aChannel == KOsmoSymbianSystemChannel1 )
       
   251         {
       
   252         // Check that the channel is opened
       
   253         if( iXtiTxPtr->iSymbianChannel1Open )
       
   254             {
       
   255             // close the channel
       
   256             TRap::SetRegister8( KOsmoSymbianSystemChannel1, KHwOsmoControlOutputAddress );
       
   257             iXtiTxPtr->iSymbianChannel1Open = EFalse;
       
   258             }
       
   259         else
       
   260             {
       
   261             ret = KErrGeneral;
       
   262             }            
       
   263         }
       
   264     else
       
   265         {        
       
   266         ret = KErrGeneral;
       
   267         }
       
   268     return ret;
       
   269     }
       
   270 
       
   271 /*
       
   272 ----------------------------------------------------------------------------
       
   273 
       
   274     XtiTx
       
   275 
       
   276     WriteData8
       
   277 
       
   278     Write 8 bits data to KOsmoSymbianSystemChannel0 or KOsmoSymbianSystemChannel1
       
   279     XTI channel in KOsmoMsgSymbianTrace or KOsmoMsgAsciiPrintf message format.
       
   280     Before using this method XTI channel and message type must be defined with
       
   281     method XtiTx::StartWrite().
       
   282     
       
   283     @param   aData     Data to be written
       
   284     
       
   285 -----------------------------------------------------------------------------
       
   286 */
       
   287 EXPORT_C void XtiTx::WriteData8( TUint8 aChannel, TUint8 aData )
       
   288     {
       
   289     // OSMO channel must be 224 or 225
       
   290     if( aChannel == KOsmoSymbianSystemChannel0 )
       
   291         {
       
   292         // Check that the channel is opened
       
   293         if( iXtiTxPtr->iSymbianChannel0Open )
       
   294             {
       
   295             // Send data
       
   296             TRap::SetRegister8( aData, KHwOsmoSymbianChannel0Address );
       
   297             }
       
   298         }
       
   299     else if( aChannel == KOsmoSymbianSystemChannel1 )
       
   300         {
       
   301         // Check that the channel is opened
       
   302         if( iXtiTxPtr->iSymbianChannel1Open )
       
   303             {
       
   304             // Send data
       
   305             TRap::SetRegister8( aData, KHwOsmoSymbianChannel1Address );
       
   306             }
       
   307         }
       
   308     }
       
   309 
       
   310 
       
   311 /*
       
   312 ----------------------------------------------------------------------------
       
   313 
       
   314     XtiTx
       
   315 
       
   316     WriteData16
       
   317 
       
   318     Write 16 bits data to KOsmoSymbianSystemChannel0 or KOsmoSymbianSystemChannel1
       
   319     XTI channel in KOsmoMsgSymbianTrace or KOsmoMsgAsciiPrintf message format.
       
   320     Before using this method XTI channel and message type must be defined with
       
   321     method XtiTx::StartWrite().
       
   322     
       
   323     @param   aData     Data to be written
       
   324 
       
   325 -----------------------------------------------------------------------------
       
   326 */
       
   327 EXPORT_C void XtiTx::WriteData16( TUint8 aChannel, TUint16 aData )
       
   328     {
       
   329     // OSMO channel must be 224 or 225
       
   330     if( aChannel == KOsmoSymbianSystemChannel0 )
       
   331         {
       
   332         // Check that the channel is opened
       
   333         if( iXtiTxPtr->iSymbianChannel0Open )
       
   334             {
       
   335             // Send data
       
   336             TRap::SetRegister16( aData, KHwOsmoSymbianChannel0Address );
       
   337             }
       
   338         }
       
   339     else if( aChannel == KOsmoSymbianSystemChannel1 )
       
   340         {
       
   341         // Check that the channel is opened
       
   342         if( iXtiTxPtr->iSymbianChannel1Open )
       
   343             {
       
   344             // Send data
       
   345             TRap::SetRegister16( aData, KHwOsmoSymbianChannel1Address );
       
   346             }
       
   347         }
       
   348     }
       
   349 
       
   350 
       
   351 /*
       
   352 ----------------------------------------------------------------------------
       
   353 
       
   354     XtiTx
       
   355 
       
   356     WriteData32
       
   357 
       
   358     Write 32 bits data to KOsmoSymbianSystemChannel0 or KOsmoSymbianSystemChannel1
       
   359     XTI channel in KOsmoMsgSymbianTrace or KOsmoMsgAsciiPrintf message format.
       
   360     Before using this method XTI channel and message type must be defined with
       
   361     method XtiTx::StartWrite().
       
   362     
       
   363     @param   aData     Data to be written
       
   364 
       
   365 -----------------------------------------------------------------------------
       
   366 */
       
   367 EXPORT_C void XtiTx::WriteData32( TUint8 aChannel, TUint32 aData )
       
   368     {
       
   369     // OSMO channel must be 224 or 225
       
   370     if( aChannel == KOsmoSymbianSystemChannel0 )
       
   371         {
       
   372         // Check that the channel is opened
       
   373         if( iXtiTxPtr->iSymbianChannel0Open )
       
   374             {
       
   375             // Send data
       
   376             TRap::SetRegister32( aData, KHwOsmoSymbianChannel0Address );
       
   377             }
       
   378         }
       
   379     else if( aChannel == KOsmoSymbianSystemChannel1 )
       
   380         {
       
   381         // Check that the channel is opened
       
   382         if( iXtiTxPtr->iSymbianChannel1Open )
       
   383             {
       
   384             // Send data
       
   385             TRap::SetRegister32( aData, KHwOsmoSymbianChannel1Address );
       
   386             }
       
   387         }
       
   388     }    
       
   389 
       
   390 /*
       
   391 ----------------------------------------------------------------------------
       
   392 
       
   393     XtiTx
       
   394 
       
   395     SetBitRate
       
   396 
       
   397     Sends set bit rate command to Musti
       
   398 
       
   399     @param   aBitRate     Uart bit rate
       
   400 
       
   401 -----------------------------------------------------------------------------
       
   402 */
       
   403 EXPORT_C void XtiTx::SetBitRate( TUint aBitRate )
       
   404     {
       
   405     if( iXtiTxPtr->iTraceEnabled )
       
   406         {
       
   407         TBuf8<KBitRateBufferSize> string;
       
   408 
       
   409         string.Append(_L("!B"));
       
   410 	    string.AppendNum( aBitRate, EDecimal );
       
   411     
       
   412         // Send Symbian trace activation message
       
   413         TRap::SetRegister8( KHwOsmoMsgAsciiPrintfLE, KHwOsmoTraceBoxConfigAddress );
       
   414 
       
   415         // Send data
       
   416         for (TInt i = 0; i < string.Length(); i++ )
       
   417             {
       
   418             TRap::SetRegister8( string[i], KHwOsmoTraceBoxConfigAddress );
       
   419             }
       
   420 
       
   421         // Complete message
       
   422         TRap::SetRegister8( KOsmoTraceBoxConfigChannel, KHwOsmoControlOutputAddress );
       
   423         }
       
   424     }
       
   425 
       
   426 /*
       
   427 ----------------------------------------------------------------------------
       
   428 
       
   429     XtiTx
       
   430 
       
   431     SendDataLenAckMsg
       
   432     
       
   433     Sends acknowledgement for data length message to Musti
       
   434    
       
   435 -----------------------------------------------------------------------------
       
   436 */                                  
       
   437 EXPORT_C void XtiTx::SendDataLenAckMsg( )
       
   438     {
       
   439     if( iXtiTxPtr->iTraceEnabled )
       
   440         {        
       
   441         // Send Symbian trace activation message
       
   442         TRap::SetRegister8( KHwOsmoMsgAsciiPrintfLE, KHwOsmoReceptionAckAddress );
       
   443         TRap::SetRegister8( KDataLengthAck, KHwOsmoReceptionAckAddress );
       
   444         // Complete message
       
   445         TRap::SetRegister8( KOsmosReceptionAckChannel, KHwOsmoControlOutputAddress );
       
   446         }
       
   447     }
       
   448 
       
   449 /*
       
   450 ----------------------------------------------------------------------------
       
   451 
       
   452     XtiTx
       
   453 
       
   454     SendDataLenAckMsg
       
   455    
       
   456     Sends acknowledgement for data message to Musti
       
   457 
       
   458 -----------------------------------------------------------------------------
       
   459 */                                  
       
   460 EXPORT_C void XtiTx::SendDataRxAckMsg( )
       
   461     {
       
   462     if( iXtiTxPtr->iTraceEnabled )
       
   463         {
       
   464         // Send Symbian trace activation message
       
   465         TRap::SetRegister8( KHwOsmoMsgAsciiPrintfLE, KHwOsmoReceptionAckAddress );
       
   466         TRap::SetRegister8( KDataMsgAck, KHwOsmoReceptionAckAddress );
       
   467         // Complete message
       
   468         TRap::SetRegister8( KOsmosReceptionAckChannel, KHwOsmoControlOutputAddress );
       
   469         }
       
   470     }
       
   471 
       
   472 /*
       
   473 ----------------------------------------------------------------------------
       
   474 
       
   475     XtiTx
       
   476 
       
   477     IsTraceEnabled
       
   478 
       
   479     Returns the flag that tells if traces are enabled
       
   480     
       
   481     @Return EFalse if traces not enabled in RDC, otherwise true
       
   482     
       
   483 -----------------------------------------------------------------------------
       
   484 */
       
   485 
       
   486 
       
   487 EXPORT_C TBool XtiTx::IsTraceEnabled()
       
   488     {
       
   489     return iXtiTxPtr != NULL && iXtiTxPtr->iTraceEnabled;
       
   490     }
       
   491 
       
   492 
       
   493 /*
       
   494 ----------------------------------------------------------------------------
       
   495 
       
   496     XtiTx
       
   497 
       
   498     CheckMessageIdForStartWrite
       
   499 
       
   500     Checks message ID is valid for writing
       
   501     
       
   502     @param   aMessageId   XTI message ID. Defines what type of messages are sent.
       
   503                           Must be KOsmoMsgSymbianTrace, KOsmoMsgAsciiPrintf, or KOsmoMsgPhoneFormatted.
       
   504 
       
   505     @Return EFalse if traces not enabled in RDC, otherwise true
       
   506     
       
   507 -----------------------------------------------------------------------------
       
   508 */
       
   509 
       
   510 
       
   511 TBool XtiTx::CheckMessageIdForStartWrite( TUint8 aMessageId )
       
   512     {
       
   513     // Message type must be MCU Symbian trace message or MCU ASCII printf message or Phone Formatted
       
   514     if( aMessageId == KOsmoMsgSymbianTrace || aMessageId == KOsmoMsgAsciiPrintf || aMessageId == KOsmoMsgPhoneFormatted )
       
   515         {
       
   516         return ETrue;
       
   517         }
       
   518     return EFalse;
       
   519     }
       
   520 
       
   521 
       
   522 /*
       
   523 ----------------------------------------------------------------------------
       
   524 
       
   525     XtiTx
       
   526 
       
   527     CheckRDC
       
   528 
       
   529     Checks R&D Certificate status bit in test ram
       
   530     
       
   531     @Return EFalse if traces not enabled in RDC, otherwise true
       
   532     
       
   533 -----------------------------------------------------------------------------
       
   534 */
       
   535 
       
   536 
       
   537 TBool XtiTx::CheckRDC()
       
   538 	{
       
   539     return ETrue;
       
   540 	}
       
   541 
       
   542 
       
   543 //===========================================================================
       
   544 
       
   545 //- Global Functions --------------------------------------------------------
       
   546 
       
   547 //---------------------------------------------------------------------------
       
   548 /**
       
   549     The entry point for a standard extension. Creates XtiTx extension.
       
   550 
       
   551     @return KErrNone, if successful
       
   552 */
       
   553 DECLARE_STANDARD_EXTENSION()    
       
   554     {
       
   555     TInt ret( KErrNoMemory );
       
   556 
       
   557     if ( XtiTx::Instance() != NULL )
       
   558         {
       
   559         ret = KErrNone;
       
   560         }
       
   561 
       
   562     return ret;
       
   563     }                 
       
   564 
       
   565 //- Namespace ---------------------------------------------------------------
       
   566 
       
   567 // End of File