navienginebsp/naviengine_assp/i2s/i2s_pil.cpp
changeset 0 5de814552237
equal deleted inserted replaced
-1:000000000000 0:5de814552237
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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 * bsp\hwip_nec_navienegine\navienegine_assp\i2s\i2s_pil.cpp
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <kernel/kernel.h>
       
    22 #include "navi_i2s.h"
       
    23 
       
    24 #define CHANNEL_ID_FROM_INTERFACE_ID(aId)	(TUint16)aId		// channel ID on bottom 16 bits (as returned by Configuration Repository)
       
    25 
       
    26 TInt TI2sManager::iChannelsNum = 0;
       
    27 DI2sChannelBase** TI2sManager::iChannels = 0;
       
    28 
       
    29 TInt TI2sManager::DoCreate()
       
    30 	{
       
    31 	TInt err=KErrNone;
       
    32 	//		(TBD) Must call into ConfRep to obtain the number of channels present and store it in iChannelsNum and create a list of all interfaces supported.
       
    33 	//		Then iterate through the list of interfaces and create channels.
       
    34 	//		This way, each channel implementation can be written independently from the others, and brroght
       
    35 	//		together at the end at the cost of a virtaul pointer dereferencing. (Incidentaly that is totally
       
    36 	//		irrelevant for the NaviEngine implementation where all channels are implemented in a single file
       
    37 	//		but we present this code as an example of how it could be done in a situation of need)
       
    38 	
       
    39 	iChannelsNum=4;		// TBD: for now, in future need to call into ConfRep
       
    40 
       
    41 	TInt* chanArray=(TInt*)Kern::Alloc(iChannelsNum*sizeof(TInt));	// allocate a temporary array of interface Ids to populate with ConfRep data
       
    42 	if(!chanArray)
       
    43 		return KErrNoMemory;
       
    44 
       
    45 	DI2sChannelBase** channels=(DI2sChannelBase**)Kern::Alloc(iChannelsNum*sizeof(DI2sChannelBase*));	// allocate an array of pointers to channels (stored in iChannels)
       
    46 	if(!channels)
       
    47 		return KErrNoMemory;
       
    48 
       
    49 	for(TInt i=0; i<iChannelsNum;i++)	// TBD: for now, in future need to call into ConfRep to populate the array of interface Ids
       
    50 		chanArray[i]=i;	// without ConfRep, interface Ids are just the channel numbers
       
    51 	
       
    52 	DI2sChannelBase* chan=NULL;
       
    53 	for(TInt j=0;j<iChannelsNum;j++)
       
    54 		{
       
    55 		err=DI2sChannelBase::CreateChannels(chan,chanArray[j]);	// this creates the channel corresponding to the interface Id passed and return it in chan
       
    56 		if(chan)
       
    57 			channels[j]=chan;		// j is the channel number
       
    58 		else
       
    59 			{
       
    60 			err=KErrNotFound;
       
    61 			break;
       
    62 			}
       
    63 		}
       
    64 	if(err==KErrNone)
       
    65 		iChannels=channels;
       
    66 	Kern::Free(chanArray);	// no longer need this
       
    67 	return err;
       
    68 	}
       
    69 
       
    70 /**,
       
    71  Configures the interface.
       
    72  
       
    73  @param aInterfaceId	The interface Id.
       
    74  @param aConfig		A pointer to the configuration as one of TI2sConfigBufV01 or greater.
       
    75 
       
    76  @return 	KErrNone, if successful; 
       
    77  KErrArgument, if aInterfaceId is invalid or aConfig is NULL;
       
    78  KErrNotSupported, if the configuration is not supported by this interface;
       
    79  KErrInUse, if interface is not quiescient (a transfer is under way).
       
    80  */
       
    81 EXPORT_C TInt I2s::ConfigureInterface(TInt aInterfaceId, TDes8* aConfig)
       
    82 	{
       
    83 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
    84 	if((chanId >= TI2sManager::iChannelsNum) || !aConfig)
       
    85 		return KErrArgument;
       
    86 	 
       
    87 	return TI2sManager::iChannels[chanId]->ConfigureInterface(aConfig);
       
    88 	}
       
    89 
       
    90 /**
       
    91  Reads the current configuration.
       
    92  
       
    93  @param aInterfaceId	The interface Id.
       
    94  @param aConfig		On return, the buffer passed is filled with the current configuration.
       
    95 
       
    96  @return 	KErrNone, if successful; 
       
    97  KErrArgument, if aInterfaceId is invalid.
       
    98  */
       
    99 EXPORT_C TInt I2s::GetInterfaceConfiguration(TInt aInterfaceId, TDes8& aConfig)
       
   100 	{
       
   101 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   102 	if(chanId >= TI2sManager::iChannelsNum)
       
   103 		return KErrArgument;
       
   104 
       
   105 	return TI2sManager::iChannels[chanId]->GetInterfaceConfiguration(aConfig);
       
   106 	}
       
   107 
       
   108 /**
       
   109  Sets the sampling rate.
       
   110  
       
   111  @param aInterfaceId	 The interface Id.
       
   112  @param aSamplingRate One of TI2sSamplingRate.
       
   113 
       
   114  @return 	KErrNone, if successful; 
       
   115  KErrArgument, if aInterfaceId is invalid;
       
   116  KErrNotSupported, if the sampling rate is not supported by this interface;
       
   117  KErrInUse, if interface is not quiescient (a transfer is under way).
       
   118  */
       
   119 EXPORT_C TInt I2s::SetSamplingRate(TInt aInterfaceId, TI2sSamplingRate aSamplingRate)
       
   120 	{
       
   121 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   122 	if(chanId >= TI2sManager::iChannelsNum)
       
   123 		return KErrArgument;
       
   124 
       
   125 	return TI2sManager::iChannels[chanId]->SetSamplingRate(aSamplingRate);
       
   126 	}
       
   127 
       
   128 /**
       
   129  Reads the sampling rate.
       
   130  
       
   131  @param aInterfaceId	 The interface Id.
       
   132  @param aSamplingRate On return, contains one of TI2sSamplingRate.
       
   133 
       
   134  @return 	KErrNone, if successful; 
       
   135  KErrArgument, if aInterfaceId is invalid.
       
   136  */
       
   137 EXPORT_C TInt I2s::GetSamplingRate(TInt aInterfaceId, TInt& aSamplingRate)
       
   138 	{
       
   139 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   140 	if(chanId >= TI2sManager::iChannelsNum)
       
   141 		return KErrArgument;
       
   142 
       
   143 	return TI2sManager::iChannels[chanId]->GetSamplingRate(aSamplingRate);
       
   144 	}
       
   145 
       
   146 /**
       
   147  Sets the frame length and format.
       
   148 
       
   149  @param aInterfaceId		  The interface Id.
       
   150  @param aFrameLength		  One of TI2sFrameLength.
       
   151  @param aLeftFramePhaseLength The length of the left frame phase (in number of data bits).
       
   152 
       
   153  @return 	KErrNone, if successful; 
       
   154  KErrArgument, if aInterfaceId is invalid;
       
   155  KErrNotSupported, if the frame length or format are not supported by this interface;
       
   156  KErrInUse, if interface is not quiescient (a transfer is under way).
       
   157 		   
       
   158  The implementation calculates the Right frame phase length as (FrameLength - LeftFramePhaseLength)
       
   159  */
       
   160 EXPORT_C TInt I2s::SetFrameLengthAndFormat(TInt aInterfaceId, TI2sFrameLength aFrameLength, TInt aLeftFramePhaseLength)
       
   161 	{
       
   162 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   163 	if(chanId >= TI2sManager::iChannelsNum)
       
   164 		return KErrArgument;
       
   165 
       
   166 	return TI2sManager::iChannels[chanId]->SetFrameLengthAndFormat(aFrameLength, aLeftFramePhaseLength);
       
   167 	}
       
   168 
       
   169 /**
       
   170  Reads the frame format.
       
   171 
       
   172  @param aInterfaceId			 The interface Id.
       
   173  @param aLeftFramePhaseLength  On return, contains the length of the left frame phase.
       
   174  @param aRightFramePhaseLength On return, contains the length of the right frame phase.
       
   175 
       
   176  @return 	KErrNone, if successful; 
       
   177  KErrArgument, if aInterfaceId is invalid.
       
   178  */
       
   179 EXPORT_C TInt I2s::GetFrameFormat(TInt aInterfaceId, TInt& aLeftFramePhaseLength, TInt& aRightFramePhaseLength)
       
   180 	{
       
   181 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   182 	if(chanId >= TI2sManager::iChannelsNum)
       
   183 		return KErrArgument;
       
   184 
       
   185 	return TI2sManager::iChannels[chanId]->GetFrameFormat(aLeftFramePhaseLength, aRightFramePhaseLength);
       
   186 	}
       
   187 
       
   188 /**
       
   189  Sets the sample length for a frame phase (left or right).
       
   190  
       
   191  @param aInterfaceId	 The interface Id.
       
   192  @param aFramePhase	 One of TI2sFramePhase.
       
   193  @param aSampleLength One of TI2sSampleLength.
       
   194 
       
   195  @return 	KErrNone, if successful; 
       
   196  KErrArgument, if aInterfaceId is invalid;
       
   197  KErrNotSupported, if the sample length for the frame phase selected is not supported by this interface;
       
   198  KErrInUse, if interface is not quiescient (a transfer is under way).
       
   199  */
       
   200 EXPORT_C TInt I2s::SetSampleLength(TInt aInterfaceId, TI2sFramePhase aFramePhase, TI2sSampleLength aSampleLength)
       
   201 	{
       
   202 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   203 	if(chanId >= TI2sManager::iChannelsNum)
       
   204 		return KErrArgument;
       
   205 
       
   206 	return TI2sManager::iChannels[chanId]->SetSampleLength(aFramePhase, aSampleLength);
       
   207 	}
       
   208 
       
   209 /**
       
   210  Reads the sample length for a frame phase (left or right).
       
   211  
       
   212  @param aInterfaceId	 The interface Id.
       
   213  @param aFramePhase	 One of TI2sFramePhase.
       
   214  @param aSampleLength On return, contains the sample length for the frame phase indicated by aFramePhase.
       
   215 
       
   216  @return 	KErrNone, if successful; 
       
   217  KErrArgument, if aInterfaceId is invalid.
       
   218  */
       
   219 EXPORT_C TInt I2s::GetSampleLength(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt& aSampleLength)
       
   220 	{
       
   221 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   222 	if(chanId >= TI2sManager::iChannelsNum)
       
   223 		return KErrArgument;
       
   224 
       
   225 	return TI2sManager::iChannels[chanId]->GetSampleLength(aFramePhase, aSampleLength);
       
   226 	}
       
   227 
       
   228 /**
       
   229  Sets the number of delay cycles for a frame phase (left or right).
       
   230  
       
   231  @param aInterfaceId	The interface Id.
       
   232  @param aFramePhase	One of TI2sFramePhase.
       
   233  @param aDelayCycles The number of delay cycles to be introduced for the frame phase indicated by aFramePhase.
       
   234 
       
   235  @return 	KErrNone, if successful; 
       
   236  KErrArgument, if aInterfaceId is invalid;
       
   237  KErrNotSupported, if the number of delay cycles for the frame phase selected is not supported by this interface;
       
   238  KErrInUse, if interface is not quiescient (a transfer is under way).
       
   239  
       
   240  Each delay cycle has a duration of a bit clock cycle. Delay cycles are inserted between the start of the frame and the start of data.
       
   241  */
       
   242 EXPORT_C TInt I2s::SetDelayCycles(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt aDelayCycles)
       
   243 	{
       
   244 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   245 	if(chanId >= TI2sManager::iChannelsNum)
       
   246 		return KErrArgument;
       
   247 
       
   248 	return TI2sManager::iChannels[chanId]->SetDelayCycles(aFramePhase, aDelayCycles);
       
   249 	}
       
   250 
       
   251 /**
       
   252  Reads the number of delay cycles for a frame phase (left or right).
       
   253  
       
   254  @param aInterfaceId	The interface Id.
       
   255  @param aFramePhase	One of TI2sFramePhase.
       
   256  @param aDelayCycles On return, contains the number of delay cycles for the frame phase indicated by aFramePhase.
       
   257 
       
   258  @return 	KErrNone, if successful; 
       
   259  KErrArgument, if aInterfaceId is invalid.
       
   260  */
       
   261 EXPORT_C TInt I2s::GetDelayCycles(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt& aDelayCycles)
       
   262 	{
       
   263 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   264 	if(chanId >= TI2sManager::iChannelsNum)
       
   265 		return KErrArgument;
       
   266 
       
   267 	return TI2sManager::iChannels[chanId]->GetDelayCycles(aFramePhase, aDelayCycles);
       
   268 	}
       
   269 
       
   270 /**
       
   271  Reads the receive data register for a frame phase.
       
   272  
       
   273  @param aInterfaceId	The interface Id.
       
   274  @param aFramePhase	One of TI2sFramePhase.
       
   275  @param aData		On return, contains the receive data register contents.
       
   276 
       
   277  @return 	KErrNone, if successful; 
       
   278  KErrArgument, if aInterfaceId is invalid;
       
   279  KErrNotSupported, if reading the receive data register is not supported (e.g. when if DMA is enabled)
       
   280  KErrNotReady, if the interface is not ready.
       
   281 
       
   282  If the implementation has a combined receive/transmit register - half duplex operation only - this API is used to read from it.
       
   283  If the implementation only supports a single receive register for both frame phases, the aFramePhase argument shall be ignored and the 
       
   284  API shall return the contents of the single register. The user of the API shall use the ReadRegisterModeStatus() API to determine
       
   285  which frame phase the data corresponds to.
       
   286  */
       
   287 EXPORT_C TInt I2s::ReadReceiveRegister(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt& aData)
       
   288 	{
       
   289 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   290 	if(chanId >= TI2sManager::iChannelsNum)
       
   291 		return KErrArgument;
       
   292 
       
   293 	return TI2sManager::iChannels[chanId]->ReadReceiveRegister(aFramePhase, aData);
       
   294 	}
       
   295 
       
   296 /**
       
   297  Writes to the transmit data register for a frame phase.
       
   298  
       
   299  @param aInterfaceId	The interface Id.
       
   300  @param aFramePhase	One of TI2sFramePhase.
       
   301  @param aData		The data to be written.
       
   302 
       
   303  @return 	KErrNone, if successful; 
       
   304  KErrArgument, if aInterfaceId is invalid;
       
   305  KErrNotSupported, if writing to the receive data register is not supported (e.g. when if DMA is enabled)
       
   306  KErrNotReady, if the interface is not ready.
       
   307 
       
   308  If the implementation has a combined receive/transmit register - half duplex operation only - this API is used to write to it.
       
   309  If the implementation only supports a single transmit register for both frame phases, the aFramePhase argument shall be ignored and the 
       
   310  API shall write to the single register. The user of the API shall use the ReadRegisterModeStatus() API to determine under which frame 
       
   311  phase the data corresponds will be transmitted.
       
   312  */
       
   313 EXPORT_C TInt I2s::WriteTransmitRegister(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt aData)
       
   314 	{
       
   315 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   316 	if(chanId >= TI2sManager::iChannelsNum)
       
   317 		return KErrArgument;
       
   318 
       
   319 	return TI2sManager::iChannels[chanId]->WriteTransmitRegister(aFramePhase, aData);
       
   320 	}
       
   321 
       
   322 /**
       
   323  Reads the transmit data register for a frame phase.
       
   324  
       
   325  @param aInterfaceId	The interface Id.
       
   326  @param aFramePhase	One of TI2sFramePhase.
       
   327  @param aData		On return, contains the transmit data register contents.
       
   328 
       
   329  @return 	KErrNone, if successful; 
       
   330  KErrArgument, if aInterfaceId is invalid;
       
   331  KErrNotSupported, if reading the transmit data register is not supported;
       
   332  KErrNotReady, if the interface is not ready.
       
   333 
       
   334  If the implementation has a combined receive/transmit register this API is used to read from it (equivalent to ReadReceiveRegister()).
       
   335  If the implementation only supports a single transmit register for both frame phases, the aFramePhase argument shall be ignored and the 
       
   336  API shall return the contents of the single register. The user of the API shall use the ReadRegisterModeStatus() API to determine
       
   337  which frame phase the data corresponds to.
       
   338  */
       
   339 EXPORT_C TInt I2s::ReadTransmitRegister(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt& aData)
       
   340 	{
       
   341 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   342 	if(chanId >= TI2sManager::iChannelsNum)
       
   343 		return KErrArgument;
       
   344 
       
   345 	return TI2sManager::iChannels[chanId]->ReadTransmitRegister(aFramePhase, aData);
       
   346 	}
       
   347 
       
   348 /**
       
   349  Reads the Register PIO access mode status flags for a frame phase.
       
   350  
       
   351  @param aInterfaceId	The interface Id.
       
   352  @param aFramePhase	One of TI2sFramePhase.
       
   353  @param aFlags		On return, contains a bitmask with the status flags for the frame phase selected (see TI2sFlags).
       
   354  A bit set to "1" indicates the condition described by the corresponding flag is occurring.
       
   355 
       
   356  @return 	KErrNone, if successful; 
       
   357  KErrArgument, if aInterfaceId is invalid;
       
   358  KErrNotSupported, if reading the status flags for Register PIO mode is not supported by this implementation.
       
   359  
       
   360  The client driver may use one of IS_I2s_<CONDITION> macros to determine the status of individual conditions.
       
   361  */
       
   362 EXPORT_C TInt I2s::ReadRegisterModeStatus(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt& aFlags)
       
   363 	{
       
   364 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   365 	if(chanId >= TI2sManager::iChannelsNum)
       
   366 		return KErrArgument;
       
   367 
       
   368 	return TI2sManager::iChannels[chanId]->ReadRegisterModeStatus(aFramePhase, aFlags);
       
   369 	}
       
   370 
       
   371 /**
       
   372  Enables Register PIO access mode related interrupts for a frame phase.
       
   373  
       
   374  @param aInterfaceId	The interface Id.
       
   375  @param aFramePhase	One of TI2sFramePhase.
       
   376  @param aInterrupt	A bitmask containing the relevant interrupt flags (see TI2sFlags).
       
   377  Bits set to "1" enable the corresponding interrupts.
       
   378 
       
   379  @return 	KErrNone, if successful; 
       
   380  KErrArgument, if aInterfaceId is invalid;
       
   381  KErrNotSupported, if one of the selected interrupt conditions cannot be generated by this implementation.
       
   382 
       
   383  If the implementation only supports single transmit and receive registers for both frame phases, the aFramePhase argument is 
       
   384  ignored.
       
   385  */
       
   386 EXPORT_C TInt I2s::EnableRegisterInterrupts(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt aInterrupt)
       
   387 	{
       
   388 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   389 	if(chanId >= TI2sManager::iChannelsNum)
       
   390 		return KErrArgument;
       
   391 
       
   392 	return TI2sManager::iChannels[chanId]->EnableRegisterInterrupts(aFramePhase, aInterrupt);
       
   393 	}
       
   394 
       
   395 /**
       
   396  Disables Register PIO access mode related interrupts for a frame phase.
       
   397  
       
   398  @param aInterfaceId	The interface Id.
       
   399  @param aFramePhase	One of TI2sFramePhase.
       
   400  @param aInterrupt	A bitmask containing the relevant interrupt flags (see TI2sFlags).
       
   401  Bits set to "1" disable the corresponding interrupts.
       
   402 
       
   403  @return 	KErrNone, if successful; 
       
   404  KErrArgument, if aInterfaceId is invalid;
       
   405  KErrNotSupported, if one of the selected interrupt conditions cannot be generated by this implementation.
       
   406 
       
   407  If the implementation only supports single transmit and receive registers for both frame phases, the aFramePhase argument is 
       
   408  ignored.
       
   409  */
       
   410 EXPORT_C TInt I2s::DisableRegisterInterrupts(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt aInterrupt)
       
   411 	{
       
   412 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   413 	if(chanId >= TI2sManager::iChannelsNum)
       
   414 		return KErrArgument;
       
   415 
       
   416 	return TI2sManager::iChannels[chanId]->DisableRegisterInterrupts(aFramePhase, aInterrupt);
       
   417 	}
       
   418 
       
   419 /**
       
   420  Reads the Register PIO access mode interrupt mask for a frame phase.
       
   421  
       
   422  @param aInterfaceId	The interface Id.
       
   423  @param aFramePhase	One of TI2sFramePhase.
       
   424  @param aEnabled		On return, contains a bitmask with the interrupts which are enabled for the frame phase selected (see TI2sFlags).
       
   425  A bit set to "1" indicates the corresponding interrupt is enabled.
       
   426 
       
   427  @return 	KErrNone, if successful; 
       
   428  KErrArgument, if aInterfaceId is invalid;
       
   429  KErrNotSupported, if one of the selected interrupt conditions cannot be generated by this implementation.
       
   430 
       
   431  If the implementation only supports single transmit and receive registers for both frame phases, the aFramePhase argument is 
       
   432  ignored.
       
   433  */
       
   434 EXPORT_C TInt I2s::IsRegisterInterruptEnabled(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt& aEnabled)
       
   435 	{
       
   436 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   437 	if(chanId >= TI2sManager::iChannelsNum)
       
   438 		return KErrArgument;
       
   439 
       
   440 	return TI2sManager::iChannels[chanId]->IsRegisterInterruptEnabled(aFramePhase, aEnabled);
       
   441 	}
       
   442 
       
   443 /**
       
   444  Enables receive and/or transmit FIFO on a per frame phase basis.
       
   445  
       
   446  @param aInterfaceId	The interface Id.
       
   447  @param aFramePhase	One of TI2sFramePhase.
       
   448  @param aFifoMask	A bitmask specifying which FIFO direction(s) - receive and/or transmit - are to be enabled for the frame 
       
   449  phase selected (see TI2sDirection).
       
   450  Bits set to "1" enable the corresponding FIFO.
       
   451 
       
   452  @return 	KErrNone, if successful; 
       
   453  KErrArgument, if aInterfaceId is invalid;
       
   454  KErrNotSupported, if the implementation does no support FIFOs.
       
   455  
       
   456  If the implementation has a combined receive/transmit FIFO - half duplex operation only - then aFifoMask is ignored.
       
   457  If the implementation only supports a single FIFO for both frame phases then aFramePhase is ignored.
       
   458  */
       
   459 EXPORT_C TInt I2s::EnableFIFO(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt aFifoMask)
       
   460 	{
       
   461 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   462 	if(chanId >= TI2sManager::iChannelsNum)
       
   463 		return KErrArgument;
       
   464 
       
   465 	return TI2sManager::iChannels[chanId]->EnableFIFO(aFramePhase, aFifoMask);
       
   466 	}
       
   467 
       
   468 /**
       
   469  Disables receive and/or transmit FIFO on a per frame phase basis.
       
   470  
       
   471  @param aInterfaceId	The interface Id.
       
   472  @param aFramePhase	One of TI2sFramePhase.
       
   473  @param aFifoMask	A bitmask specifying which FIFO direction(s) - receive and/or transmit - are to be disabled for the frame 
       
   474  phase selected (see TI2sDirection).
       
   475  Bits set to "1" disable the corresponding FIFO.
       
   476 
       
   477  @return 	KErrNone, if successful; 
       
   478  KErrArgument, if aInterfaceId is invalid;
       
   479  KErrNotSupported, if the implementation does no support FIFOs.
       
   480 
       
   481  If the implementation has a combined receive/transmit FIFO - half duplex operation only - then aFifoMask is ignored.
       
   482  If the implementation only supports a single FIFO for both frame phases then aFramePhase is ignored.
       
   483  */
       
   484 EXPORT_C TInt I2s::DisableFIFO(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt aFifoMask)
       
   485 	{
       
   486 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   487 	if(chanId >= TI2sManager::iChannelsNum)
       
   488 		return KErrArgument;
       
   489 
       
   490 	return TI2sManager::iChannels[chanId]->DisableFIFO(aFramePhase, aFifoMask);
       
   491 	}
       
   492 
       
   493 /**
       
   494  Reads the enabled state of a frame phase's FIFOs.
       
   495  
       
   496  @param aInterfaceId	The interface Id.
       
   497  @param aFramePhase	One of TI2sFramePhase.
       
   498  @param aEnabled		On return, contains a bitmask indicating which FIFOs which are enabled for the frame phase selected (see TI2sDirection).
       
   499  A bit set to "1" indicates the corresponding FIFO is enabled.
       
   500 
       
   501  @return 	KErrNone, if successful; 
       
   502  KErrArgument, if aInterfaceId is invalid;
       
   503  KErrNotSupported, if the implementation does no support FIFOs.
       
   504 
       
   505  If the implementation has a combined receive/transmit FIFO - half duplex operation only - then aEnabled will have 
       
   506  both Rx and Tx bits set when the FIFO is enabled.
       
   507  If the implementation only supports a single FIFO for both frame phases then aFramePhase is ignored.
       
   508  */
       
   509 EXPORT_C TInt I2s::IsFIFOEnabled(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt& aEnabled)
       
   510 	{
       
   511 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   512 	if(chanId >= TI2sManager::iChannelsNum)
       
   513 		return KErrArgument;
       
   514 
       
   515 	return TI2sManager::iChannels[chanId]->IsFIFOEnabled(aFramePhase, aEnabled);
       
   516 	}
       
   517 
       
   518 /**
       
   519  Sets the receive or transmit FIFO threshold on a per frame phase basis.
       
   520  
       
   521  @param aInterfaceId	The interface Id.
       
   522  @param aFramePhase	One of TI2sFramePhase.
       
   523  @param aDirection	One of TDirection.
       
   524  @param aThreshold	A threshold level at which a receive FIFO is considered full or a transmit FIFO is considered empty.
       
   525 
       
   526  @return 	KErrNone, if successful; 
       
   527  KErrArgument, if aInterfaceId is invalid;
       
   528  KErrNotSupported, if the implementation does no support FIFOs;
       
   529  KErrOverflow if the threshold level requested exceeds the FIFO length (or the admissible highest level allowed)
       
   530  KErrUnderflow if the threshold level requested is less than the minimum threshold allowed.
       
   531  
       
   532  If the implementation has a combined receive/transmit FIFO - half duplex operation only - then aDirection is ignored.
       
   533  If the implementation only supports a single FIFO for both frame phases then aFramePhase is ignored.
       
   534  */
       
   535 EXPORT_C TInt I2s::SetFIFOThreshold(TInt aInterfaceId, TI2sFramePhase aFramePhase, TI2sDirection aDirection, TInt aThreshold)
       
   536 	{
       
   537 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   538 	if(chanId >= TI2sManager::iChannelsNum)
       
   539 		return KErrArgument;
       
   540 
       
   541 	return TI2sManager::iChannels[chanId]->SetFIFOThreshold(aFramePhase, aDirection, aThreshold);
       
   542 	}
       
   543 
       
   544 /**
       
   545  Reads the FIFO PIO access mode status flags for a frame phase.
       
   546  
       
   547  @param aInterfaceId	The interface Id.
       
   548  @param aFramePhase	One of TI2sFramePhase.
       
   549  @param aFlags		On return, contains a bitmask with the status flags for the frame phase selected (see TI2sFlags).
       
   550  A bit set to "1" indicates the condition described by the corresponding flag is occurring.
       
   551 
       
   552  @return 	KErrNone, if successful; 
       
   553  KErrArgument, if aInterfaceId is invalid;
       
   554  KErrNotSupported, if reading the status flags for FIFO PIO mode is not supported by this implementation.
       
   555  
       
   556  The client driver may use one of IS_I2s_<CONDITION> macros to determine the status of individual conditions.
       
   557  If the implementation has a combined receive/transmit FIFO - half duplex operation only - then aFlags will be set according
       
   558  to which operation (receive/transmit) is undergoing.
       
   559  If the implementation only supports a single FIFO for both frame phases then aFramePhase is ignored.
       
   560  */
       
   561 EXPORT_C TInt I2s::ReadFIFOModeStatus(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt& aFlags)
       
   562 	{
       
   563 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   564 	if(chanId >= TI2sManager::iChannelsNum)
       
   565 		return KErrArgument;
       
   566 
       
   567 	return TI2sManager::iChannels[chanId]->ReadFIFOModeStatus(aFramePhase, aFlags);
       
   568 	}
       
   569 
       
   570 /**
       
   571  Enables FIFO related interrupts for a frame phase.
       
   572  
       
   573  @param aInterfaceId	The interface Id.
       
   574  @param aFramePhase	One of TI2sFramePhase.
       
   575  @param aInterrupt	A bitmask containing the relevant interrupt flags (see TI2sFlags).
       
   576  Bits set to "1" enable the corresponding interrupts.
       
   577 
       
   578  @return 	KErrNone, if successful; 
       
   579  KErrArgument, if aInterfaceId is invalid;
       
   580  KErrNotSupported, if one of the selected interrupt conditions cannot be generated by this implementation.
       
   581 
       
   582  If the implementation only supports single transmit and receive FIFO for both frame phases, the aFramePhase argument is 
       
   583  ignored.
       
   584  */
       
   585 EXPORT_C TInt I2s::EnableFIFOInterrupts(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt aInterrupt)
       
   586 	{
       
   587 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   588 	if(chanId >= TI2sManager::iChannelsNum)
       
   589 		return KErrArgument;
       
   590 
       
   591 	return TI2sManager::iChannels[chanId]->EnableFIFOInterrupts(aFramePhase, aInterrupt);
       
   592 	}
       
   593 
       
   594 /**
       
   595  Disables FIFO related interrupts for a frame phase.
       
   596  
       
   597  @param aInterfaceId	The interface Id.
       
   598  @param aFramePhase	One of TI2sFramePhase.
       
   599  @param aInterrupt	A bitmask containing the relevant interrupt flags (see TI2sFlags).
       
   600  Bits set to "1" disable the corresponding interrupts.
       
   601 
       
   602  @return 	KErrNone, if successful; 
       
   603  KErrArgument, if aInterfaceId is invalid;
       
   604  KErrNotSupported, if one of the selected interrupt conditions cannot be generated by this implementation.
       
   605 
       
   606  If the implementation only supports single transmit and receive FIFO for both frame phases, the aFramePhase argument is 
       
   607  ignored.
       
   608  */
       
   609 EXPORT_C TInt I2s::DisableFIFOInterrupts(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt aInterrupt)
       
   610 	{
       
   611 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   612 	if(chanId >= TI2sManager::iChannelsNum)
       
   613 		return KErrArgument;
       
   614 
       
   615 	return TI2sManager::iChannels[chanId]->DisableFIFOInterrupts(aFramePhase, aInterrupt);
       
   616 	}
       
   617 
       
   618 /**
       
   619  Reads the FIFO interrupt masks for a frame phase.
       
   620  
       
   621  @param aInterfaceId	The interface Id.
       
   622  @param aFramePhase	One of TI2sFramePhase.
       
   623  @param aEnabled		On return, contains a bitmask with the interrupts which are enabled for the frame phase selected (see TI2sFlags).
       
   624  A bit set to "1" indicates the corresponding interrupt is enabled.
       
   625 
       
   626  @return 	KErrNone, if successful; 
       
   627  KErrArgument, if aInterfaceId is invalid;
       
   628  KErrNotSupported, if one of the selected interrupt conditions cannot be generated by this implementation.
       
   629  */
       
   630 EXPORT_C TInt I2s::IsFIFOInterruptEnabled(TInt aInterfaceId, TI2sFramePhase aFramePhase, TInt& aEnabled)
       
   631 	{
       
   632 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   633 	if(chanId >= TI2sManager::iChannelsNum)
       
   634 		return KErrArgument;
       
   635 
       
   636 	return TI2sManager::iChannels[chanId]->IsFIFOInterruptEnabled(aFramePhase, aEnabled);
       
   637 	}
       
   638 
       
   639 /**
       
   640  Reads the receive or transmit FIFO current level on a per frame phase basis.
       
   641  
       
   642  @param aInterfaceId	The interface Id.
       
   643  @param aFramePhase	One of TI2sFramePhase.
       
   644  @param aDirection	One of TDirection.
       
   645  @param aLevel		On return, contains the current level for the FIFO described by the (aFramePhase,aDirection) pair.
       
   646 
       
   647  @return 	KErrNone, if successful; 
       
   648  KErrArgument, if aInterfaceId is invalid;
       
   649  KErrNotSupported, if the implementation does no support FIFOs.
       
   650  
       
   651  If the implementation has a combined receive/transmit FIFO - half duplex operation only - then aDirection is ignored.
       
   652  If the implementation only supports a single FIFO for both frame phases then aFramePhase is ignored.
       
   653  */
       
   654 EXPORT_C TInt I2s::ReadFIFOLevel(TInt aInterfaceId, TI2sFramePhase aFramePhase, TI2sDirection aDirection, TInt& aLevel)
       
   655 	{
       
   656 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   657 	if(chanId >= TI2sManager::iChannelsNum)
       
   658 		return KErrArgument;
       
   659 
       
   660 	return TI2sManager::iChannels[chanId]->ReadFIFOLevel(aFramePhase, aDirection, aLevel);
       
   661 	}
       
   662 
       
   663 /**
       
   664  Enables receive and/or transmit DMA.
       
   665  
       
   666  @param aInterfaceId	The interface Id.
       
   667  @param aFifoMask	A bitmask specifying which directions - receive and/or transmit - is DMA to be enabled (see TI2sDirection).
       
   668  Bits set to "1" enable DMA.
       
   669 
       
   670  @return 	KErrNone, if successful; 
       
   671  KErrArgument, if aInterfaceId is invalid;
       
   672  KErrNotSupported, if the implementation does no support DMA.
       
   673  
       
   674  If the implementation has a combined receive/transmit FIFO - half duplex operation only - then aFifoMask is ignored.
       
   675  */
       
   676 EXPORT_C TInt I2s::EnableDMA(TInt aInterfaceId, TInt aFifoMask)
       
   677 	{
       
   678 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   679 	if(chanId >= TI2sManager::iChannelsNum)
       
   680 		return KErrArgument;
       
   681 
       
   682 	return TI2sManager::iChannels[chanId]->EnableDMA(aFifoMask);
       
   683 	}
       
   684 
       
   685 /**
       
   686  Disables receive and/or transmit DMA.
       
   687  
       
   688  @param aInterfaceId	The interface Id.
       
   689  @param aFifoMask	A bitmask specifying which directions - receive and/or transmit - is DMA to be disabled (see TI2sDirection).
       
   690  Bits set to "1" disable DMA.
       
   691 
       
   692  @return 	KErrNone, if successful; 
       
   693  KErrArgument, if aInterfaceId is invalid;
       
   694  KErrNotSupported, if the implementation does no support DMA.
       
   695 
       
   696  If the implementation has a combined receive/transmit FIFO - half duplex operation only - then aFifoMask is ignored.
       
   697  */
       
   698 EXPORT_C TInt I2s::DisableDMA(TInt aInterfaceId, TInt aFifoMask)
       
   699 	{
       
   700 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   701 	if(chanId >= TI2sManager::iChannelsNum)
       
   702 		return KErrArgument;
       
   703 
       
   704 	return TI2sManager::iChannels[chanId]->DisableDMA(aFifoMask);
       
   705 	}
       
   706 
       
   707 /**
       
   708  Reads the enabled state of DMA.
       
   709  
       
   710  @param aInterfaceId	The interface Id.
       
   711  @param aEnabled		On return, contains a bitmask indicating if DMA enabled for the corresponding directions (see TI2sDirection).
       
   712  A bit set to "1" indicates DMA is enabled for the corresponding direction.
       
   713 
       
   714  @return 	KErrNone, if successful; 
       
   715  KErrArgument, if aInterfaceId is invalid;
       
   716  KErrNotSupported, if the implementation does no support FIFOs.
       
   717 
       
   718  If the implementation has a combined receive/transmit FIFO - half duplex operation only - then aEnabled will have 
       
   719  both Rx and Tx bits set when the DMA is enabled.
       
   720  */
       
   721 EXPORT_C TInt I2s::IsDMAEnabled(TInt aInterfaceId, TInt& aEnabled)
       
   722 	{
       
   723 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   724 	if(chanId >= TI2sManager::iChannelsNum)
       
   725 		return KErrArgument;
       
   726 
       
   727 	return TI2sManager::iChannels[chanId]->IsDMAEnabled(aEnabled);
       
   728 	}
       
   729 
       
   730 /**
       
   731  Starts data transmission and/or data reception unless interface is a Controller;
       
   732  if device is also a Master, starts generation of data synchronisation signals.
       
   733  
       
   734  @param aInterfaceId	The interface Id.
       
   735  @param aDirection	A bitmask made of TI2sDirection values. The value is ignored if interface is a Controller.
       
   736 
       
   737  @return 	KErrNone, if successful; 
       
   738  KErrArgument, if aInterfaceId is invalid or if aDirection  is invalid (i.e. negative, 0 or greater than 3)
       
   739  KErrNotSupported, if one of the transfer directions selected is not supported on this interface;
       
   740  KErrInUse, if interface has a bidirectional data port and an access in the opposite direction is underway;
       
   741  KErrNotReady, if interface is not ready (e.g. incomplete configuration).
       
   742  
       
   743  Start() is idempotent, attempting to start an already started interface has no effect (returns KErrNone).
       
   744  */
       
   745 EXPORT_C TInt I2s::Start(TInt aInterfaceId, TInt aDirection)
       
   746 	{
       
   747 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   748 	if(chanId >= TI2sManager::iChannelsNum)
       
   749 		return KErrArgument;
       
   750 
       
   751 	return TI2sManager::iChannels[chanId]->Start(aDirection);
       
   752 	}
       
   753 
       
   754 /**
       
   755  Stops data transmission and/or data reception;
       
   756  if device is also a Master, stops generation of data synchronisation signals.
       
   757  
       
   758  @param aInterfaceId	The interface Id.
       
   759  @param aDirection	A bitmask made of TI2sDirection values.
       
   760 
       
   761  @return 	KErrNone, if successful; 
       
   762  KErrArgument, if aInterfaceId is invalid or if aDirection  is invalid (i.e. negative, 0 or greater than 3)
       
   763  KErrNotSupported, if one of the transfer directions selected is not supported on this interface.
       
   764 
       
   765  Stop() is idempotent, attempting to stop an already started interface has no effect (returns KErrNone).
       
   766  */
       
   767 EXPORT_C TInt I2s::Stop(TInt aInterfaceId, TInt aDirection)
       
   768 	{
       
   769 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   770 	if(chanId >= TI2sManager::iChannelsNum)
       
   771 		return KErrArgument;
       
   772 
       
   773 	return TI2sManager::iChannels[chanId]->Stop(aDirection);
       
   774 	}
       
   775 
       
   776 /**
       
   777  Checks if a transmission or a reception is underway.
       
   778  
       
   779  @param aInterfaceId	The interface Id.
       
   780  @param aDirection	One of TI2sDirection.
       
   781  @param aStarted 	On return, contains ETrue if the the access is underway, EFalse otherwise.
       
   782 
       
   783  @return 	KErrNone, if successful; 
       
   784  KErrArgument, if aInterfaceId is invalid or if aDirection  is invalid (i.e. negative, 0 or greater than 3)
       
   785  KErrNotSupported, if one of the transfer directions selected is not supported on this interface.
       
   786 
       
   787  If the interface is a Controller and a bus operation is underway, ETrue is returned regardless of aDirection.
       
   788  */
       
   789 EXPORT_C TInt I2s::IsStarted(TInt aInterfaceId, TI2sDirection aDirection, TBool& aStarted)
       
   790 	{
       
   791 	TUint16 chanId=CHANNEL_ID_FROM_INTERFACE_ID(aInterfaceId);
       
   792 	if(chanId >= TI2sManager::iChannelsNum)
       
   793 		return KErrArgument;
       
   794 
       
   795 	return TI2sManager::iChannels[chanId]->IsStarted(aDirection, aStarted);
       
   796 	}
       
   797 
       
   798 // dll entry point..
       
   799 DECLARE_STANDARD_EXTENSION()
       
   800 	{
       
   801 	__KTRACE_OPT(KBOOT, Kern::Printf("Starting I2S Extension"));
       
   802 	// coverity[alloc_fn]
       
   803 	TI2sManager* pD = new TI2sManager;
       
   804 	TInt r=KErrNoMemory;
       
   805 	if (pD)
       
   806 		r=pD->DoCreate();
       
   807 	return r;
       
   808 	}
       
   809